Remove LogsDir in favor of just path::PathBuf

This commit is contained in:
Kiril Videlov 2024-01-31 15:42:37 +01:00 committed by Kiril Videlov
parent bfbfaacdd0
commit 3e1a77e83a
4 changed files with 22 additions and 68 deletions

View File

@ -18,7 +18,6 @@ pub mod keys;
pub mod lock;
pub mod logs;
pub mod menu;
pub mod paths;
pub mod project_repository;
pub mod projects;
pub mod reader;

View File

@ -5,12 +5,13 @@ use tracing::{metadata::LevelFilter, subscriber::set_global_default};
use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_subscriber::{fmt::format::FmtSpan, layer::SubscriberExt, Layer};
use crate::{paths::LogsDir, sentry};
use crate::sentry;
pub fn init(app_handle: &AppHandle) {
let logs_dir = LogsDir::try_from(app_handle)
.expect("failed to get logs dir")
.to_path_buf();
let logs_dir = app_handle
.path_resolver()
.app_log_dir()
.expect("failed to get logs dir");
fs::create_dir_all(&logs_dir).expect("failed to create logs dir");
let file_appender = RollingFileAppender::builder()

View File

@ -1,42 +0,0 @@
use std::path;
use anyhow::Context;
use tauri::AppHandle;
pub struct LogsDir(path::PathBuf);
impl LogsDir {
pub fn to_path_buf(&self) -> path::PathBuf {
self.0.clone()
}
}
impl TryFrom<&AppHandle> for LogsDir {
type Error = anyhow::Error;
fn try_from(app_handle: &AppHandle) -> Result<Self, Self::Error> {
app_handle
.path_resolver()
.app_log_dir()
.map(Self)
.context("failed to get app log dir")
}
}
impl From<&path::PathBuf> for LogsDir {
fn from(value: &path::PathBuf) -> Self {
Self::from(value.clone())
}
}
impl From<path::PathBuf> for LogsDir {
fn from(value: path::PathBuf) -> Self {
Self(value)
}
}
impl From<LogsDir> for path::PathBuf {
fn from(logs_dir: LogsDir) -> Self {
logs_dir.0
}
}

View File

@ -2,16 +2,13 @@ use std::path;
use tauri::AppHandle;
use crate::{
paths::LogsDir,
projects::{self, ProjectId},
};
use crate::projects::{self, ProjectId};
use super::Zipper;
pub struct Controller {
local_data_dir: path::PathBuf,
logs_dir: LogsDir,
logs_dir: path::PathBuf,
zipper: Zipper,
projects_controller: projects::Controller,
}
@ -20,19 +17,20 @@ impl TryFrom<&AppHandle> for Controller {
type Error = anyhow::Error;
fn try_from(value: &AppHandle) -> Result<Self, Self::Error> {
let local_data_dir = value.path_resolver().app_data_dir();
match local_data_dir {
Some(local_data_dir) => {
let logs_dir = LogsDir::try_from(value)?;
Ok(Self {
local_data_dir,
logs_dir,
zipper: Zipper::try_from(value)?,
projects_controller: projects::Controller::try_from(value)?,
})
}
None => Err(anyhow::anyhow!("failed to get app data dir")),
}
let local_data_dir = value
.path_resolver()
.app_data_dir()
.ok_or_else(|| anyhow::anyhow!("failed to get local data dir"))?;
let logs_dir = value
.path_resolver()
.app_log_dir()
.ok_or_else(|| anyhow::anyhow!("failed to get logs dir"))?;
Ok(Self {
local_data_dir,
logs_dir,
zipper: Zipper::try_from(value)?,
projects_controller: projects::Controller::try_from(value)?,
})
}
}
@ -54,9 +52,7 @@ impl Controller {
}
pub fn logs_archive(&self) -> Result<path::PathBuf, LogsArchiveError> {
self.zipper
.zip(self.logs_dir.to_path_buf())
.map_err(Into::into)
self.zipper.zip(&self.logs_dir).map_err(Into::into)
}
}