diff --git a/.changes/autostart-freebsd.md b/.changes/autostart-freebsd.md new file mode 100644 index 0000000000..c29209ea1f --- /dev/null +++ b/.changes/autostart-freebsd.md @@ -0,0 +1,6 @@ +--- +"autostart": patch +"autostart-js": patch +--- + +Use the executable path for FreeBSD autostart while preserving existing platform dependency versions. diff --git a/Cargo.lock b/Cargo.lock index 22fbc476fb..ff78addf2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,7 +297,7 @@ dependencies = [ "objc2-app-kit", "objc2-core-foundation", "objc2-core-graphics", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "parking_lot", "percent-encoding", "windows-sys 0.59.0", @@ -551,6 +551,20 @@ dependencies = [ "winreg 0.10.1", ] +[[package]] +name = "auto-launch" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17918dba7ecf78b9a14507ec9f984e7977d13fad87dc86d61038980a45d128cf" +dependencies = [ + "dirs 6.0.0", + "os_info", + "smappservice-rs", + "thiserror 2.0.12", + "windows-registry 0.6.1", + "windows-result 0.4.1", +] + [[package]] name = "autocfg" version = "1.4.0" @@ -972,7 +986,7 @@ dependencies = [ "iana-time-zone", "num-traits", "serde", - "windows-link", + "windows-link 0.1.1", ] [[package]] @@ -2801,7 +2815,7 @@ dependencies = [ "tokio", "tower-service", "tracing", - "windows-registry", + "windows-registry 0.5.1", ] [[package]] @@ -3478,7 +3492,7 @@ checksum = "0b95dfb34071d1592b45622bf93e315e3a72d414b6782aca9a015c12bec367ef" dependencies = [ "cc", "objc2 0.6.4", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "time", ] @@ -3614,7 +3628,7 @@ dependencies = [ "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "once_cell", "png 0.18.1", "serde", @@ -3826,7 +3840,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate 3.3.0", "proc-macro2", "quote", "syn 2.0.100", @@ -3878,7 +3892,7 @@ dependencies = [ "objc2 0.6.4", "objc2-core-foundation", "objc2-core-graphics", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -3889,7 +3903,7 @@ checksum = "6c1948a9be5f469deadbd6bcb86ad7ff9e47b4f632380139722f7d9840c0d42c" dependencies = [ "bitflags 2.9.0", "objc2 0.6.4", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -3899,16 +3913,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f860f8e841f6d32f754836f51e6bc7777cd7e7053cf18528233f6811d3eceb4" dependencies = [ "objc2 0.6.4", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] name = "objc2-core-foundation" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daeaf60f25471d26948a1c2f840e3f7d86f4109e3af4e8e4b5cd70c39690d925" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" dependencies = [ "bitflags 2.9.0", + "dispatch2", "objc2 0.6.4", ] @@ -3931,7 +3946,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ffa6bea72bf42c78b0b34e89c0bafac877d5f80bf91e159a5d96ea7f693ca56" dependencies = [ "objc2 0.6.4", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -3941,7 +3956,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d31f4c5b5192304996badc466aeadffe1411d73a9bbd3b18b6b2ee9d048b07bd" dependencies = [ "objc2 0.6.4", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -3973,9 +3988,9 @@ dependencies = [ [[package]] name = "objc2-foundation" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a21c6c9014b82c39515db5b396f91645182611c97d24637cf56ac01e5f8d998" +checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" dependencies = [ "bitflags 2.9.0", "block2 0.6.2", @@ -4016,7 +4031,7 @@ dependencies = [ "bitflags 2.9.0", "objc2 0.6.4", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -4041,7 +4056,31 @@ dependencies = [ "bitflags 2.9.0", "objc2 0.6.4", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-security" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe137109bd1e8b5a99390f77a7d8b2961dafc1a1c5db8f2e60329ad6d895a" +dependencies = [ + "bitflags 2.9.0", + "objc2 0.6.4", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-service-management" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b213642d6959cc6023ceb1217aa595eaaf09b8094ce95127c103cab611fe65e8" +dependencies = [ + "block2 0.6.2", + "objc2 0.6.4", + "objc2-core-foundation", + "objc2-foundation 0.3.2", + "objc2-security", ] [[package]] @@ -4059,7 +4098,7 @@ dependencies = [ "objc2-core-graphics", "objc2-core-image", "objc2-core-location", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "objc2-quartz-core 0.3.0", "objc2-user-notifications", ] @@ -4071,7 +4110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "670fe793adbf3b5e93686d48a05a7ed7ee53dfa65d106ced4805fae8969059b2" dependencies = [ "objc2 0.6.4", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -4085,7 +4124,7 @@ dependencies = [ "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", ] [[package]] @@ -4229,7 +4268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "732c71caeaa72c065bb69d7ea08717bd3f4863a4f451402fc9513e29dbd5261b" dependencies = [ "objc2 0.6.4", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "objc2-osa-kit", "serde", "serde_json", @@ -5007,7 +5046,7 @@ dependencies = [ "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "pollster", "raw-window-handle", "urlencoding", @@ -5720,6 +5759,18 @@ dependencies = [ "serde", ] +[[package]] +name = "smappservice-rs" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52703b97a53101cf5d4580e0737aaa634ce1fdcfc123c16b2a9658e358013488" +dependencies = [ + "objc2 0.6.4", + "objc2-foundation 0.3.2", + "objc2-service-management", + "thiserror 2.0.12", +] + [[package]] name = "socket2" version = "0.5.9" @@ -6259,7 +6310,7 @@ dependencies = [ "ndk-sys", "objc2 0.6.4", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "objc2-ui-kit", "once_cell", "parking_lot", @@ -6334,7 +6385,7 @@ dependencies = [ "muda", "objc2 0.6.4", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "objc2-ui-kit", "objc2-web-kit", "percent-encoding", @@ -6446,11 +6497,13 @@ dependencies = [ name = "tauri-plugin-autostart" version = "2.5.1" dependencies = [ - "auto-launch", + "auto-launch 0.5.0", + "auto-launch 0.6.0", "serde", "serde_json", "tauri", "tauri-plugin", + "tempfile", "thiserror 2.0.12", ] @@ -6520,8 +6573,8 @@ dependencies = [ "thiserror 2.0.12", "tracing", "url", - "windows-registry", - "windows-result", + "windows-registry 0.5.1", + "windows-result 0.3.2", ] [[package]] @@ -6550,7 +6603,7 @@ dependencies = [ "log", "notify", "notify-debouncer-full", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "percent-encoding", "schemars", "serde", @@ -6647,7 +6700,7 @@ dependencies = [ "fern", "log", "objc2 0.6.4", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "serde", "serde_json", "serde_repr", @@ -6698,7 +6751,7 @@ dependencies = [ "dunce", "glob", "objc2-app-kit", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "open", "schemars", "serde", @@ -7480,7 +7533,7 @@ dependencies = [ "objc2-app-kit", "objc2-core-foundation", "objc2-core-graphics", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "once_cell", "png 0.18.1", "serde", @@ -8206,7 +8259,7 @@ dependencies = [ "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "raw-window-handle", "windows-sys 0.59.0", "windows-version", @@ -8234,7 +8287,7 @@ dependencies = [ "windows-collections", "windows-core", "windows-future", - "windows-link", + "windows-link 0.1.1", "windows-numerics", ] @@ -8255,9 +8308,9 @@ checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" dependencies = [ "windows-implement", "windows-interface", - "windows-link", - "windows-result", - "windows-strings", + "windows-link 0.1.1", + "windows-result 0.3.2", + "windows-strings 0.4.0", ] [[package]] @@ -8267,7 +8320,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a1d6bbefcb7b60acd19828e1bc965da6fcf18a7e39490c5f8be71e54a19ba32" dependencies = [ "windows-core", - "windows-link", + "windows-link 0.1.1", ] [[package]] @@ -8298,6 +8351,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + [[package]] name = "windows-numerics" version = "0.2.0" @@ -8305,7 +8364,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" dependencies = [ "windows-core", - "windows-link", + "windows-link 0.1.1", ] [[package]] @@ -8314,9 +8373,20 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1da3e436dc7653dfdf3da67332e22bff09bb0e28b0239e1624499c7830842e" dependencies = [ - "windows-link", - "windows-result", - "windows-strings", + "windows-link 0.1.1", + "windows-result 0.3.2", + "windows-strings 0.4.0", +] + +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link 0.2.1", + "windows-result 0.4.1", + "windows-strings 0.5.1", ] [[package]] @@ -8325,7 +8395,16 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" dependencies = [ - "windows-link", + "windows-link 0.1.1", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link 0.2.1", ] [[package]] @@ -8334,7 +8413,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" dependencies = [ - "windows-link", + "windows-link 0.1.1", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link 0.2.1", ] [[package]] @@ -8450,7 +8538,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e04a5c6627e310a23ad2358483286c7df260c964eb2d003d8efd6d0f4e79265c" dependencies = [ - "windows-link", + "windows-link 0.1.1", ] [[package]] @@ -8770,7 +8858,7 @@ dependencies = [ "objc2 0.6.4", "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.0", + "objc2-foundation 0.3.2", "objc2-ui-kit", "objc2-web-kit", "once_cell", diff --git a/plugins/autostart/Cargo.toml b/plugins/autostart/Cargo.toml index 596566843d..8efe8c9e9a 100644 --- a/plugins/autostart/Cargo.toml +++ b/plugins/autostart/Cargo.toml @@ -31,4 +31,13 @@ serde = { workspace = true } serde_json = { workspace = true } tauri = { workspace = true } thiserror = { workspace = true } + +[target.'cfg(not(target_os = "freebsd"))'.dependencies] auto-launch = "0.5" + +[target.'cfg(target_os = "freebsd")'.dependencies] +auto-launch = "0.6" + +[dev-dependencies] +tauri = { workspace = true, features = ["test"] } +tempfile = "3.20" diff --git a/plugins/autostart/src/lib.rs b/plugins/autostart/src/lib.rs index 82fc56fc95..cc85424dda 100644 --- a/plugins/autostart/src/lib.rs +++ b/plugins/autostart/src/lib.rs @@ -222,6 +222,10 @@ impl Builder { builder.set_app_path(¤t_exe.display().to_string()); } + // FreeBSD has no AppImage environment; autostart uses the executable. + #[cfg(target_os = "freebsd")] + builder.set_app_path(¤t_exe.display().to_string()); + app.manage(AutoLaunchManager( builder.build().map_err(|e| e.to_string())?, )); diff --git a/plugins/autostart/tests/xdg.rs b/plugins/autostart/tests/xdg.rs new file mode 100644 index 0000000000..ecb74c2602 --- /dev/null +++ b/plugins/autostart/tests/xdg.rs @@ -0,0 +1,81 @@ +// Copyright 2019-2023 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +#![cfg(any(target_os = "linux", target_os = "freebsd"))] + +use std::{ + env, fs, + process::Command, + thread, + time::{Duration, Instant}, +}; +use tauri::test::{mock_builder, mock_context, noop_assets}; +use tauri_plugin_autostart::ManagerExt; + +const TEST_NAME: &str = "xdg_autostart_uses_executable_and_preserves_arguments"; +const CHILD_ENV: &str = "TAURI_AUTOSTART_TEST_HOME"; + +#[test] +fn xdg_autostart_uses_executable_and_preserves_arguments() { + if let Some(home) = env::var_os(CHILD_ENV) { + // The parent gives only this child a disposable home. Never mutate the + // developer's autostart entries or process-wide environment in a test. + assert_eq!(env::var_os("HOME"), Some(home.clone())); + let home = std::path::PathBuf::from(home); + let app = mock_builder() + .plugin( + tauri_plugin_autostart::Builder::new() + .app_name("Tauri Autostart Test") + .args(["--from-autostart", "--profile=test"]) + .build(), + ) + .build(mock_context(noop_assets())) + .unwrap(); + let autostart = app.autolaunch(); + let entry = home.join(".config/autostart/Tauri Autostart Test.desktop"); + assert!(!autostart.is_enabled().unwrap()); + autostart.enable().unwrap(); + assert!(autostart.is_enabled().unwrap()); + let desktop = fs::read_to_string(&entry).unwrap(); + let expected = format!( + "Exec={} --from-autostart --profile=test", + env::current_exe().unwrap().display() + ); + assert!(desktop.lines().any(|line| line == expected)); + assert!(desktop.lines().any(|line| line == "Type=Application")); + assert!(!home.join(".config/systemd").exists()); + autostart.enable().unwrap(); + assert_eq!(fs::read_to_string(&entry).unwrap(), desktop); + autostart.disable().unwrap(); + assert!(!autostart.is_enabled().unwrap()); + assert!(!entry.exists()); + autostart.disable().unwrap(); + return; + } + + let home = tempfile::tempdir().unwrap(); + fs::create_dir(home.path().join(".config")).unwrap(); + let mut child = Command::new(env::current_exe().unwrap()) + .args(["--exact", TEST_NAME, "--nocapture", "--test-threads=1"]) + .env(CHILD_ENV, home.path()) + .env("HOME", home.path()) + .env("XDG_CONFIG_HOME", home.path().join(".config")) + .env_remove("APPIMAGE") + .env_remove("APPDIR") + .spawn() + .unwrap(); + let deadline = Instant::now() + Duration::from_secs(30); + loop { + if let Some(status) = child.try_wait().unwrap() { + assert!(status.success(), "autostart test child failed"); + break; + } + if Instant::now() >= deadline { + let _ = child.kill(); + let _ = child.wait(); + panic!("autostart test child timed out"); + } + thread::sleep(Duration::from_millis(10)); + } +}