Skip to content

Commit

Permalink
src: Adjustments for dekstop-client project
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin committed Sep 19, 2024
1 parent afdf6a3 commit 5e7ca20
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ validator = "0.18.1"
thiserror = "1.0.63"
shellexpand = "3.1"

tauri = { version = "1.7.2", optional = true, features = ["shell-open"] }


[build-dependencies]
vergen-gix = { version = "1.0.1", default-features = false, features = ["build", "cargo"] }

Expand All @@ -44,3 +47,7 @@ path = "src/lib.rs"
[[bin]]
name = "ping-viewer-next"
path = "src/main.rs"

[features]
default = []
desktop-app = ["tauri"]
44 changes: 42 additions & 2 deletions src/logger/manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{path::PathBuf, str::FromStr};

use crate::cli;

Expand Down Expand Up @@ -39,13 +39,15 @@ pub fn init() {
EnvFilter::new(LevelFilter::DEBUG.to_string())
};

let dir = cli::manager::log_path();
let dir = get_app_log_dir();

let file_appender = custom_rolling_appender(
dir,
tracing_appender::rolling::Rotation::HOURLY,
"ping-viewer",
"log",
);

let file_layer = fmt::Layer::new()
.with_writer(file_appender)
.with_ansi(false)
Expand Down Expand Up @@ -136,3 +138,41 @@ fn custom_rolling_appender<P: AsRef<std::path::Path>>(
.build(dir)
.expect("failed to initialize rolling file appender")
}

#[allow(unused)]
#[cfg(feature = "desktop-app")]
static APP_DIR: &str = "Ping-Viewer-Next";

#[cfg(feature = "desktop-app")]
pub fn get_app_home_dir() -> PathBuf {
#[cfg(target_os = "windows")]
if let Err(e) = std::env::current_dir() {
error!("Failed to get app home dir. Errmsg: {}", e);
std::process::exit(-1);
} else {
return std::env::current_dir().unwrap();
}

#[cfg(not(target_os = "windows"))]
match tauri::api::path::home_dir() {
None => {
error!("Failed to get app home dir");
std::process::exit(-1);
}
Some(path) => {
return path.join(APP_DIR);
}
}
}

pub fn get_app_log_dir() -> PathBuf {
#[cfg(feature = "desktop-app")]
{
get_app_home_dir().join("logs")
}

#[cfg(not(feature = "desktop-app"))]
{
PathBuf::from(cli::manager::log_path())
}
}

0 comments on commit 5e7ca20

Please sign in to comment.