Skip to content

Commit 5ad7e3c

Browse files
Merge pull request #489 from dwall-rs/dev
2 parents 2fe42ba + 5d986a9 commit 5ad7e3c

File tree

7 files changed

+42
-8
lines changed

7 files changed

+42
-8
lines changed

daemon/src/lazy.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,30 @@ pub static DWALL_CACHE_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
5252

5353
dir
5454
});
55+
56+
/// Global log directory path
57+
///
58+
/// Initialized lazily on first access. Creates the directory if it doesn't exist.
59+
/// Uses the application bundle identifier for better organization.
60+
///
61+
/// # Panics
62+
/// Panics if unable to determine user's log directory or create the dwall subdirectory.
63+
pub static DWALL_LOG_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
64+
let log_dir = DWALL_CACHE_DIR.join("log");
65+
66+
if !log_dir.exists() {
67+
if let Err(e) = fs::create_dir(&log_dir) {
68+
error!(error = %e, "Failed to create log directory");
69+
panic!("Failed to create log directory: {e}");
70+
} else {
71+
info!(
72+
"Log directory created successfully at: {}",
73+
log_dir.display()
74+
);
75+
}
76+
} else {
77+
debug!(path = %log_dir.display(), "Log directory already exists");
78+
}
79+
80+
log_dir
81+
});

daemon/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern crate tracing;
1313
pub use config::Config;
1414
pub use core::daemon::DaemonApplication;
1515
pub use error::DwallResult;
16-
pub use lazy::{DWALL_CACHE_DIR, DWALL_CONFIG_DIR};
16+
pub use lazy::{DWALL_CACHE_DIR, DWALL_CONFIG_DIR, DWALL_LOG_DIR};
1717
pub use utils::logging::setup_logging;
1818

1919
// Re-export domain types

daemon/src/utils/logging.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ pub fn setup_logging<S: AsRef<str>>(pkg_names: &[S]) {
5858
let writer = if cfg!(debug_assertions) {
5959
BoxMakeWriter::new(Mutex::new(std::io::stderr()))
6060
} else {
61-
use crate::lazy::DWALL_CONFIG_DIR;
61+
use crate::lazy::DWALL_LOG_DIR;
6262
use std::fs::File;
6363

64-
let log_file =
65-
File::create(DWALL_CONFIG_DIR.join(format!("{}.log", pkg_names[0].as_ref())))
66-
.expect("Failed to create the log file");
64+
let log_file = File::create(DWALL_LOG_DIR.join(format!("{}.log", pkg_names[0].as_ref())))
65+
.expect("Failed to create the log file");
6766
BoxMakeWriter::new(Mutex::new(log_file))
6867
};
6968

src-tauri/src/app/commands.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
use dwall::{
1212
config::Config, domain::geography::check_location_permission,
1313
read_config_file as dwall_read_config, write_config_file as dwall_write_config, ColorScheme,
14-
DisplayMonitor, DWALL_CONFIG_DIR,
14+
DisplayMonitor, DWALL_CONFIG_DIR, DWALL_LOG_DIR,
1515
};
1616
use tauri::{AppHandle, Manager, WebviewWindow};
1717

@@ -66,6 +66,11 @@ pub async fn open_config_dir() -> DwallSettingsResult<()> {
6666
open::that(DWALL_CONFIG_DIR.as_os_str()).map_err(|e| e.into())
6767
}
6868

69+
#[tauri::command]
70+
pub async fn open_log_dir() -> DwallSettingsResult<()> {
71+
open::that(DWALL_LOG_DIR.as_os_str()).map_err(|e| e.into())
72+
}
73+
6974
#[tauri::command]
7075
pub async fn set_titlebar_color_mode(
7176
window: WebviewWindow,

src-tauri/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ async fn main() -> DwallSettingsResult<()> {
6464
commands::request_location_permission,
6565
commands::open_dir,
6666
commands::open_config_dir,
67+
commands::open_log_dir,
6768
commands::set_titlebar_color_mode,
6869
commands::move_themes_directory_cmd,
6970
commands::kill_daemon_cmd,

src/commands/system.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ export const openDir = async (dirPath: string) =>
77
invoke<void>("open_dir", { dirPath });
88

99
export const killDaemon = async () => invoke<void>("kill_daemon_cmd");
10+
11+
export const openLogDir = async () => invoke<void>("open_log_dir");

src/components/Settings/Footer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getVersion } from "@tauri-apps/api/app";
55
import { ask, message } from "@tauri-apps/plugin-dialog";
66
import { open } from "@tauri-apps/plugin-shell";
77

8-
import { openConfigDir } from "~/commands";
8+
import { openLogDir } from "~/commands";
99
import { useTranslations, useUpdate } from "~/contexts";
1010
import {
1111
LazyButton,
@@ -21,7 +21,7 @@ const SettingsFooter = () => {
2121
const { update: resource, recheckUpdate, setShowUpdateDialog } = useUpdate();
2222

2323
const onOpenLogDir = async () => {
24-
await openConfigDir();
24+
await openLogDir();
2525
};
2626

2727
const onUpdate = async () => {

0 commit comments

Comments
 (0)