diff --git a/plugins/autostart/src/lib.rs b/plugins/autostart/src/lib.rs index 509e6b3f..91dcfa27 100644 --- a/plugins/autostart/src/lib.rs +++ b/plugins/autostart/src/lib.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT use auto_launch::{AutoLaunch, AutoLaunchBuilder}; +use log::info; use serde::{ser::Serializer, Serialize}; use tauri::{ command, @@ -98,7 +99,6 @@ pub fn init( .invoke_handler(tauri::generate_handler![enable, disable, is_enabled]) .setup(move |app| { let mut builder = AutoLaunchBuilder::new(); - builder.set_app_name(&app.package_info().name); if let Some(args) = args { builder.set_args(&args); @@ -110,7 +110,26 @@ pub fn init( #[cfg(windows)] builder.set_app_path(¤t_exe.display().to_string()); #[cfg(target_os = "macos")] - builder.set_app_path(¤t_exe.canonicalize()?.display().to_string()); + { + // on macOS, current_exe gives path to /Applications/Example.app/MacOS/Example + // but this results in seeing a Unix Executable in macOS login items + // It must be: /Applications/Example.app + // If it didn't find exactly a single occurance of .app, it will default to + // exe path to not break it. + let exe_path = current_exe.canonicalize()?.display().to_string(); + let parts: Vec<&str> = exe_path.split(".app/").collect(); + let app_path = if parts.len() == 2 { + format!( + "{}{}", + parts.get(0).unwrap().to_string(), + ".app" + ) + } else { + exe_path + }; + info!("auto_start path {}", &app_path); + builder.set_app_path(&app_path); + } #[cfg(target_os = "linux")] if let Some(appimage) = app .env()