diff --git a/crates/coa-core/src/net.rs b/crates/coa-core/src/net.rs index 6b7bf0b..b1fb7c5 100644 --- a/crates/coa-core/src/net.rs +++ b/crates/coa-core/src/net.rs @@ -88,10 +88,16 @@ pub struct Tailscale { pub connected: bool, } +#[cfg(windows)] fn tailscale_exe() -> Option { ["C:/Program Files/Tailscale/tailscale.exe", "C:/Program Files (x86)/Tailscale/tailscale.exe"].iter().map(PathBuf::from).find(|p| p.is_file()) } +#[cfg(not(windows))] +fn tailscale_exe() -> Option { + ["/usr/bin/tailscale", "/usr/local/bin/tailscale", "/usr/sbin/tailscale"].iter().map(PathBuf::from).find(|p| p.is_file()) +} + pub fn parse_tailscale_ip(out: &str) -> Option { out.lines().map(str::trim).find(|l| l.parse::().map(is_cgnat_range).unwrap_or(false)).map(str::to_string) } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 03ad116..d35cf7a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -70,11 +70,24 @@ struct StatusView { path_exists: bool, } +/// Where the Manager keeps its own state (server list, logs). `%LOCALAPPDATA%` on Windows, the XDG data folder elsewhere. fn data_dir() -> PathBuf { + #[cfg(windows)] let base = std::env::var_os("LOCALAPPDATA").map(PathBuf::from).unwrap_or_else(std::env::temp_dir); + #[cfg(not(windows))] + let base = unix_data_home(std::env::var_os("XDG_DATA_HOME"), std::env::var_os("HOME")); base.join("CoAServerManager") } +/// `$XDG_DATA_HOME` when it is an absolute path (the spec says to ignore relative ones), else `~/.local/share`. +#[cfg(not(windows))] +fn unix_data_home(xdg: Option, home: Option) -> PathBuf { + xdg.map(PathBuf::from) + .filter(|p| p.is_absolute()) + .or_else(|| home.map(|h| PathBuf::from(h).join(".local/share"))) + .unwrap_or_else(std::env::temp_dir) +} + fn path_of(state: &AppState, id: &str) -> Result { state .registry @@ -1478,3 +1491,30 @@ pub fn run() { .run(tauri::generate_context!()) .expect("error while running CoA Server Manager"); } + +#[cfg(all(test, not(windows)))] +mod tests { + use super::unix_data_home; + use std::ffi::OsString; + use std::path::PathBuf; + + fn os(s: &str) -> Option { + Some(s.into()) + } + + #[test] + fn data_home_prefers_an_absolute_xdg_folder() { + assert_eq!(unix_data_home(os("/data/xdg"), os("/home/u")), PathBuf::from("/data/xdg")); + } + + #[test] + fn data_home_ignores_a_relative_xdg_folder_and_falls_back_to_home() { + assert_eq!(unix_data_home(os("relative/dir"), os("/home/u")), PathBuf::from("/home/u/.local/share")); + assert_eq!(unix_data_home(None, os("/home/u")), PathBuf::from("/home/u/.local/share")); + } + + #[test] + fn data_home_without_any_variable_uses_the_temp_folder() { + assert_eq!(unix_data_home(None, None), std::env::temp_dir()); + } +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index abbcfa2..67c2cdb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,5 +1,11 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { + // WebKitGTK's DMA-BUF renderer ends the process with a Wayland "Protocol error" on some graphics stacks (seen with + // an NVIDIA card on Wayland). The path without it works everywhere; a value set by the user is left alone. + #[cfg(target_os = "linux")] + if std::env::var_os("WEBKIT_DISABLE_DMABUF_RENDERER").is_none() { + std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1"); + } coa_server_manager_lib::run() }