entracte_lib/platform.rs
1//! Authoritative platform detection for the renderer.
2//!
3//! Frontend code used to lean on `navigator.userAgent`, which lies on
4//! Linux WebViews that masquerade as Mac/Safari for compatibility.
5//! Rust knows the host OS for certain via `std::env::consts::OS`, so
6//! this module exposes it as a Tauri command and the renderer caches
7//! the result through its `usePlatform()` hook.
8
9/// Return the host platform string as known to Rust:
10/// `"macos"`, `"linux"`, `"windows"`, etc. — the value of
11/// `std::env::consts::OS`. The renderer normalises this through
12/// `normalisePlatform` in `lib/platform.ts`.
13#[tauri::command]
14pub fn get_platform() -> &'static str {
15 std::env::consts::OS
16}
17
18#[cfg(test)]
19mod tests {
20 use super::*;
21
22 #[test]
23 fn get_platform_returns_a_known_value() {
24 let p = get_platform();
25 // The crate's CI matrix covers all three; reject anything we don't
26 // expect so a new target gets a deliberate decision rather than a
27 // surprise string slipping through to the renderer.
28 assert!(
29 matches!(p, "macos" | "linux" | "windows"),
30 "unexpected std::env::consts::OS = {p:?}",
31 );
32 }
33}