From e889e0a7896b54f610e0bda5425161e99dc446b7 Mon Sep 17 00:00:00 2001 From: "Fabien F." <8136686+lostmind84@users.noreply.github.com> Date: Fri, 2 Oct 2026 18:22:16 +0200 Subject: [PATCH] feat: the Manager starts and finds its folders on Linux - main: set WEBKIT_DISABLE_DMABUF_RENDERER=1 on Linux unless the user did. WebKitGTK's DMA-BUF renderer ended the process at startup with a Wayland "Protocol error" (seen with an NVIDIA card on Wayland). - data_dir: use $XDG_DATA_HOME (absolute only) or ~/.local/share on Linux instead of the temp folder. Windows keeps %LOCALAPPDATA%. - open_link: xdg-open on Linux, explorer.exe on Windows as before. - tailscale_exe: look in the usual Linux locations. Every Windows branch is the previous code unchanged. --- crates/coa-core/src/net.rs | 6 +++++ src-tauri/src/lib.rs | 48 ++++++++++++++++++++++++++++++++++++-- src-tauri/src/main.rs | 6 +++++ 3 files changed, 58 insertions(+), 2 deletions(-) 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 ba059f4..5be0904 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 @@ -1120,8 +1133,12 @@ fn open_link(url: String) -> std::result::Result<(), UiError> { if !(issue || catalog || ALLOWED.iter().any(|p| url.starts_with(p))) || !chars_ok || url.len() > 12_000 { return Err(Error::Invalid("That link is not allowed.".into()).into()); } - // explorer.exe opens the address in the default browser without going through a shell. - std::process::Command::new("explorer.exe").arg(&url).spawn().map_err(|e| Error::Invalid(e.to_string()))?; + // The system opener launches the default browser without going through a shell. + #[cfg(windows)] + let opener = "explorer.exe"; + #[cfg(not(windows))] + let opener = "xdg-open"; + std::process::Command::new(opener).arg(&url).spawn().map_err(|e| Error::Invalid(e.to_string()))?; Ok(()) } @@ -1442,3 +1459,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() }