From a177d38ab27c5e06810064c4d478404dfa1d4abe Mon Sep 17 00:00:00 2001 From: javis-bot Date: Sun, 15 Nov 2026 17:11:19 +0900 Subject: [PATCH] fix(screen): an excluded window never shows, also when it moves during the capture or its program cannot be told - Excluded windows are read before and after each monitor or whole-screen capture; when they differ, the capture is thrown away and taken again (at most 3 times, then refused). - A window whose program cannot be told counts as excluded: not listed, not picked, painted black. Co-Authored-By: Claude Opus 5.5 --- app/src/admin.spec.md | 9 +++-- app/src/screen.rs | 76 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/app/src/admin.spec.md b/app/src/admin.spec.md index 88388a2..25f3012 100644 --- a/app/src/admin.spec.md +++ b/app/src/admin.spec.md @@ -185,7 +185,10 @@ one window; the app captures and decides who may. - **Exclusions**: `pcControl.screenExclude` (program file names, ".exe" may be left out; default `1Password`, `Bitwarden`, `KeePass`, `KeePassXC`). Their windows are never captured or listed, and in a monitor or whole-screen picture their area is painted black before anything leaves the - capture. + capture. A window whose program cannot be told (its process refuses the query) counts as + excluded. The excluded windows are read before and after each monitor or whole-screen capture; + when they differ (one moved, was brought back or opened), that capture is thrown away and taken + again, at most 3 times, then refused ("보면 안 되는 창이 움직이는 중이라 지금은 볼 수 없습니다"). - **Pictures**: scaled down (area average) so the long side is at most 768 px (`fast`), 1280 px (`normal`) or, for `detailed`, cut in four parts of at most 1280 px each (a picture whose long side is at most 1600 px stays one part at full size); JPEG quality 80. At most 3 MiB of pictures per @@ -864,7 +867,9 @@ turns game mode on with its name and off once it ends. Screen viewing (`tests/sc the whole screen come back as JPEG pictures of their size, and with Notepad excluded it is neither picked nor listed and its area is black on the whole screen; someone not registered is refused. On every system with a fake screen: refusals before any capture, monitors by number, the whole screen -as placed with excluded areas black (also at another display scale), windows by title or program +as placed with excluded areas black (also at another display scale), an excluded window that +moves or is brought back during the capture never shown (taken again, or refused while it keeps +moving), a window of a program that cannot be told treated as excluded, windows by title or program front first (never excluded, secondary or the app's own), minimised and black pictures refused, the detail sizes and parts; the worker protocol test carries a 4K capture's pictures to a fake brain and back. Performance stages (on every system, with a fake diff --git a/app/src/screen.rs b/app/src/screen.rs index 3854cb8..df9f059 100644 --- a/app/src/screen.rs +++ b/app/src/screen.rs @@ -141,10 +141,20 @@ fn not_registered() -> String { "PC 제어 화면에 등록된 사람만 화면을 볼 수 있습니다".into() } +/// Excluded: on the list, or a program that could not be told (its process refused the query), so +/// no excluded program slips through unnamed. fn excluded(s: &Settings, program: &str) -> bool { - crate::game::listed(program, &s.pc_control.screen_exclude) + program.is_empty() || crate::game::listed(program, &s.pc_control.screen_exclude) } +/// Where excluded windows show now (minimised ones show nowhere). +fn hidden_rects(s: &Settings, all: &[Window]) -> Vec { + all.iter().filter(|w| !w.minimised && excluded(s, &w.program)).map(|w| w.rect).collect() +} + +/// Captures of monitors and screens tried while excluded windows keep moving. +const STILL_TRIES: usize = 3; + /// The windows the list shows and a window request may pick: not secondary, not this app's, not /// excluded; front first. fn listable<'a>(s: &'a Settings, all: &'a [Window]) -> impl Iterator + 'a { @@ -331,9 +341,21 @@ pub fn act(s: &Settings, screen: &dyn Screen, a: &ScreenAction) -> Result = screen.windows()?.iter() - .filter(|w| !w.minimised && excluded(s, &w.program)).map(|w| w.rect).collect(); - let (img, black) = whole(screen, &chosen, &hidden)?; + // Excluded windows are read before and after the capture; if one moved, was + // brought back or opened meanwhile, the black areas may miss it: that capture + // is thrown away. + let mut tries = 0; + let (img, black) = loop { + let before = hidden_rects(s, &screen.windows()?); + let shot = whole(screen, &chosen, &before)?; + if hidden_rects(s, &screen.windows()?) == before { + break shot; + } + tries += 1; + if tries == STILL_TRIES { + return Err("보면 안 되는 창이 움직이는 중이라 지금은 볼 수 없습니다".into()); + } + }; (img, black, activity_target(&target)) } }; @@ -581,6 +603,9 @@ mod tests { struct Fake { monitors: Vec, windows: Vec, + /// What the next reads of the windows give, one each, before `windows` again: a window + /// that moves while the screen is captured. + later: RefCell>>, shot: Image, captured: RefCell>, } @@ -590,7 +615,8 @@ mod tests { Ok(self.monitors.clone()) } fn windows(&self) -> Result, String> { - Ok(self.windows.clone()) + let mut later = self.later.borrow_mut(); + Ok(if later.is_empty() { self.windows.clone() } else { later.remove(0) }) } fn capture_monitor(&self, m: &Monitor) -> Result { self.captured.borrow_mut().push(format!("monitor {}", m.number)); @@ -619,6 +645,7 @@ mod tests { win("notepad.exe", "메모", Rect { x: 0, y: 0, w: 50, h: 50 }), Window { own: true, ..win("jarvis.exe", "Jarvis 관리", Rect { x: 0, y: 0, w: 50, h: 50 }) }, ], + later: RefCell::new(vec![]), shot: solid(800, 600, 120), captured: RefCell::new(vec![]), } @@ -682,6 +709,45 @@ mod tests { assert_eq!(at(500, 250), 0, "nothing outside the monitors"); } + #[test] + fn an_excluded_window_that_moves_or_comes_back_during_the_capture_never_shows() { + let s = settings(); + let moved = |x: i32, minimised: bool| { + let mut w = fake().windows; + w[0].rect.x = x; + w[0].minimised = minimised; + w + }; + // Moved between the reading before and after the capture: that capture is thrown away and + // the next one, with the window still, is sent. + let f = fake(); + *f.later.borrow_mut() = vec![moved(10, false), moved(200, false)]; + assert!(act(&s, &f, &action("capture", OWNER, json!({"target": "screen"}))).is_ok()); + assert_eq!(f.captured.borrow().len(), 4, "captured twice"); + // Brought back from the task bar during the capture: the same. + let f = fake(); + *f.later.borrow_mut() = vec![moved(10, true), moved(10, false)]; + assert!(act(&s, &f, &action("capture", OWNER, json!({"target": "monitor", "monitor": 1}))).is_ok()); + assert_eq!(f.captured.borrow().len(), 2, "captured twice"); + // Moving all the time: nothing is sent. + let f = fake(); + *f.later.borrow_mut() = (0..20).map(|i| moved(i * 7, false)).collect(); + let e = act(&s, &f, &action("capture", OWNER, json!({"target": "screen"}))).unwrap_err(); + assert!(e.contains("움직"), "{e}"); + } + + #[test] + fn a_window_whose_program_cannot_be_told_is_treated_as_excluded() { + let s = settings(); + let mut f = fake(); + f.windows = vec![win("", "Vault - unlocked", Rect { x: 10, y: 10, w: 100, h: 50 })]; + assert!(pick_window(&s, &f.windows, "vault").is_none()); + let v = act(&s, &f, &action("list", OWNER, json!({}))).unwrap(); + assert_eq!(v["item"]["windows"], json!([])); + let hidden = hidden_rects(&s, &f.windows); + assert_eq!(hidden, vec![f.windows[0].rect], "painted black on the screen"); + } + #[test] fn excluded_areas_follow_a_monitor_captured_at_another_scale() { // A picture twice the placed size (display scaling): the black area doubles with it.