diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd482a..a2d835e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,19 @@ All notable changes to this project are documented here. This project adheres to [Semantic Versioning](https://semver.org/). +## [2.3.3] — 2026-10-18 + +### Fixed +- **Hidden apps no longer lag or glitch.** HideMyWindows used to reach into + every hidden app once a second to re-check its protection. It now checks + only when the app's windows change (or every 15 seconds), and the helper + inside hidden apps does far less work per window event. + +### Added +- **Settings: turn off the protection checker** if you don't need it. +- **Settings: Quick Launch only** — hide only apps started from Quick Launch; + rules are paused while it is on. + ## [2.3.2] — 2026-10-14 **Save your work before updating.** The update to 2.3.1 could close other diff --git a/Cargo.lock b/Cargo.lock index acd409c..be04338 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1490,7 +1490,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hidemywindows" -version = "2.3.2" +version = "2.3.3" dependencies = [ "hmw-core", "serde", @@ -1507,7 +1507,7 @@ dependencies = [ [[package]] name = "hmw-core" -version = "2.3.2" +version = "2.3.3" dependencies = [ "png 0.17.16", "regex", @@ -1518,7 +1518,7 @@ dependencies = [ [[package]] name = "hmw-payload" -version = "2.3.2" +version = "2.3.3" dependencies = [ "cc", "regex", @@ -1529,7 +1529,7 @@ dependencies = [ [[package]] name = "hmw-release" -version = "2.3.2" +version = "2.3.3" dependencies = [ "hmw-core", ] diff --git a/Cargo.toml b/Cargo.toml index 47184ac..4d72fe0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["hmw-core", "hmw-release", "payload", "src-tauri"] [workspace.package] -version = "2.3.2" +version = "2.3.3" edition = "2021" license = "MIT" repository = "https://github.com/mehdimamas/hidemywindows" diff --git a/hmw-core/src/config.rs b/hmw-core/src/config.rs index ba1270d..023d6d9 100644 --- a/hmw-core/src/config.rs +++ b/hmw-core/src/config.rs @@ -81,6 +81,17 @@ pub struct Config { #[serde(default)] pub quick_launch: Vec, + + /// Periodically re-verify capture exclusion on already-hidden processes. + /// Off means hiding still happens (at launch and via the in-process + /// payload worker), but the controller stops re-checking from outside. + #[serde(default = "default_true")] + pub protection_checker: bool, + + /// When on, the window-rule watcher does no listing, no rule passes and + /// no injection; only Quick Launch entries are hidden at launch. + #[serde(default)] + pub quick_launch_only: bool, } impl Default for Config { @@ -100,6 +111,8 @@ impl Default for Config { tour_completed: false, window_rules: Vec::new(), quick_launch: Vec::new(), + protection_checker: true, + quick_launch_only: false, } } } @@ -176,6 +189,22 @@ mod tests { assert_eq!(cfg.normal_launch_pause_until_ms, 0); } + #[test] + fn new_fields_default_on_old_config() { + // An old config file, saved before these fields existed, must load + // with the checker on and Quick Launch only off. + let cfg: Config = serde_json::from_str(r#"{"hideSelf":true}"#).unwrap(); + assert!(cfg.protection_checker); + assert!(!cfg.quick_launch_only); + } + + #[test] + fn defaults_match_documented_behavior() { + let cfg = Config::default(); + assert!(cfg.protection_checker); + assert!(!cfg.quick_launch_only); + } + #[test] fn timed_pause_survives_serialization_and_resumes_at_deadline() { let cfg = Config { diff --git a/hmw-core/src/hider.rs b/hmw-core/src/hider.rs index bda3df0..994e2bb 100644 --- a/hmw-core/src/hider.rs +++ b/hmw-core/src/hider.rs @@ -86,3 +86,52 @@ pub fn check_protection(pid: u32, payload_path: &str) -> Result<()> { )) }) } + +/// How long a steady target goes without a protection health check. +pub const PROTECTION_RECHECK: std::time::Duration = std::time::Duration::from_secs(15); + +/// Decides when `check_protection` is worth a remote thread. A target is +/// checked when its visible window set changed since the last check, or when +/// the last check is older than `PROTECTION_RECHECK`. +#[derive(Debug, Default)] +pub struct ProtectionThrottle { + seen: std::collections::HashMap, +} + +impl ProtectionThrottle { + /// True when `pid` should be checked now; records the check when it is. + pub fn due(&mut self, pid: u32, signature: u64, now: std::time::Instant) -> bool { + match self.seen.get(&pid) { + Some(&(last, at)) + if last == signature && now.duration_since(at) < PROTECTION_RECHECK => + { + false + } + _ => { + self.seen.insert(pid, (signature, now)); + true + } + } + } + + /// Forget a pid, so its next check is immediate. + pub fn forget(&mut self, pid: u32) { + self.seen.remove(&pid); + } + + /// Drop entries for pids no longer being tracked. + pub fn retain(&mut self, keep: impl Fn(u32) -> bool) { + self.seen.retain(|&pid, _| keep(pid)); + } +} + +/// Order-independent fingerprint of a set of window handles. +pub fn window_signature(hwnds: impl IntoIterator) -> u64 { + hwnds.into_iter().fold(0u64, |acc, h| { + acc.wrapping_add( + (h as u64) + .wrapping_mul(0x9E37_79B9_7F4A_7C15) + .rotate_left(17), + ) + }) +} diff --git a/hmw-core/src/inject.rs b/hmw-core/src/inject.rs index 5586166..fed8a16 100644 --- a/hmw-core/src/inject.rs +++ b/hmw-core/src/inject.rs @@ -249,8 +249,49 @@ pub fn call_export(pid: u32, payload_path: &str, export: &str, hwnd: isize) -> R } } + // A loaded payload keeps its base for the life of the process. Remember it + // per (pid, start time, path) so steady targets skip the module snapshot. + let started = crate::process::process_started_at(pid); + if let Some(started) = started { + if let Some(base) = cached_base(pid, started, payload_path) { + match run_export(&handle, base, export, hwnd) { + Ok(()) => return Ok(()), + Err(_) => forget_base(pid), + } + } + } let base = ensure_loaded(&handle, pid, payload_path)?; - run_export(&handle, base, export, hwnd) + let result = run_export(&handle, base, export, hwnd); + match (&result, started) { + (Ok(()), Some(started)) => remember_base(pid, started, payload_path, base), + _ => forget_base(pid), + } + result +} + +type BaseCache = std::collections::HashMap; + +fn base_cache() -> std::sync::MutexGuard<'static, BaseCache> { + static CACHE: std::sync::OnceLock> = std::sync::OnceLock::new(); + CACHE + .get_or_init(Default::default) + .lock() + .unwrap_or_else(|p| p.into_inner()) +} + +fn cached_base(pid: u32, started: u64, payload_path: &str) -> Option { + match base_cache().get(&pid) { + Some((s, path, base)) if *s == started && path == payload_path => Some(*base), + _ => None, + } +} + +fn remember_base(pid: u32, started: u64, payload_path: &str, base: isize) { + base_cache().insert(pid, (started, payload_path.to_string(), base)); +} + +fn forget_base(pid: u32) { + base_cache().remove(&pid); } /// Start `export` of the payload at `base` in the target and wait for it. diff --git a/hmw-core/src/notifications.rs b/hmw-core/src/notifications.rs index b6e535e..2c7f0af 100644 --- a/hmw-core/src/notifications.rs +++ b/hmw-core/src/notifications.rs @@ -34,6 +34,12 @@ fn staged_payload(payload_path: &str) -> Result { if dest.parent().is_none_or(|dir| !dir.is_dir()) { return Ok(payload_path.to_string()); } + // Steady state: the staged copy is current, so leave the file alone. + if let (Ok(src), Ok(dst)) = (std::fs::metadata(payload_path), std::fs::metadata(&dest)) { + if src.len() == dst.len() && src.modified().ok() == dst.modified().ok() { + return Ok(dest.to_string_lossy().into_owned()); + } + } match std::fs::copy(payload_path, &dest) { Ok(_) => Ok(dest.to_string_lossy().into_owned()), Err(_) if dest.is_file() => Ok(dest.to_string_lossy().into_owned()), @@ -80,9 +86,46 @@ pub fn apply_notification_toasts(hidden: bool, payload_path: &str) -> Vec