mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-27 07:58:01 +01:00
* Meetings: one Calls sheet for what a call gets * Meetings offer: short answers, the title names the app * Calls: one name, Always record * Goldens: the Calls row; check the Calls sheet * Goldens: the Calls sheet * hex settings: name labs.dictate_while_annotating
93 lines
3 KiB
Rust
93 lines
3 KiB
Rust
//! Applications a dictation mode can activate for. Each OS lists them the
|
|
//! way its mode matcher identifies the focused application: macOS by the
|
|
//! bundle name Finder shows, Windows and Linux by the executable name.
|
|
|
|
use std::collections::HashSet;
|
|
use std::path::PathBuf;
|
|
use std::sync::OnceLock;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
#[path = "application_catalog/macos.rs"]
|
|
mod platform;
|
|
#[cfg(target_os = "windows")]
|
|
#[path = "application_catalog/windows.rs"]
|
|
mod platform;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
#[path = "application_catalog/linux.rs"]
|
|
mod platform;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct InstalledApplication {
|
|
pub name: String,
|
|
pub bundle_id: Option<String>,
|
|
pub path: PathBuf,
|
|
}
|
|
|
|
static APPLICATIONS: OnceLock<Vec<InstalledApplication>> = OnceLock::new();
|
|
|
|
pub fn discover() -> Vec<InstalledApplication> {
|
|
APPLICATIONS
|
|
.get_or_init(|| {
|
|
let mut applications = platform::applications();
|
|
normalize(&mut applications);
|
|
applications
|
|
})
|
|
.clone()
|
|
}
|
|
|
|
pub fn insert(applications: &mut Vec<InstalledApplication>, application: InstalledApplication) {
|
|
applications.push(application);
|
|
normalize(applications);
|
|
}
|
|
|
|
/// The application a user picked in the file dialog: a macOS `.app`
|
|
/// bundle, a Windows `.exe`, or a Linux `.desktop` entry or executable.
|
|
pub fn metadata(path: &std::path::Path) -> color_eyre::Result<InstalledApplication> {
|
|
platform::metadata(path)
|
|
}
|
|
|
|
/// The catalog name of the application whose desktop entry is `app_id`;
|
|
/// Wayland compositors report a window's app ID as its desktop file name.
|
|
#[cfg(target_os = "linux")]
|
|
pub fn desktop_application_name(app_id: &str) -> Option<String> {
|
|
platform::desktop_application_name(app_id)
|
|
}
|
|
|
|
/// The application whose bundle ID (macOS) or executable (Windows, Linux)
|
|
/// is `id`, as a call's provider names it.
|
|
pub fn find<'a>(
|
|
applications: &'a [InstalledApplication],
|
|
id: &str,
|
|
) -> Option<&'a InstalledApplication> {
|
|
applications
|
|
.iter()
|
|
.find(|a| a.bundle_id.as_deref() == Some(id))
|
|
.or_else(|| {
|
|
applications.iter().find(|a| {
|
|
let key = a.bundle_id.as_deref().unwrap_or(&a.name);
|
|
crate::microphone_activity::canonical_bundle_id_for(key, None) == Some(id)
|
|
})
|
|
})
|
|
}
|
|
|
|
/// One entry per application: macOS bundles by identifier (or path), and
|
|
/// executables by name, since Windows modes match the executable name.
|
|
fn normalize(applications: &mut Vec<InstalledApplication>) {
|
|
let mut identities = HashSet::new();
|
|
applications.retain(|application| {
|
|
identities.insert(application.bundle_id.clone().unwrap_or_else(|| {
|
|
if cfg!(target_os = "macos") {
|
|
application.path.to_string_lossy().into_owned()
|
|
} else {
|
|
application.name.to_lowercase()
|
|
}
|
|
}))
|
|
});
|
|
applications.sort_by(|left, right| {
|
|
left.name
|
|
.to_lowercase()
|
|
.cmp(&right.name.to_lowercase())
|
|
.then_with(|| left.path.cmp(&right.path))
|
|
});
|
|
}
|