mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* read the browser's page for windows meeting detection Windows meeting detection read nothing from a browser holding the microphone, so a Meet or Teams page in Chrome was offered as a generic "Call in Google Chrome" and recorded under the browser's name. Every visible window of the browser's executable is now read through UI Automation (the Chromium utility process that holds the microphone has no window), on a helper thread with one read in flight and a 2 s deadline; titles are read inline, so a hung provider still answers with them. The address and title choice matches macOS: a page that names a call wins, and a call's tab title outranks another window's address. * make the windows meeting read cheap and clean its window titles Review of #2079: - FindAll walked a page's whole content for every probe. The walk now follows only the browser's own chrome and stops at Document elements, and one UI Automation instance (one COM initialization) serves a whole meeting read instead of one per window. - A Windows window title is a whole window's, not a tab's: zero-width characters, the browser's own name, Edge's profile name, and Edge's "and N more pages" are removed before detection reads it. - macOS shares the page-choice rule (`detection::call_page`) instead of keeping its own copy. * read the meeting page with one FindFirst per window Second review of #2079: - Dictation's foreground page read and its guard are back to origin/dev's own function bodies, byte for byte. - The meeting read asks each window's root for its first Document with FindFirst over the Document control type. UI Automation searches in pre-order and stops at the first match, so page content is never searched however many tabs or bookmarks a window shows; the walker and its element cap are gone. One automation instance still serves the whole read, with its 2 s deadline and one-in-flight guard. - Window title cleanup moves to meeting::window_title (detection.rs had reached its size limit). It keeps the notes on Edge's ambiguous profile segment and the English-only "and N more pages", and now also drops Chrome's trailing " - Google Chrome - <profile>".
71 lines
3 KiB
Rust
71 lines
3 KiB
Rust
//! The page a Windows browser window's title names, before meeting detection
|
|
//! reads it: a window title carries the browser's own name and Edge's profile
|
|
//! and other-tab count, while macOS and Linux report a tab's title.
|
|
|
|
use super::detection::{BROWSER_TITLE_SUFFIXES, clean_title};
|
|
|
|
/// Characters browsers put in their window titles that no one sees: Edge's
|
|
/// own name arrives as `Microsoft\u{200b} Edge`.
|
|
const ZERO_WIDTH: [char; 7] = [
|
|
'\u{200b}', '\u{200c}', '\u{200d}', '\u{200e}', '\u{200f}', '\u{2060}', '\u{feff}',
|
|
];
|
|
|
|
/// The page a browser window's title names. A Windows window title is not a
|
|
/// tab's: the browser appends its name (Edge after its profile name and a
|
|
/// zero-width space), and Edge counts the window's other tabs ("and 2 more
|
|
/// pages", English only). Both are removed here, before detection reads the
|
|
/// title; macOS and Linux titles are tab titles and need no cleaning.
|
|
///
|
|
/// Without a profile segment, an Edge title cannot be told apart from a page
|
|
/// title that contains " - ", so a profile is dropped only when a page title
|
|
/// is still left.
|
|
#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
|
|
pub(crate) fn normalize_window_title(title: &str) -> String {
|
|
let title: String = title
|
|
.chars()
|
|
.filter(|character| !ZERO_WIDTH.contains(character))
|
|
.collect();
|
|
let title = title.trim();
|
|
let title = if let Some(page) = title.strip_suffix(" - Microsoft Edge") {
|
|
strip_edge_profile(page)
|
|
} else if let Some(page) = strip_chrome_profile(title) {
|
|
page
|
|
} else {
|
|
clean_title(title, BROWSER_TITLE_SUFFIXES)
|
|
};
|
|
trim_more_pages(title).to_string()
|
|
}
|
|
|
|
/// Edge puts the profile's name between the page and the browser's own name,
|
|
/// and leaves it out for a single-profile window. It is dropped only when a
|
|
/// page title is still left, so `Meet - Design sync` keeps its name.
|
|
fn strip_edge_profile(title: &str) -> &str {
|
|
title
|
|
.rsplit_once(" - ")
|
|
.filter(|(page, _)| page.contains(" - "))
|
|
.map_or(title, |(page, _)| page)
|
|
}
|
|
|
|
/// Some Chrome windows put the profile's name after the browser's own
|
|
/// ("… - Google Chrome - Personal"). The browser's name marks the boundary,
|
|
/// so this needs no " - " guard like Edge's.
|
|
fn strip_chrome_profile(title: &str) -> Option<&str> {
|
|
let (page, profile) = title.rsplit_once(" - Google Chrome")?;
|
|
let profile = profile.strip_prefix(" - ")?;
|
|
(!profile.is_empty() && !profile.contains(" - ")).then_some(page)
|
|
}
|
|
|
|
/// Leaves out a browser window's count of its other tabs ("and 2 more
|
|
/// pages"), which Edge puts right after the page title.
|
|
fn trim_more_pages(title: &str) -> &str {
|
|
let Some((page, count)) = title.rsplit_once(" and ") else {
|
|
return title;
|
|
};
|
|
let count = count
|
|
.strip_suffix(" more pages")
|
|
.or_else(|| count.strip_suffix(" more page"));
|
|
match count {
|
|
Some(count) if !count.is_empty() && count.bytes().all(|byte| byte.is_ascii_digit()) => page,
|
|
_ => title,
|
|
}
|
|
}
|