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

View File

@@ -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

View File

@@ -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);

View File

@@ -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)

View File

@@ -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<Mutex<Receiver<WindowManagerEvent>>>) -> Result<Self> {
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(_) => {}

View File

@@ -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);