Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

Windows: names from calls through UI Automation (Meet in a browser, Teams, Zoom), as on Linux (#70)

christianmat89fa33d03d8a
diff --git a/app/native/yogurt-system/Cargo.toml b/app/native/yogurt-system/Cargo.toml
index 7d0cb690..50759ef4 100644
--- a/app/native/yogurt-system/Cargo.toml
+++ b/app/native/yogurt-system/Cargo.toml
@@ -23,6 +23,7 @@ windows = { version = "=0.58.0", features = [
"Win32_System_Variant",
"Win32_System_Diagnostics_ToolHelp",
"Win32_System_Threading",
+ "Win32_UI_Accessibility",
"Win32_UI_WindowsAndMessaging",
] }
diff --git a/app/native/yogurt-system/smoke/windows.ps1 b/app/native/yogurt-system/smoke/windows.ps1
index 5ef3c7e9..128c0746 100644
--- a/app/native/yogurt-system/smoke/windows.ps1
+++ b/app/native/yogurt-system/smoke/windows.ps1
@@ -53,6 +53,38 @@ try {
} finally { Stop-Process -Id $p.Id -Force }
Check 'no window for an app that is not open' { param($v) $null -eq $v.title } (& $Bin browser-title notrunninghere.exe)
+# call-watch: a window shaped like a Meet call (its title has the word Meet) with a person's name in it, read through
+# UI Automation; the watch ends when its stdin closes
+$form = "Add-Type -AssemblyName System.Windows.Forms; `$f = New-Object System.Windows.Forms.Form; `$f.Text = '$title'; `$l = New-Object System.Windows.Forms.Label; `$l.Text = 'Ana Ruiz'; `$f.Controls.Add(`$l); [System.Windows.Forms.Application]::Run(`$f)"
+$p = Start-Process powershell.exe -ArgumentList '-NoProfile', '-WindowStyle', 'Hidden', '-Command', $form -PassThru
+try {
+ $psi = New-Object System.Diagnostics.ProcessStartInfo $Bin
+ $psi.Arguments = 'call-watch 400 notrunninghere.exe powershell.exe'
+ $psi.UseShellExecute = $false
+ $psi.RedirectStandardOutput = $true
+ $psi.RedirectStandardInput = $true
+ $w = [System.Diagnostics.Process]::Start($psi)
+ $raw = $null
+ for ($i = 0; $i -lt 60 -and -not $raw; $i++) {
+ $line = $w.StandardOutput.ReadLine()
+ if ($line -match '"app":"powershell.exe"' -and $line -match 'Ana Ruiz') { $raw = $line }
+ }
+ if (-not $raw) { throw "failed: call-watch never read the window; last line: $line" }
+ Write-Host "call-watch: $($raw.Substring(0, [Math]::Min(600, $raw.Length)))"
+ function Find($n, $role, $text) {
+ if ($n.r -eq $role -and $n.t -eq $text) { return $true }
+ foreach ($k in @($n.k)) { if ($k -and (Find $k $role $text)) { return $true } }
+ return $false
+ }
+ Check 'call-watch reads the call window' { param($v) $v.app -eq 'powershell.exe' -and $v.windows[0].title -eq $title -and $v.t -gt 0 } $raw
+ Check 'the name is a label, as AT-SPI calls it' { param($v) Find $v.windows[0].tree 'label' 'Ana Ruiz' } $raw
+ $w.StandardInput.Close()
+ if (-not $w.WaitForExit(5000)) { $w.Kill(); throw 'failed: call-watch did not end when its stdin closed' }
+ Write-Host 'ok: call-watch ends when its stdin closes'
+} finally { Stop-Process -Id $p.Id -Force }
+$raw = & $Bin call-watch 2>$null
+if ($LASTEXITCODE -eq 0) { throw 'call-watch with no ids should fail' }
+
& $Bin browser-title 2>$null
if ($LASTEXITCODE -eq 0) { throw 'browser-title with no id should fail' }
Write-Host 'all Windows smoke checks passed'
diff --git a/app/native/yogurt-system/src/call.rs b/app/native/yogurt-system/src/call.rs
new file mode 100644
index 00000000..04c9f6d4
--- /dev/null
+++ b/app/native/yogurt-system/src/call.rs
@@ -0,0 +1,114 @@
+//! What Linux's and Windows's call watches share: which app a call is in, which windows can hold it, and whether a
+//! window's tree is a call (Teams keeps its calendar and chat in windows shaped like the call's).
+
+use serde_json::Value;
+use std::time::{SystemTime, UNIX_EPOCH};
+
+/// what kind of window a call app has, from its id (detect.ts's names carry the app)
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub enum Kind {
+ Zoom,
+ Teams,
+ Meet,
+}
+
+pub fn kind(id: &str) -> Kind {
+ let id = id.to_ascii_lowercase();
+ if id.contains("zoom") {
+ Kind::Zoom
+ } else if id.contains("teams") {
+ Kind::Teams
+ } else {
+ Kind::Meet
+ }
+}
+
+/// the controls only a call window has: the calendar and chat views have none
+pub const CALL_CONTROLS: &[&str] = &["leave", "leave call", "hang up", "end call", "mute mic", "unmute mic", "close participants pane"];
+
+/// Whether a tree has a call control: the calendar and chat views have no Leave or Mute, the call window always does
+pub fn is_call_tree(tree: &Value) -> bool {
+ fn walk(n: &Value) -> bool {
+ let Some(o) = n.as_object() else { return false };
+ let role = o.get("r").and_then(Value::as_str).unwrap_or("");
+ if matches!(role, "button" | "push button" | "toggle button" | "menu item") {
+ for key in ["t", "d"] {
+ if let Some(s) = o.get(key).and_then(Value::as_str) {
+ if CALL_CONTROLS.contains(&s.trim().to_ascii_lowercase().as_str()) {
+ return true;
+ }
+ }
+ }
+ }
+ o.get("k").and_then(Value::as_array).is_some_and(|kids| kids.iter().any(walk))
+ }
+ walk(tree)
+}
+
+/// Whether a window may hold the call: a browser only when its front tab is a Meet call, Zoom only a meeting, Teams
+/// any window (its calendar and chat views look like the call's; is_call_tree tells them apart)
+pub fn call_window(kind: Kind, title: &str) -> bool {
+ match kind {
+ Kind::Teams => true,
+ Kind::Zoom => title.starts_with("Zoom Meeting") || title.starts_with("Zoom Webinar") || title == "Meeting",
+ Kind::Meet => has_word(title, "meet"),
+ }
+}
+
+/// "Meet - abc-defg-hij" has the word; "Meeting notes" does not
+pub fn has_word(title: &str, word: &str) -> bool {
+ title.split(|c: char| !c.is_alphanumeric()).any(|w| w.eq_ignore_ascii_case(word))
+}
+
+pub fn now_ms() -> u64 {
+ SystemTime::now().duration_since(UNIX_EPOCH).map(|d| d.as_millis() as u64).unwrap_or(0)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+
+ #[test]
+ fn the_kind_comes_from_the_id() {
+ assert_eq!(kind("us.zoom.xos"), Kind::Zoom);
+ assert_eq!(kind("zoom"), Kind::Zoom);
+ assert_eq!(kind("com.microsoft.teams2"), Kind::Teams);
+ assert_eq!(kind("teams-for-linux"), Kind::Teams);
+ assert_eq!(kind("com.github.IsmaelMartinez.teams_for_linux"), Kind::Teams);
+ assert_eq!(kind("com.google.Chrome"), Kind::Meet);
+ assert_eq!(kind("firefox"), Kind::Meet);
+ // Windows: the program's file name, lowercased
+ assert_eq!(kind("zoom.exe"), Kind::Zoom);
+ assert_eq!(kind("ms-teams.exe"), Kind::Teams);
+ assert_eq!(kind("msedge.exe"), Kind::Meet);
+ }
+
+ #[test]
+ fn a_browser_window_is_a_call_only_with_the_word_meet() {
+ assert!(call_window(Kind::Meet, "Meet - abc-defg-hij - Google Chrome"));
+ assert!(call_window(Kind::Meet, "meet.google.com"));
+ assert!(call_window(Kind::Meet, "Meet – abc-defg-hij and 1 more page - Work - Microsoft Edge"));
+ assert!(!call_window(Kind::Meet, "Meeting notes - Google Chrome"));
+ assert!(call_window(Kind::Zoom, "Zoom Meeting"));
+ assert!(call_window(Kind::Zoom, "Meeting"));
+ assert!(call_window(Kind::Zoom, "Zoom Webinar - 123"));
+ assert!(!call_window(Kind::Zoom, "Zoom Workplace"));
+ }
+
+ #[test]
+ fn only_a_tree_with_call_controls_is_a_call() {
+ let call = json!({ "r": "frame", "k": [
+ { "r": "static", "t": "Calendar | Meeting with Dana Smith | Microsoft Teams" },
+ { "r": "button", "t": "Mute mic" },
+ { "r": "button", "t": "Leave" }
+ ] });
+ assert!(is_call_tree(&call));
+ let calendar = json!({ "r": "frame", "k": [
+ { "r": "static", "t": "Calendar | Meeting with Dana Smith | Microsoft Teams" },
+ { "r": "button", "t": "Go to today November 12, 2026" }
+ ] });
+ assert!(!is_call_tree(&calendar));
+ assert!(!is_call_tree(&json!({})));
+ }
+}
diff --git a/app/native/yogurt-system/src/calls.rs b/app/native/yogurt-system/src/calls.rs
index 6cacbfa3..8c027d8c 100644
--- a/app/native/yogurt-system/src/calls.rs
+++ b/app/native/yogurt-system/src/calls.rs
@@ -3,30 +3,12 @@
use std::fs;
use std::io::Read;
-use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
+use std::time::{Duration, Instant};
use serde_json::{json, Value};
use crate::atspi::{window_role, A11y, App};
-
-/// what kind of window a call app has, from its id (detect.ts's names carry the app)
-#[derive(Clone, Copy, Debug, PartialEq)]
-enum Kind {
- Zoom,
- Teams,
- Meet,
-}
-
-fn kind(id: &str) -> Kind {
- let id = id.to_ascii_lowercase();
- if id.contains("zoom") {
- Kind::Zoom
- } else if id.contains("teams") {
- Kind::Teams
- } else {
- Kind::Meet
- }
-}
+use crate::call::{call_window, is_call_tree, kind, now_ms, Kind};
/// The watch: read the apps asked about every `every_ms`, until Yogurt closes stdin (or dies, which closes it too)
pub fn watch(every_ms: u64, ids: &[String]) -> ! {
@@ -78,8 +60,6 @@ pub fn watch(every_ms: u64, ids: &[String]) -> ! {
/// one reading stops walking after this long: an app that stopped answering cannot hold the watch for minutes
const READ_DEADLINE: Duration = Duration::from_millis(1500);
-/// the controls only a call window has: the calendar and chat views have none
-const CALL_CONTROLS: &[&str] = &["leave", "leave call", "hang up", "end call", "mute mic", "unmute mic", "close participants pane"];
/// how much of a Teams window to read before trusting it is a call (the measured call has its Leave button within ~200)
const CALL_PROBE: i32 = 1200;
@@ -150,40 +130,6 @@ fn windows(a11y: &A11y, app: &App, kind: Kind, deadline: Instant) -> Vec<Value>
out
}
-/// Whether a tree has a call control: the calendar and chat views have no Leave or Mute, the call window always does
-fn is_call_tree(tree: &Value) -> bool {
- fn walk(n: &Value) -> bool {
- let Some(o) = n.as_object() else { return false };
- let role = o.get("r").and_then(Value::as_str).unwrap_or("");
- if matches!(role, "button" | "push button" | "toggle button" | "menu item") {
- for key in ["t", "d"] {
- if let Some(s) = o.get(key).and_then(Value::as_str) {
- if CALL_CONTROLS.contains(&s.trim().to_ascii_lowercase().as_str()) {
- return true;
- }
- }
- }
- }
- o.get("k").and_then(Value::as_array).is_some_and(|kids| kids.iter().any(walk))
- }
- walk(tree)
-}
-
-/// Whether a window may hold the call: a browser only when its front tab is a Meet call, Zoom only a meeting, Teams
-/// any window (its calendar and chat views look like the call's; is_call_tree tells them apart)
-fn call_window(kind: Kind, title: &str) -> bool {
- match kind {
- Kind::Teams => true,
- Kind::Zoom => title.starts_with("Zoom Meeting") || title.starts_with("Zoom Webinar") || title == "Meeting",
- Kind::Meet => has_word(title, "meet"),
- }
-}
-
-/// "Meet - abc-defg-hij" has the word; "Meeting notes" does not
-fn has_word(title: &str, word: &str) -> bool {
- title.split(|c: char| !c.is_alphanumeric()).any(|w| w.eq_ignore_ascii_case(word))
-}
-
/// The id asked about that this process is: its Flatpak app id, else its program name
fn matched_id(pid: u32, ids: &[String]) -> Option<String> {
if let Some(id) = matched_id_here(pid, ids) {
@@ -244,52 +190,10 @@ fn program_name_of(cmdline: &[u8]) -> Option<String> {
(!base.is_empty()).then(|| base.to_string())
}
-fn now_ms() -> u64 {
- SystemTime::now().duration_since(UNIX_EPOCH).map(|d| d.as_millis() as u64).unwrap_or(0)
-}
-
#[cfg(test)]
mod tests {
use super::*;
- #[test]
- fn the_kind_comes_from_the_id() {
- assert_eq!(kind("us.zoom.xos"), Kind::Zoom);
- assert_eq!(kind("zoom"), Kind::Zoom);
- assert_eq!(kind("com.microsoft.teams2"), Kind::Teams);
- assert_eq!(kind("teams-for-linux"), Kind::Teams);
- assert_eq!(kind("com.github.IsmaelMartinez.teams_for_linux"), Kind::Teams);
- assert_eq!(kind("com.google.Chrome"), Kind::Meet);
- assert_eq!(kind("firefox"), Kind::Meet);
- }
-
- #[test]
- fn a_browser_window_is_a_call_only_with_the_word_meet() {
- assert!(call_window(Kind::Meet, "Meet - abc-defg-hij - Google Chrome"));
- assert!(call_window(Kind::Meet, "meet.google.com"));
- assert!(!call_window(Kind::Meet, "Meeting notes - Google Chrome"));
- assert!(call_window(Kind::Zoom, "Zoom Meeting"));
- assert!(call_window(Kind::Zoom, "Meeting"));
- assert!(call_window(Kind::Zoom, "Zoom Webinar - 123"));
- assert!(!call_window(Kind::Zoom, "Zoom Workplace"));
- }
-
- #[test]
- fn only_a_tree_with_call_controls_is_a_call() {
- let call = json!({ "r": "frame", "k": [
- { "r": "static", "t": "Calendar | Meeting with Dana Smith | Microsoft Teams" },
- { "r": "button", "t": "Mute mic" },
- { "r": "button", "t": "Leave" }
- ] });
- assert!(is_call_tree(&call));
- let calendar = json!({ "r": "frame", "k": [
- { "r": "static", "t": "Calendar | Meeting with Dana Smith | Microsoft Teams" },
- { "r": "button", "t": "Go to today November 12, 2026" }
- ] });
- assert!(!is_call_tree(&calendar));
- assert!(!is_call_tree(&json!({})));
- }
-
#[test]
fn a_flatpak_id_comes_from_the_cgroup() {
let line = "0::/user.slice/user-1000.slice/[email protected]/app.slice/app-flatpak-com.github.IsmaelMartinez.teams_for_linux-1512112203.scope";
diff --git a/app/native/yogurt-system/src/main.rs b/app/native/yogurt-system/src/main.rs
index dd1b47ee..ff1349f8 100644
--- a/app/native/yogurt-system/src/main.rs
+++ b/app/native/yogurt-system/src/main.rs
@@ -4,7 +4,7 @@
//! mic-apps [{"bundleId","name","pid"}] for each app recording from a microphone now
//! running-apps ID... the IDs that have a running process
//! browser-title ID {"title": the app's front window title, or null}
-//! call-watch MS ID... Linux: one JSON line every MS with the call app's windows (yogurt-mac's call-watch)
+//! call-watch MS ID... one JSON line every MS with the call app's windows (yogurt-mac's call-watch)
//!
//! IDs are the program's file name: "zoom.exe" (lowercased) on Windows, "zoom" or a Flatpak app id on Linux.
@@ -12,6 +12,8 @@
#[allow(dead_code)]
mod parse;
+#[cfg(any(target_os = "linux", windows))]
+mod call;
#[cfg(target_os = "linux")]
mod atspi;
#[cfg(target_os = "linux")]
@@ -20,6 +22,8 @@ mod calls;
mod linux;
#[cfg(windows)]
mod win;
+#[cfg(windows)]
+mod wincalls;
#[cfg(target_os = "linux")]
use linux as os;
@@ -29,10 +33,7 @@ use win as os;
use serde_json::{json, Value};
use std::io::Write;
-#[cfg(target_os = "linux")]
const USAGE: &str = "yogurt-system mic-apps | running-apps APP_ID... | browser-title APP_ID | call-watch MS APP_ID...";
-#[cfg(not(target_os = "linux"))]
-const USAGE: &str = "yogurt-system mic-apps | running-apps APP_ID... | browser-title APP_ID";
fn out(v: Value) {
let mut stdout = std::io::stdout().lock();
@@ -56,13 +57,17 @@ fn main() {
}
out(json!({ "title": os::window_title(&args[1]) }))
}
- #[cfg(target_os = "linux")]
Some("call-watch") => {
if args.len() < 3 {
fail("call-watch MS APP_ID...")
}
let every = args[1].parse::<u64>().unwrap_or(400);
- calls::watch(every, &args[2..])
+ #[cfg(target_os = "linux")]
+ calls::watch(every, &args[2..]);
+ #[cfg(windows)]
+ wincalls::watch(every, &args[2..]);
+ #[cfg(not(any(target_os = "linux", windows)))]
+ fail(&format!("call-watch {every}: Linux and Windows only"))
}
_ => fail(USAGE),
}
diff --git a/app/native/yogurt-system/src/parse.rs b/app/native/yogurt-system/src/parse.rs
index 36a6f8af..3c3a598e 100644
--- a/app/native/yogurt-system/src/parse.rs
+++ b/app/native/yogurt-system/src/parse.rs
@@ -179,6 +179,39 @@ pub fn argv0_base(cmdline: &[u8]) -> Option<String> {
(!base.is_empty()).then_some(base)
}
+/// A UI Automation control type (UIA_ButtonControlTypeId = 50000 ...) by the role AT-SPI gives the same thing, so
+/// src/main/callNames/parse.ts reads a Windows call window with the rules it has for Linux
+pub fn uia_role(control_type: i32) -> &'static str {
+ match control_type {
+ 50000 | 50031 => "push button",
+ 50002 => "check box",
+ 50003 => "combo box",
+ 50004 => "entry",
+ 50005 => "link",
+ 50006 => "image",
+ 50007 => "list item",
+ 50008 => "list",
+ 50009 => "menu",
+ 50010 => "menu bar",
+ 50011 => "menu item",
+ 50013 => "radio button",
+ 50018 => "page tab list",
+ 50019 => "page tab",
+ 50020 => "label",
+ 50021 => "tool bar",
+ 50023 => "tree",
+ 50024 => "tree item",
+ 50026 | 50033 => "panel",
+ 50028 | 50036 => "table",
+ 50029 => "table row",
+ 50030 => "document web",
+ 50032 => "frame",
+ 50034 => "header",
+ 50037 => "title bar",
+ _ => "unknown",
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -312,4 +345,16 @@ mod tests {
assert_eq!(argv0_base(b"/usr/lib/firefox/firefox\0-contentproc\0").as_deref(), Some("firefox"));
assert_eq!(argv0_base(b""), None);
}
+
+ #[test]
+ fn ui_automation_types_get_at_spi_roles() {
+ assert_eq!(uia_role(50019), "page tab");
+ assert_eq!(uia_role(50020), "label");
+ assert_eq!(uia_role(50024), "tree item");
+ assert_eq!(uia_role(50023), "tree");
+ assert_eq!(uia_role(50000), "push button");
+ assert_eq!(uia_role(50029), "table row");
+ assert_eq!(uia_role(50008), "list");
+ assert_eq!(uia_role(12345), "unknown");
+ }
}
diff --git a/app/native/yogurt-system/src/win.rs b/app/native/yogurt-system/src/win.rs
index 871493a4..01ccc444 100644
--- a/app/native/yogurt-system/src/win.rs
+++ b/app/native/yogurt-system/src/win.rs
@@ -1,5 +1,5 @@
//! Windows: who records from a microphone (Core Audio sessions, then the privacy ConsentStore), running programs
-//! (Toolhelp) and window titles (EnumWindows). None of these need a permission.
+//! (Toolhelp) and window titles (EnumWindows). None of these need a permission. Call windows are read in wincalls.rs.
use crate::parse::{self, MicApp, Proc};
use std::collections::HashMap;
@@ -23,7 +23,7 @@ fn utf16(buf: &[u16]) -> String {
String::from_utf16_lossy(&buf[..len])
}
-fn processes() -> HashMap<u32, Proc> {
+pub fn processes() -> HashMap<u32, Proc> {
let mut map = HashMap::new();
unsafe {
let Ok(snap) = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) else { return map };
@@ -161,14 +161,20 @@ unsafe extern "system" fn each_window(hwnd: HWND, data: LPARAM) -> BOOL {
BOOL(1)
}
-/** The app's foreground window title, else its topmost visible one. EnumWindows lists top-level windows top first. */
-pub fn window_title(id: &str) -> Option<String> {
- let id = id.to_lowercase();
- let procs = processes();
+/** Every visible top-level window with a title: (handle, process id, title), top first */
+pub fn top_windows() -> Vec<(u64, u32, String)> {
let mut found: Vec<(u64, u32, String)> = Vec::new();
unsafe {
let _ = EnumWindows(Some(each_window), LPARAM(&mut found as *mut _ as isize));
}
+ found
+}
+
+/** The app's foreground window title, else its topmost visible one. EnumWindows lists top-level windows top first. */
+pub fn window_title(id: &str) -> Option<String> {
+ let id = id.to_lowercase();
+ let procs = processes();
+ let found = top_windows();
let active = unsafe { GetForegroundWindow() }.0 as usize as u64;
let windows: Vec<(u64, bool, String)> =
found.into_iter().map(|(h, pid, title)| (h, procs.get(&pid).is_some_and(|p| parse::exe_id(&p.exe) == id), title)).collect();
diff --git a/app/native/yogurt-system/src/wincalls.rs b/app/native/yogurt-system/src/wincalls.rs
new file mode 100644
index 00000000..a8b70c97
--- /dev/null
+++ b/app/native/yogurt-system/src/wincalls.rs
@@ -0,0 +1,193 @@
+//! `yogurt-system call-watch MS ID...` on Windows: who is in a call and who is talking, as the call app shows it through
+//! UI Automation, one JSON line per reading (the same shape as yogurt-mac's call-watch and Linux's calls.rs).
+//! UI Automation needs no permission. Chromium (Meet in Chrome or Edge, and the new Teams, which is Edge's WebView2)
+//! gives its page's elements with their DOM classes as ClassName; Zoom gives its own controls.
+
+use std::io::Read;
+use std::time::{Duration, Instant};
+
+use serde_json::{json, Map, Value};
+use windows::core::Interface;
+use windows::Win32::Foundation::HWND;
+use windows::Win32::System::Com::{CoCreateInstance, CoInitializeEx, CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED};
+use windows::Win32::UI::Accessibility::{
+ AutomationElementMode_None, CUIAutomation, CUIAutomation8, IUIAutomation, IUIAutomation2, IUIAutomationCacheRequest,
+ IUIAutomationElement, TreeScope_Subtree, UIA_AutomationIdPropertyId, UIA_ClassNamePropertyId, UIA_ControlTypePropertyId,
+ UIA_HelpTextPropertyId, UIA_NamePropertyId,
+};
+
+use crate::call::{call_window, is_call_tree, kind, now_ms, Kind};
+use crate::parse;
+
+/// at most this many call windows of the app per reading
+const MAX_WINDOWS: usize = 4;
+/// how much of one window is copied out, and how deep (as on Linux)
+const BUDGET: i32 = 4000;
+const MAX_DEPTH: usize = 40;
+/// an app that stopped answering gives up its reading after this long, so it cannot hold the watch
+const TIMEOUT_MS: u32 = 1500;
+/// longer text is cut: names and labels are short
+const MAX_TEXT: usize = 300;
+
+struct Uia {
+ uia: IUIAutomation,
+ req: IUIAutomationCacheRequest,
+}
+
+impl Uia {
+ fn new() -> windows::core::Result<Self> {
+ unsafe {
+ let _ = CoInitializeEx(None, COINIT_MULTITHREADED);
+ let uia: IUIAutomation = match CoCreateInstance(&CUIAutomation8, None, CLSCTX_INPROC_SERVER) {
+ Ok(u) => u,
+ Err(_) => CoCreateInstance(&CUIAutomation, None, CLSCTX_INPROC_SERVER)?,
+ };
+ if let Ok(u2) = uia.cast::<IUIAutomation2>() {
+ let _ = u2.SetConnectionTimeout(TIMEOUT_MS);
+ let _ = u2.SetTransactionTimeout(TIMEOUT_MS);
+ }
+ // the whole window comes over in one call, with just these properties: one element at a time would be a
+ // round trip to the app each
+ let req = uia.CreateCacheRequest()?;
+ for p in [UIA_ControlTypePropertyId, UIA_NamePropertyId, UIA_HelpTextPropertyId, UIA_AutomationIdPropertyId, UIA_ClassNamePropertyId] {
+ req.AddProperty(p)?;
+ }
+ req.SetTreeScope(TreeScope_Subtree)?;
+ // the raw view keeps the page's plain containers, so Meet's tiles have the depth they have on Linux
+ req.SetTreeFilter(&uia.RawViewCondition()?)?;
+ req.SetAutomationElementMode(AutomationElementMode_None)?;
+ Ok(Self { uia, req })
+ }
+ }
+
+ fn tree(&self, hwnd: u64) -> Option<Value> {
+ let el = unsafe { self.uia.ElementFromHandleBuildCache(HWND(hwnd as usize as *mut core::ffi::c_void), &self.req) }.ok()?;
+ let mut budget = BUDGET;
+ Some(node(&el, 0, &mut budget))
+ }
+}
+
+fn clip(s: &str) -> String {
+ let s = s.trim();
+ match s.char_indices().nth(MAX_TEXT) {
+ Some((i, _)) => s[..i].to_string(),
+ None => s.to_string(),
+ }
+}
+
+/// One element and what is under it, in the shape src/main/callNames/parse.ts reads (AxNode). What someone types is
+/// never copied: an edit field's value is not asked for.
+fn node(el: &IUIAutomationElement, depth: usize, budget: &mut i32) -> Value {
+ *budget -= 1;
+ let mut n = Map::new();
+ unsafe {
+ let role = el.CachedControlType().map(|t| parse::uia_role(t.0)).unwrap_or("unknown");
+ n.insert("r".into(), json!(role));
+ let name = el.CachedName().map(|b| b.to_string()).unwrap_or_default();
+ if !name.trim().is_empty() {
+ n.insert("t".into(), json!(clip(&name)));
+ }
+ if let Ok(help) = el.CachedHelpText().map(|b| b.to_string()) {
+ if !help.trim().is_empty() && help != name {
+ n.insert("d".into(), json!(clip(&help)));
+ }
+ }
+ if let Ok(id) = el.CachedAutomationId().map(|b| b.to_string()) {
+ if !id.is_empty() {
+ n.insert("i".into(), json!(clip(&id)));
+ }
+ }
+ if let Ok(class) = el.CachedClassName().map(|b| b.to_string()) {
+ let classes: Vec<&str> = class.split_whitespace().take(20).collect();
+ if !classes.is_empty() {
+ n.insert("c".into(), json!(classes));
+ }
+ }
+ if depth < MAX_DEPTH && *budget > 0 {
+ if let Ok(kids) = el.GetCachedChildren() {
+ let mut out = Vec::new();
+ for i in 0..kids.Length().unwrap_or(0) {
+ if *budget <= 0 {
+ break;
+ }
+ if let Ok(k) = kids.GetElement(i) {
+ out.push(node(&k, depth + 1, budget));
+ }
+ }
+ if !out.is_empty() {
+ n.insert("k".into(), json!(out));
+ }
+ }
+ }
+ }
+ Value::Object(n)
+}
+
+/// The watch: read the apps asked about every `every_ms`, until Yogurt closes stdin (or dies, which closes it too)
+pub fn watch(every_ms: u64, ids: &[String]) -> ! {
+ std::thread::spawn(|| {
+ let mut sink = Vec::new();
+ let _ = std::io::stdin().read_to_end(&mut sink);
+ std::process::exit(0);
+ });
+ let every = every_ms.max(100);
+ let ids: Vec<String> = ids.iter().map(|id| id.to_lowercase()).collect();
+ let mut uia: Option<Uia> = None;
+ let mut complained = false;
+ loop {
+ let started = Instant::now();
+ if uia.is_none() {
+ match Uia::new() {
+ Ok(u) => uia = Some(u),
+ Err(e) => {
+ if !complained {
+ eprintln!("call-watch: {e}");
+ complained = true;
+ }
+ }
+ }
+ }
+ let line = match &uia {
+ Some(u) => read_once(u, &ids),
+ None => json!({ "t": now_ms(), "error": "no-accessibility" }),
+ };
+ crate::out(line);
+ // a slow app (a big page) is read less often, so the reading never takes much of the computer
+ let took = started.elapsed().as_millis() as u64;
+ std::thread::sleep(Duration::from_millis(every.max(took * 2).saturating_sub(took)));
+ }
+}
+
+/// The first app asked about with a call window, and its call windows, top first
+fn read_once(u: &Uia, ids: &[String]) -> Value {
+ let t = now_ms();
+ let procs = crate::win::processes();
+ let mut seen = false;
+ let mut app: Option<String> = None;
+ let mut windows = Vec::new();
+ for (hwnd, pid, title) in crate::win::top_windows() {
+ let Some(p) = procs.get(&pid) else { continue };
+ let exe = parse::exe_id(&p.exe);
+ let Some(id) = ids.iter().find(|id| **id == exe) else { continue };
+ seen = true;
+ if windows.len() == MAX_WINDOWS || app.as_ref().is_some_and(|a| a != id) {
+ continue;
+ }
+ let k = kind(id);
+ if !call_window(k, &title) {
+ continue;
+ }
+ let Some(tree) = u.tree(hwnd) else { continue };
+ // Teams's calendar and chat windows look like the call's: only a window with call controls is sent, so their
+ // text never reaches the JSON or the log
+ if k == Kind::Teams && !is_call_tree(&tree) {
+ continue;
+ }
+ app = Some(id.clone());
+ windows.push(json!({ "title": title, "tree": tree }));
+ }
+ match app {
+ Some(app) => json!({ "t": t, "app": app, "windows": windows }),
+ None => json!({ "t": t, "error": if seen { "no-call-window" } else { "not-running" } }),
+ }
+}
diff --git a/app/src/main/callNames/index.ts b/app/src/main/callNames/index.ts
index a470e958..ee00e364 100644
--- a/app/src/main/callNames/index.ts
+++ b/app/src/main/callNames/index.ts
@@ -5,7 +5,7 @@ import { readCall, summarize, type AxWindow, type CallKind } from './parse'
/**
* Names from the call: while a meeting records, the call app it is in (Zoom, Teams, Meet in a browser) is read through
- * the accessibility tree about twice a second (macOS Accessibility, AT-SPI on Linux), and each line of the other side
+ * the accessibility tree about twice a second (macOS Accessibility, AT-SPI on Linux, UI Automation on Windows), and each line of the other side
* is named after the person the app shows talking, or the only other person in the call. The mic is always You.
* Without the permission, in another app, or when the app shows nothing clear, lines of the other side are Them.
* Nothing is guessed, and nothing leaves the computer.
@@ -16,17 +16,18 @@ export type WatchLine = { t: number; app?: string; windows?: AxWindow[]; error?:
export type Watch = (ids: string[], onLine: (l: WatchLine) => void) => { stop(): void }
/** the call apps that can be read, by the name meeting detection gives them (detect.ts), and the kind of window each
- * has. A Mac's ids are bundle ids; Linux's are program names or Flatpak app ids. */
+ * has. A Mac's ids are bundle ids; Linux's are program names or Flatpak app ids; Windows's are program file names,
+ * lowercased (detect.ts). Webex's Windows window isn't read yet: its lines stay Them there. */
const APPS: Record<string, { kind: CallKind; ids: string[] }> = {
- Zoom: { kind: 'zoom', ids: ['us.zoom.xos', 'zoom', 'us.zoom.Zoom'] },
- Teams: { kind: 'teams', ids: ['com.microsoft.teams2', 'com.microsoft.teams', 'teams-for-linux', 'com.github.IsmaelMartinez.teams_for_linux'] },
+ Zoom: { kind: 'zoom', ids: ['us.zoom.xos', 'zoom', 'us.zoom.Zoom', 'zoom.exe'] },
+ Teams: { kind: 'teams', ids: ['com.microsoft.teams2', 'com.microsoft.teams', 'teams-for-linux', 'com.github.IsmaelMartinez.teams_for_linux', 'ms-teams.exe', 'teams.exe'] },
Webex: { kind: 'webex', ids: ['Cisco-Systems.Spark', 'com.cisco.webexmeetingsapp'] },
- Chrome: { kind: 'meet', ids: ['com.google.Chrome', 'chrome', 'google-chrome'] },
- Arc: { kind: 'meet', ids: ['company.thebrowser.Browser'] },
- Brave: { kind: 'meet', ids: ['com.brave.Browser', 'brave'] },
- Edge: { kind: 'meet', ids: ['com.microsoft.edgemac', 'msedge', 'com.microsoft.Edge'] },
+ Chrome: { kind: 'meet', ids: ['com.google.Chrome', 'chrome', 'google-chrome', 'chrome.exe'] },
+ Arc: { kind: 'meet', ids: ['company.thebrowser.Browser', 'arc.exe'] },
+ Brave: { kind: 'meet', ids: ['com.brave.Browser', 'brave', 'brave.exe'] },
+ Edge: { kind: 'meet', ids: ['com.microsoft.edgemac', 'msedge', 'com.microsoft.Edge', 'msedge.exe'] },
Safari: { kind: 'meet', ids: ['com.apple.Safari'] },
- Firefox: { kind: 'meet', ids: ['org.mozilla.firefox', 'firefox', 'firefox-bin'] },
+ Firefox: { kind: 'meet', ids: ['org.mozilla.firefox', 'firefox', 'firefox-bin', 'firefox.exe'] },
}
/** The apps to read for a meeting: the one it was detected in; with none (started by hand) any of them, the frontmost with a call first */
export const watchIds = (app: string | null): string[] => (app ? APPS[app]?.ids ?? [] : Object.values(APPS).flatMap((a) => a.ids))
diff --git a/app/src/main/callNames/parse.ts b/app/src/main/callNames/parse.ts
index 4c1252fb..c79b2310 100644
--- a/app/src/main/callNames/parse.ts
+++ b/app/src/main/callNames/parse.ts
@@ -12,7 +12,8 @@ export type CallKind = 'zoom' | 'teams' | 'meet' | 'webex'
export type CallReading = { speaking: string[]; participants: string[]; me: string | null }
// A role has two names: macOS Accessibility says AXTabGroup, AXStaticText, AXRow, AXOutline; AT-SPI (Linux) says
-// page tab, label/static/text, table row/list item, tree table/table/list. The rules below know both.
+// page tab, label/static/text, table row/list item, tree table/table/list. The rules below know both. Windows's helper
+// gives UI Automation's control types the AT-SPI names (yogurt-system parse.rs uia_role), so it reads as Linux does.
const TAB_GROUP = new Set(['AXTabGroup', 'page tab'])
const STATIC_TEXT = new Set(['AXStaticText', 'static', 'label', 'text', 'paragraph', 'heading', 'caption'])
const ROW = new Set(['AXRow', 'table row', 'list item', 'row'])
@@ -107,8 +108,10 @@ function readZoom(windows: AxWindow[]): CallReading {
let me: string | null = null
for (const w of windows) {
walk(w.tree, (n, up) => {
- if (TAB_GROUP.has(n.r) && n.d) {
- const tile = zoomTile(n.d)
+ // the words are the description on a Mac and Linux, the name under UI Automation (Windows)
+ const tileWords = n.d ?? n.t
+ if (TAB_GROUP.has(n.r) && tileWords) {
+ const tile = zoomTile(tileWords)
if (tile) { participants.push(tile.name); if (tile.talking) speaking.push(tile.name) }
}
// the Linux Zoom Workplace tile is a push button named "video item <name> [Active Speaker]"
diff --git a/app/src/main/permissions.ts b/app/src/main/permissions.ts
index a4021c25..d36ff500 100644
--- a/app/src/main/permissions.ts
+++ b/app/src/main/permissions.ts
@@ -79,11 +79,11 @@ export type Permissions = ReturnType<typeof createPermissions>
* Windows and Linux have no prompts to ask with: the mic, call audio and notifications are simply on. Windows can still
* block desktop apps from the mic; the recorder finds that out when it starts (no-mic), and the mic reads as off until a
* recording hears it again. Its Settings page opens from the hint. Calendar doesn't exist there; Linux reads call names
- * through AT-SPI, which asks nothing, so Accessibility is granted there. On Windows it doesn't exist and stays unknown.
+ * through AT-SPI and Windows through UI Automation, neither of which asks, so Accessibility is granted on both.
*/
function offMac(platform: string, open: (url: string) => void, micBlocked?: () => boolean) {
const status = async (): Promise<PermissionStatus> =>
- ({ mic: platform === 'win32' && micBlocked?.() ? 'denied' : 'granted', systemAudio: 'granted', calendar: 'unknown', notifications: 'granted', accessibility: platform === 'linux' ? 'granted' : 'unknown' })
+ ({ mic: platform === 'win32' && micBlocked?.() ? 'denied' : 'granted', systemAudio: 'granted', calendar: 'unknown', notifications: 'granted', accessibility: 'granted' })
return {
status,
async request(kind: PermissionKind): Promise<Access> { return (await status())[kind] },
diff --git a/app/src/shared/platform.ts b/app/src/shared/platform.ts
index 09c2bf23..57bffffa 100644
--- a/app/src/shared/platform.ts
+++ b/app/src/shared/platform.ts
@@ -24,8 +24,8 @@ export type Capabilities = {
export function capabilities(platform: string): Capabilities {
const mac = platform === 'darwin'
- // Linux reads call names through AT-SPI (yogurt-system call-watch), the same WatchLine JSON as the Mac
- return { calendar: mac, callNames: mac || platform === 'linux', permissionPrompts: mac, mediaPause: mac }
+ // Linux reads call names through AT-SPI, Windows through UI Automation (yogurt-system call-watch), the same WatchLine JSON as the Mac
+ return { calendar: mac, callNames: mac || platform === 'linux' || platform === 'win32', permissionPrompts: mac, mediaPause: mac }
}
/** The computer Yogurt runs on. Only fake mode may pretend to be another one (YOGURT_FAKE_PLATFORM), so Mac tests can try the others' screens. */
diff --git a/app/test/callNames.test.ts b/app/test/callNames.test.ts
index 01418d4e..9d8add1a 100644
--- a/app/test/callNames.test.ts
+++ b/app/test/callNames.test.ts
@@ -72,10 +72,11 @@ const wait = () => new Promise((r) => setTimeout(r, 10))
describe('watchIds: only the call app the meeting is in', () => {
it('maps the detected app to its ids (bundle ids on a Mac, program names and Flatpak ids on Linux); no app known: every call app (the first with a call is read)', () => {
- expect(watchIds('Zoom')).toEqual(['us.zoom.xos', 'zoom', 'us.zoom.Zoom'])
- expect(watchIds('Teams')).toEqual(['com.microsoft.teams2', 'com.microsoft.teams', 'teams-for-linux', 'com.github.IsmaelMartinez.teams_for_linux'])
+ expect(watchIds('Zoom')).toEqual(['us.zoom.xos', 'zoom', 'us.zoom.Zoom', 'zoom.exe'])
+ expect(watchIds('Teams')).toEqual(['com.microsoft.teams2', 'com.microsoft.teams', 'teams-for-linux', 'com.github.IsmaelMartinez.teams_for_linux', 'ms-teams.exe', 'teams.exe'])
expect(watchIds('Webex')).toEqual(['Cisco-Systems.Spark', 'com.cisco.webexmeetingsapp'])
- expect(watchIds('Chrome')).toEqual(['com.google.Chrome', 'chrome', 'google-chrome'])
+ expect(watchIds('Chrome')).toEqual(['com.google.Chrome', 'chrome', 'google-chrome', 'chrome.exe'])
+ expect(watchIds('Edge')).toContain('msedge.exe')
expect(watchIds('Safari')).toEqual(['com.apple.Safari'])
expect(watchIds('FaceTime')).toEqual([])
expect(watchIds(null)).toContain('us.zoom.xos')
@@ -116,7 +117,7 @@ describe('hookCallNames', () => {
it('reads the meeting\'s app while it records, and a line of the other side gets the name talking then', () => {
const s = setup()
s.start()
- expect(s.watched).toEqual([['us.zoom.xos', 'zoom', 'us.zoom.Zoom']])
+ expect(s.watched).toEqual([['us.zoom.xos', 'zoom', 'us.zoom.Zoom', 'zoom.exe']])
// meeting time 0 was heard at 1_005_000 (the 100 ms of audio arrived 100 ms after it started)
s.audio(0, 1_005_100)
for (let t = 1_006_000; t < 1_014_000; t += 500) s.emit(zoomLine(t, ['Alex Morgan', 'Dana Smith', 'Ann Lee'], t < 1_010_000 ? 'Dana Smith' : 'Ann Lee'))
diff --git a/app/test/callParse.test.ts b/app/test/callParse.test.ts
index 65b36df3..20ab3836 100644
--- a/app/test/callParse.test.ts
+++ b/app/test/callParse.test.ts
@@ -61,6 +61,13 @@ describe('Zoom', () => {
expect(readCall('zoom', [win(tree)])).toEqual({ speaking: ['Ana Ruiz', 'Ann Lee'], participants: ['Ana Ruiz', 'Alex Morgan'], me: 'Alex Morgan' })
})
+ it('reads a tile whose words are its name (UI Automation on Windows has no separate description)', () => {
+ const tree = node('frame', { t: 'Zoom Meeting' },
+ node('page tab', { t: 'Ana Ruiz, Computer audio unmuted, Active speaker' }),
+ node('page tab', { t: 'Chat' }))
+ expect(readCall('zoom', [win(tree)])).toEqual({ speaking: ['Ana Ruiz'], participants: ['Ana Ruiz'], me: null })
+ })
+
it('reads the Linux Zoom Workplace tile: a push button named "video item <name>"', () => {
expect(zoomLinuxTile('video item Ana Ruiz Active Speaker')).toEqual({ name: 'Ana Ruiz', talking: true })
expect(zoomLinuxTile('video item Ana Ruiz')).toEqual({ name: 'Ana Ruiz', talking: false })
diff --git a/app/test/onboarding.test.ts b/app/test/onboarding.test.ts
index 09ecbc79..b931328c 100644
--- a/app/test/onboarding.test.ts
+++ b/app/test/onboarding.test.ts
@@ -99,14 +99,14 @@ describe('the launch screen', () => {
})
})
-describe('a computer without a calendar or names from calls (Windows)', () => {
+describe('a computer without a calendar (Windows)', () => {
const kinds = supportedKinds(capabilities('win32'))
- it('the first run never asks for them', () => {
- const plan = firstRunPlan({ ask: true, welcomed: false, introSeen: false, status: all('unknown'), kinds })
+ it('the first run never asks for it, nor for names from calls (UI Automation needs no permission, so it reads as on)', () => {
+ const plan = firstRunPlan({ ask: true, welcomed: false, introSeen: false, status: { ...all('unknown'), accessibility: 'granted' }, kinds })
expect(screensOf(plan.steps).map((s) => s.id)).toEqual(['record', 'notifications'])
})
- it('Finish setup leaves them out of the list and the progress', () => {
- const st: PermissionStatus = { ...all('granted'), accessibility: 'unknown', calendar: 'unknown' }
+ it('Finish setup leaves it out of the list and the progress', () => {
+ const st: PermissionStatus = { ...all('granted'), calendar: 'unknown' }
expect(missing(st, kinds)).toEqual([])
expect(nudge(st, [], kinds)).toEqual([])
expect(finishSetupPercent(st, kinds)).toBe(100)
diff --git a/app/test/permissions.test.ts b/app/test/permissions.test.ts
index 57cf143b..929f47f3 100644
--- a/app/test/permissions.test.ts
+++ b/app/test/permissions.test.ts
@@ -95,7 +95,7 @@ describe('permissions on Windows and Linux', () => {
systemAudio: 'granted',
calendar: 'unknown',
// Linux reads call names through AT-SPI, which has no permission prompt; Windows has no such permission
- accessibility: platform === 'linux' ? 'granted' : 'unknown',
+ accessibility: 'granted',
notifications: 'granted',
})
expect(await p.request('mic')).toBe('granted')
diff --git a/app/test/platform.test.ts b/app/test/platform.test.ts
index 744f7f1a..9c97de63 100644
--- a/app/test/platform.test.ts
+++ b/app/test/platform.test.ts
@@ -6,8 +6,8 @@ describe('what each computer can do', () => {
it('a Mac has every feature, exactly as before', () => {
expect(capabilities('darwin')).toEqual({ calendar: true, callNames: true, permissionPrompts: true, mediaPause: true })
})
- it('Windows has no calendar and no names from calls; Linux reads names through AT-SPI', () => {
- expect(capabilities('win32')).toEqual({ calendar: false, callNames: false, permissionPrompts: false, mediaPause: false })
+ it('Windows and Linux have no calendar; both read names from calls (UI Automation, AT-SPI)', () => {
+ expect(capabilities('win32')).toEqual({ calendar: false, callNames: true, permissionPrompts: false, mediaPause: false })
expect(capabilities('linux')).toEqual({ calendar: false, callNames: true, permissionPrompts: false, mediaPause: false })
})
it('only fake mode can pretend to be another computer, so the Mac CI can try the Windows and Linux screens', () => {
@@ -39,10 +39,10 @@ describe('permissions to ask for', () => {
it('a Mac asks for every one, in the same order', () => {
expect(supportedKinds(capabilities('darwin'))).toEqual(PERMISSION_KINDS)
})
- it('without a calendar or names from calls, those are never asked', () => {
- expect(supportedKinds(capabilities('win32'))).toEqual(['mic', 'systemAudio', 'notifications'])
+ it('without a calendar, it is never asked', () => {
+ expect(supportedKinds(capabilities('win32'))).toEqual(['mic', 'systemAudio', 'notifications', 'accessibility'])
})
- it('Linux keeps accessibility in the list (it has no prompt for it)', () => {
+ it('Windows and Linux keep accessibility in the list (they have no prompt for it)', () => {
expect(supportedKinds(capabilities('linux'))).toEqual(['mic', 'systemAudio', 'notifications', 'accessibility'])
})
})