diff --git a/espanso/src/cli/launcher/mod.rs b/espanso/src/cli/launcher/mod.rs index c303327..f034604 100644 --- a/espanso/src/cli/launcher/mod.rs +++ b/espanso/src/cli/launcher/mod.rs @@ -31,7 +31,6 @@ pub fn new() -> CliModule { #[allow(clippy::needless_update)] CliModule { requires_paths: true, - requires_config: true, enable_logs: false, subcommand: "launcher".to_string(), entry: launcher_main, @@ -60,7 +59,7 @@ fn launcher_main(args: CliModuleArgs) -> i32 { let is_legacy_version_running_handler = Box::new(move || util::is_legacy_version_running(&runtime_dir_clone)); - let is_migrate_page_enabled = args.is_legacy_config; + let is_migrate_page_enabled = espanso_config::is_legacy_config(&paths.config); let paths_clone = paths.clone(); let backup_and_migrate_handler = Box::new(move || match util::migrate_configuration(&paths_clone) { diff --git a/espanso/src/main.rs b/espanso/src/main.rs index 88e0613..686ab09 100644 --- a/espanso/src/main.rs +++ b/espanso/src/main.rs @@ -132,14 +132,8 @@ fn main() { .takes_value(false) .help("Prompt for permissions if the operation requires elevated privileges."), ) - .subcommand( - SubCommand::with_name("register") - .about("Add 'espanso' command to PATH"), - ) - .subcommand( - SubCommand::with_name("unregister") - .about("Remove 'espanso' command from PATH"), - ) + .subcommand(SubCommand::with_name("register").about("Add 'espanso' command to PATH")) + .subcommand(SubCommand::with_name("unregister").about("Remove 'espanso' command from PATH")) .about("Add or remove the 'espanso' command from the PATH (macOS and Windows only)"), ) // .subcommand(SubCommand::with_name("cmd") @@ -326,10 +320,20 @@ fn main() { _ => LevelFilter::Debug, }; - let handler = CLI_HANDLERS + let mut handler = CLI_HANDLERS .iter() .find(|cli| matches.subcommand_matches(&cli.subcommand).is_some()); + // When started from the macOS App Bundle, override the default + // handler with "launcher", otherwise the GUI could not be started. + if let Some(context) = std::env::var_os("MAC_LAUNCH_CONTEXT") { + if context == "bundle" { + handler = CLI_HANDLERS + .iter() + .find(|cli| cli.subcommand == "launcher"); + } + } + if let Some(handler) = handler { let log_proxy = FileProxy::new(); if handler.enable_logs { diff --git a/espanso/src/res/macos/Info.plist b/espanso/src/res/macos/Info.plist index 8851e78..d55fe99 100644 --- a/espanso/src/res/macos/Info.plist +++ b/espanso/src/res/macos/Info.plist @@ -2,6 +2,11 @@ + LSEnvironment + + MAC_LAUNCH_CONTEXT + bundle + NSPrincipalClass NSApplication CFBundleInfoDictionaryVersion