refactor(wm): store rt files under %LOCALAPPDATA% (#164)

This commit is contained in:
Amr Bashir
2022-06-27 18:09:02 +02:00
committed by LGUG2Z
parent 39971774ea
commit 4576078b96
5 changed files with 13 additions and 17 deletions
+2 -2
View File
@@ -604,14 +604,14 @@ the IDE for completions and navigation:
## Logs and Debugging ## 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. 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 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. 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 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 ### Restoring Windows
+2 -2
View File
@@ -118,6 +118,7 @@ lazy_static! {
dirs::home_dir().expect("there is no home directory") 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 = { static ref AHK_V1_EXE: String = {
let mut ahk_v1: String = String::from("autohotkey.exe"); 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"); std::env::set_var("RUST_LOG", "info");
} }
let home = HOME_DIR.clone(); let appender = tracing_appender::rolling::never(DATA_DIR.clone(), "komorebi.log");
let appender = tracing_appender::rolling::never(home, "komorebi.log");
let color_appender = tracing_appender::rolling::never(std::env::temp_dir(), "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 (non_blocking, guard) = tracing_appender::non_blocking(appender);
let (color_non_blocking, color_guard) = tracing_appender::non_blocking(color_appender); let (color_non_blocking, color_guard) = tracing_appender::non_blocking(color_appender);
+2 -3
View File
@@ -19,8 +19,8 @@ use crate::window_manager_event::WindowManagerEvent;
use crate::windows_api::WindowsApi; use crate::windows_api::WindowsApi;
use crate::Notification; use crate::Notification;
use crate::NotificationEvent; use crate::NotificationEvent;
use crate::DATA_DIR;
use crate::HIDDEN_HWNDS; use crate::HIDDEN_HWNDS;
use crate::HOME_DIR;
use crate::TRAY_AND_MULTI_WINDOW_IDENTIFIERS; use crate::TRAY_AND_MULTI_WINDOW_IDENTIFIERS;
#[tracing::instrument] #[tracing::instrument]
@@ -487,8 +487,7 @@ impl WindowManager {
} }
} }
let mut hwnd_json = HOME_DIR.clone(); let hwnd_json = DATA_DIR.join("komorebi.hwnd.json");
hwnd_json.push("komorebi.hwnd.json");
let file = OpenOptions::new() let file = OpenOptions::new()
.write(true) .write(true)
.truncate(true) .truncate(true)
+2 -4
View File
@@ -39,6 +39,7 @@ use crate::windows_api::WindowsApi;
use crate::winevent_listener::WINEVENT_CALLBACK_CHANNEL; use crate::winevent_listener::WINEVENT_CALLBACK_CHANNEL;
use crate::workspace::Workspace; use crate::workspace::Workspace;
use crate::BORDER_OVERFLOW_IDENTIFIERS; use crate::BORDER_OVERFLOW_IDENTIFIERS;
use crate::DATA_DIR;
use crate::FLOAT_IDENTIFIERS; use crate::FLOAT_IDENTIFIERS;
use crate::HOME_DIR; use crate::HOME_DIR;
use crate::LAYERED_WHITELIST; use crate::LAYERED_WHITELIST;
@@ -142,10 +143,7 @@ impl EnforceWorkspaceRuleOp {
impl WindowManager { impl WindowManager {
#[tracing::instrument] #[tracing::instrument]
pub fn new(incoming: Arc<Mutex<Receiver<WindowManagerEvent>>>) -> Result<Self> { pub fn new(incoming: Arc<Mutex<Receiver<WindowManagerEvent>>>) -> Result<Self> {
let home = HOME_DIR.clone(); let socket = DATA_DIR.join("komorebi.sock");
let mut socket = home;
socket.push("komorebi.sock");
let socket = socket.as_path();
match std::fs::remove_file(&socket) { match std::fs::remove_file(&socket) {
Ok(_) => {} Ok(_) => {}
+5 -6
View File
@@ -60,6 +60,9 @@ lazy_static! {
dirs::home_dir().expect("there is no home directory") 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 { trait AhkLibrary {
@@ -675,10 +678,7 @@ enum SubCommand {
} }
pub fn send_message(bytes: &[u8]) -> Result<()> { pub fn send_message(bytes: &[u8]) -> Result<()> {
let mut socket = HOME_DIR.clone(); let socket = DATA_DIR.join("komorebi.sock");
socket.push("komorebi.sock");
let socket = socket.as_path();
let mut stream = UnixStream::connect(&socket)?; let mut stream = UnixStream::connect(&socket)?;
Ok(stream.write_all(bytes)?) Ok(stream.write_all(bytes)?)
} }
@@ -1072,8 +1072,7 @@ fn main() -> Result<()> {
} }
} }
SubCommand::RestoreWindows => { SubCommand::RestoreWindows => {
let mut hwnd_json = HOME_DIR.clone(); let hwnd_json = DATA_DIR.join("komorebi.hwnd.json");
hwnd_json.push("komorebi.hwnd.json");
let file = File::open(hwnd_json)?; let file = File::open(hwnd_json)?;
let reader = BufReader::new(file); let reader = BufReader::new(file);