Skip to main content

Module platform

Module platform 

Source
Expand description

Authoritative platform detection for the renderer.

Frontend code used to lean on navigator.userAgent, which lies on Linux WebViews that masquerade as Mac/Safari for compatibility. Rust knows the host OS for certain via std::env::consts::OS, so this module exposes it as a Tauri command and the renderer caches the result through its usePlatform() hook.

Structs§

PlatformCapabilities
Behavioural capability flags the renderer branches on, so each platform-gated feature is decided once here rather than re-derived from the raw platform string in every component.

Functions§

capabilities_for 🔒
Derive the capability flags for a given target-OS string and whether the session is Wayland. Kept pure and parameterised so every branch is unit-testable on a single host; the #[tauri::command] wrapper feeds it the real target and session type.
get_arch
Return the host CPU architecture as the value of std::env::consts::ARCH ("aarch64", "x86_64", …). Compiled into the binary, so it reflects the build target the user is running — exactly the build the Download button should offer them. The browser can’t see this reliably (WKWebView masks Apple Silicon as Intel), so the renderer asks Rust and normalises the answer through normaliseArch in lib/platform.ts.
get_locale
Return the OS’s preferred locale as a BCP-47 tag (e.g. "en-GB", "nb-NO"). The renderer formats the pause-picker date with Intl using this. The WebView’s own locale is unreliable — a non-localised app falls back to en-US even when the OS region differs — so it’s read natively.
get_platform
Return the host platform string as known to Rust: "macos", "linux", "windows", etc. — the value of std::env::consts::OS. The renderer normalises this through normalisePlatform in lib/platform.ts.
get_platform_capabilities
Return the host’s platform capability flags, derived from the compile-time target OS and the runtime session type. The renderer caches the result through its usePlatformCapabilities() hook.
is_wayland_session 🔒
Whether the current session is Wayland. Thin shim that reads the host OS and session env vars and defers to wayland_session_from_env.
locale_or_default 🔒
Normalise an optional OS locale into a BCP-47 tag the renderer can hand to Intl. Falls back to "en-US" when the OS reports nothing usable. Pure so the fallback is unit-testable without the platform locale source.
wayland_session_from_env 🔒
Whether the given OS + session env signals a Wayland session. Off Linux the Wayland env vars are irrelevant to video detection, so this is always false there. On Linux it mirrors the probe in video.rs / overlay.rs: XDG_SESSION_TYPE=wayland or a WAYLAND_DISPLAY set. Kept pure (OS + env passed in) so every branch — including the off-Linux short-circuit — is unit-testable on the single Linux coverage runner.