diff --git a/README.md b/README.md index d1c40ccb..de021c50 100644 --- a/README.md +++ b/README.md @@ -604,14 +604,14 @@ the IDE for completions and navigation: ## Logs and Debugging -Logs from `komorebi` will be appended to `~/komorebi.log`; this file is never rotated or overwritten, so it will keep +Logs from `komorebi` will be appended to `%LOCALAPPDATA%/komorebi/komorebi.log`; this file is never rotated or overwritten, so it will keep growing until it is deleted by the user. Whenever running the `komorebic stop` command or sending a Ctrl-C signal to `komorebi` directly, the `komorebi` process ensures that all hidden windows are restored before termination. If however, you ever end up with windows that are hidden and cannot be restored, a list of window handles known -to `komorebi` are stored and continuously updated in `~/komorebi.hwnd.json`. +to `komorebi` are stored and continuously updated in `%LOCALAPPDATA%/komorebi//komorebi.hwnd.json`. ### Restoring Windows diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 0664b276..695e6b83 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -118,6 +118,7 @@ lazy_static! { dirs::home_dir().expect("there is no home directory") } }; + static ref DATA_DIR: PathBuf = dirs::data_local_dir().expect("there is no local data directory").join("komorebi"); static ref AHK_V1_EXE: String = { let mut ahk_v1: String = String::from("autohotkey.exe"); @@ -156,8 +157,7 @@ fn setup() -> Result<(WorkerGuard, WorkerGuard)> { std::env::set_var("RUST_LOG", "info"); } - let home = HOME_DIR.clone(); - let appender = tracing_appender::rolling::never(home, "komorebi.log"); + let appender = tracing_appender::rolling::never(DATA_DIR.clone(), "komorebi.log"); let color_appender = tracing_appender::rolling::never(std::env::temp_dir(), "komorebi.log"); let (non_blocking, guard) = tracing_appender::non_blocking(appender); let (color_non_blocking, color_guard) = tracing_appender::non_blocking(color_appender); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 7f6d5f8f..5ca67b86 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -19,8 +19,8 @@ use crate::window_manager_event::WindowManagerEvent; use crate::windows_api::WindowsApi; use crate::Notification; use crate::NotificationEvent; +use crate::DATA_DIR; use crate::HIDDEN_HWNDS; -use crate::HOME_DIR; use crate::TRAY_AND_MULTI_WINDOW_IDENTIFIERS; #[tracing::instrument] @@ -487,8 +487,7 @@ impl WindowManager { } } - let mut hwnd_json = HOME_DIR.clone(); - hwnd_json.push("komorebi.hwnd.json"); + let hwnd_json = DATA_DIR.join("komorebi.hwnd.json"); let file = OpenOptions::new() .write(true) .truncate(true) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 3e0fd19b..319890d5 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -39,6 +39,7 @@ use crate::windows_api::WindowsApi; use crate::winevent_listener::WINEVENT_CALLBACK_CHANNEL; use crate::workspace::Workspace; use crate::BORDER_OVERFLOW_IDENTIFIERS; +use crate::DATA_DIR; use crate::FLOAT_IDENTIFIERS; use crate::HOME_DIR; use crate::LAYERED_WHITELIST; @@ -142,10 +143,7 @@ impl EnforceWorkspaceRuleOp { impl WindowManager { #[tracing::instrument] pub fn new(incoming: Arc>>) -> Result { - let home = HOME_DIR.clone(); - let mut socket = home; - socket.push("komorebi.sock"); - let socket = socket.as_path(); + let socket = DATA_DIR.join("komorebi.sock"); match std::fs::remove_file(&socket) { Ok(_) => {} diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 233a7446..92675a64 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -60,6 +60,9 @@ lazy_static! { dirs::home_dir().expect("there is no home directory") } }; + static ref DATA_DIR: PathBuf = dirs::data_local_dir() + .expect("there is no local data directory") + .join("komorebi"); } trait AhkLibrary { @@ -675,10 +678,7 @@ enum SubCommand { } pub fn send_message(bytes: &[u8]) -> Result<()> { - let mut socket = HOME_DIR.clone(); - socket.push("komorebi.sock"); - let socket = socket.as_path(); - + let socket = DATA_DIR.join("komorebi.sock"); let mut stream = UnixStream::connect(&socket)?; Ok(stream.write_all(bytes)?) } @@ -1072,8 +1072,7 @@ fn main() -> Result<()> { } } SubCommand::RestoreWindows => { - let mut hwnd_json = HOME_DIR.clone(); - hwnd_json.push("komorebi.hwnd.json"); + let hwnd_json = DATA_DIR.join("komorebi.hwnd.json"); let file = File::open(hwnd_json)?; let reader = BufReader::new(file);