platform: fix macOS data path + add get_os_info + frontend osInfo helper

CROSS-PLATFORM AUDIT:
- Linux x86_64 (Fedora 43, KDE Wayland): HIGH confidence (the dev target)
- Linux other distros / X11: MEDIUM (tested patterns, untested distros)
- Windows 10/11: LOW — theoretically supported via Tauri + CPAL + whisper.cpp
  + tauri-plugin-global-shortcut (the custom evdev hotkey is no-op on
  Windows); has had zero hands-on testing
- macOS Apple Silicon / Intel: LOW — same; macOS Info.plist needs
  NSMicrophoneUsageDescription for the bundled app, and the path bug
  fixed in this commit

REAL BUG FIXED — macOS app_data_dir was Unix-style:
crates/storage/src/file_storage.rs::app_data_dir() previously fell into
the "Unix" branch on macOS and wrote to ~/.kon/, which violates Apple
guidelines and confuses install/uninstall tooling. Now correctly:
- Windows: %LOCALAPPDATA%/kon (unchanged)
- macOS: ~/Library/Application Support/Kon/
- Linux: $XDG_DATA_HOME/kon or ~/.local/share/kon (XDG Base Directory),
         with legacy ~/.kon/ fallback so existing installs keep working
- Other Unix: ~/.kon/ (unchanged)

OS DETECTION LAYER:
- New get_os_info Tauri command in commands/diagnostics.rs returns:
  {os, arch, family, usesCmd, isWayland, customHotkeyBackend,
   primaryModifierLabel}
- New src/lib/utils/osInfo.js helper:
  - async loadOsInfo() warms a cache, called once at root layout mount
  - then isMac() / isWindows() / isLinux() / modKeyLabel() / isWayland()
    are synchronous
  - browser-preview fallback reads navigator.platform
- Lets components localise hotkey labels (Cmd vs Ctrl), file-picker
  copy ("Open Finder" vs "Open Explorer"), etc, without recomputing in
  every place.

cargo check -p kon-storage clean. Updated HANDOVER-2026-04-17.md with
a per-platform confidence table.
This commit is contained in:
2026-04-17 13:52:58 +01:00
parent 62ea58d95a
commit 4e6ca0ed96
6 changed files with 241 additions and 6 deletions

View File

@@ -344,6 +344,72 @@ fn read_tail(path: &PathBuf, n_bytes: u64) -> std::io::Result<String> {
Ok(String::from_utf8_lossy(&buf).to_string())
}
/// Cross-platform OS info exposed to the frontend so the UI can adapt:
/// hotkey labels (Cmd vs Ctrl), file-picker text, "open file location"
/// terminology, etc. Returned on demand via the `get_os_info` Tauri
/// command rather than recomputed in JS so we have a single source of
/// truth in the Rust layer.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OsInfo {
/// "windows" | "macos" | "linux" | "ios" | "android" | other
pub os: String,
/// "x86_64" | "aarch64" | other
pub arch: String,
/// Human-readable platform family for tooltips: "Windows", "macOS",
/// "Linux"
pub family: String,
/// True if the platform uses the Cmd modifier rather than Ctrl as
/// the primary accelerator (macOS).
pub uses_cmd: bool,
/// True if the user is currently in a Wayland session (Linux only).
/// Useful for status display; the actual workaround is automatic.
pub is_wayland: bool,
/// True if the custom evdev hotkey listener is the primary backend
/// (Linux only). Otherwise the Tauri global-shortcut plugin is used.
pub custom_hotkey_backend: bool,
/// Convenience: a localised label for the primary modifier
/// ("Cmd" on macOS, "Ctrl" elsewhere).
pub primary_modifier_label: String,
}
#[tauri::command]
pub fn get_os_info() -> OsInfo {
let os = std::env::consts::OS.to_string();
let arch = std::env::consts::ARCH.to_string();
let family = match os.as_str() {
"windows" => "Windows",
"macos" => "macOS",
"linux" => "Linux",
"ios" => "iOS",
"android" => "Android",
_ => "Unknown",
}
.to_string();
let uses_cmd = os == "macos";
let primary_modifier_label = if uses_cmd { "Cmd" } else { "Ctrl" }.to_string();
let is_wayland = if os == "linux" {
std::env::var("XDG_SESSION_TYPE")
.map(|v| v.eq_ignore_ascii_case("wayland"))
.unwrap_or(false)
} else {
false
};
let custom_hotkey_backend = os == "linux";
OsInfo {
os,
arch,
family,
uses_cmd,
is_wayland,
custom_hotkey_backend,
primary_modifier_label,
}
}
/// Write the report to a file and return the path. Lets the user save it
/// somewhere they can attach to an email.
#[tauri::command]

View File

@@ -252,6 +252,7 @@ pub fn run() {
commands::diagnostics::list_crash_files,
commands::diagnostics::generate_diagnostic_report,
commands::diagnostics::save_diagnostic_report,
commands::diagnostics::get_os_info,
commands::live::start_live_transcription_session,
commands::live::stop_live_transcription_session,
// Windows