fix(v2): pcControl keys reach a Store app agent-desktop cannot name by its window
On the game PC agent-desktop's press --window-id answers APP_NOT_FOUND for
the new Calculator ("not found with exact process identity", nothing sent),
though focus-window brings it in front. The keys now go to the window in
front while it is still that window. The Windows test checks Notepad's typed
text by element values only (a label such as Ctrl+Shift+X contains "hi").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,13 @@ fn text(reply: &Value) -> String {
|
||||
.map(|e| format!("{} {}", e["name"].as_str().unwrap_or(""), e["value"].as_str().unwrap_or(""))).collect::<Vec<_>>().join(" | ")
|
||||
}
|
||||
|
||||
/// Every element's value of a reading, joined: the typed text without the window's labels (a label
|
||||
/// such as "Ctrl+Shift+X" contains "hi").
|
||||
fn values(reply: &Value) -> String {
|
||||
reply["item"]["elements"].as_array().into_iter().flatten()
|
||||
.filter_map(|e| e["value"].as_str()).collect::<Vec<_>>().join(" | ")
|
||||
}
|
||||
|
||||
/// Closed however the test ends (by name too: a program may hand over to another process).
|
||||
struct Closed(Vec<String>, Vec<std::process::Child>);
|
||||
|
||||
@@ -100,7 +107,7 @@ fn keys_go_behind_or_in_front_for_a_moment_and_the_window_in_front_stays() {
|
||||
}
|
||||
let read = act(&pc, "read", json!({"window": notepad}));
|
||||
println!("notepad after behind: {}", text(&read).chars().take(300).collect::<String>());
|
||||
assert!(text(&read).contains("hi") && text(&read).contains("ok"), "the letters reached Notepad behind");
|
||||
assert!(values(&read).contains("hi") && values(&read).contains("ok"), "the letters reached Notepad behind");
|
||||
|
||||
// A combination goes in front for a moment, then the window in front is back.
|
||||
let r = act(&pc, "keys", json!({"window": notepad, "keys": "ctrl+a"}));
|
||||
@@ -108,9 +115,9 @@ fn keys_go_behind_or_in_front_for_a_moment_and_the_window_in_front_stays() {
|
||||
assert_eq!(probe.foreground().as_deref(), Some(front.as_str()), "ctrl+a: the window in front is back");
|
||||
let r = act(&pc, "keys", json!({"window": notepad, "keys": "x"}));
|
||||
assert_eq!(r["ok"], true, "x: {r}");
|
||||
let after = text(&act(&pc, "read", json!({"window": notepad})));
|
||||
println!("notepad after ctrl+a, x: {}", after.chars().take(300).collect::<String>());
|
||||
assert!(!after.contains("hi"), "ctrl+a selected the text and x replaced it");
|
||||
let after = values(&act(&pc, "read", json!({"window": notepad})));
|
||||
println!("notepad after ctrl+a, x: {after:?}");
|
||||
assert!(after.contains('x') && !after.contains("hi"), "ctrl+a selected the text and x replaced it");
|
||||
|
||||
// The Calculator: in front for a moment when it does not take keys behind (the Store app).
|
||||
let calc = act(&pc, "run", json!({"program": "calc"}));
|
||||
|
||||
Reference in New Issue
Block a user