feat(core): implement macOS bundle launching logic

This commit is contained in:
Federico Terzi 2021-06-26 22:31:20 +02:00
parent 9f905fbd36
commit a8522720a2
3 changed files with 19 additions and 11 deletions

View File

@ -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) {

View File

@ -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 {

View File

@ -2,6 +2,11 @@
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>LSEnvironment</key>
<dict>
<key>MAC_LAUNCH_CONTEXT</key>
<string>bundle</string>
</dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleInfoDictionaryVersion</key>