mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-30 17:48:50 +02:00
fix(autostart): fix auto start choosing wrong app path on macOS (#125)
* Update lib.rs * Update lib.rs * Update lib.rs --------- Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
|
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
|
||||||
|
use log::info;
|
||||||
use serde::{ser::Serializer, Serialize};
|
use serde::{ser::Serializer, Serialize};
|
||||||
use tauri::{
|
use tauri::{
|
||||||
command,
|
command,
|
||||||
@@ -98,7 +99,6 @@ pub fn init<R: Runtime>(
|
|||||||
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
|
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
|
||||||
.setup(move |app| {
|
.setup(move |app| {
|
||||||
let mut builder = AutoLaunchBuilder::new();
|
let mut builder = AutoLaunchBuilder::new();
|
||||||
|
|
||||||
builder.set_app_name(&app.package_info().name);
|
builder.set_app_name(&app.package_info().name);
|
||||||
if let Some(args) = args {
|
if let Some(args) = args {
|
||||||
builder.set_args(&args);
|
builder.set_args(&args);
|
||||||
@@ -110,7 +110,26 @@ pub fn init<R: Runtime>(
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
builder.set_app_path(¤t_exe.display().to_string());
|
builder.set_app_path(¤t_exe.display().to_string());
|
||||||
#[cfg(target_os = "macos")]
|
#[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")]
|
#[cfg(target_os = "linux")]
|
||||||
if let Some(appimage) = app
|
if let Some(appimage) = app
|
||||||
.env()
|
.env()
|
||||||
|
|||||||
Reference in New Issue
Block a user