feat(core): implement macOS bundle launching logic
This commit is contained in:
parent
9f905fbd36
commit
a8522720a2
|
@ -31,7 +31,6 @@ pub fn new() -> CliModule {
|
||||||
#[allow(clippy::needless_update)]
|
#[allow(clippy::needless_update)]
|
||||||
CliModule {
|
CliModule {
|
||||||
requires_paths: true,
|
requires_paths: true,
|
||||||
requires_config: true,
|
|
||||||
enable_logs: false,
|
enable_logs: false,
|
||||||
subcommand: "launcher".to_string(),
|
subcommand: "launcher".to_string(),
|
||||||
entry: launcher_main,
|
entry: launcher_main,
|
||||||
|
@ -60,7 +59,7 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
|
||||||
let is_legacy_version_running_handler =
|
let is_legacy_version_running_handler =
|
||||||
Box::new(move || util::is_legacy_version_running(&runtime_dir_clone));
|
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 paths_clone = paths.clone();
|
||||||
let backup_and_migrate_handler =
|
let backup_and_migrate_handler =
|
||||||
Box::new(move || match util::migrate_configuration(&paths_clone) {
|
Box::new(move || match util::migrate_configuration(&paths_clone) {
|
||||||
|
|
|
@ -132,14 +132,8 @@ fn main() {
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("Prompt for permissions if the operation requires elevated privileges."),
|
.help("Prompt for permissions if the operation requires elevated privileges."),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(SubCommand::with_name("register").about("Add 'espanso' command to PATH"))
|
||||||
SubCommand::with_name("register")
|
.subcommand(SubCommand::with_name("unregister").about("Remove 'espanso' command from PATH"))
|
||||||
.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)"),
|
.about("Add or remove the 'espanso' command from the PATH (macOS and Windows only)"),
|
||||||
)
|
)
|
||||||
// .subcommand(SubCommand::with_name("cmd")
|
// .subcommand(SubCommand::with_name("cmd")
|
||||||
|
@ -326,10 +320,20 @@ fn main() {
|
||||||
_ => LevelFilter::Debug,
|
_ => LevelFilter::Debug,
|
||||||
};
|
};
|
||||||
|
|
||||||
let handler = CLI_HANDLERS
|
let mut handler = CLI_HANDLERS
|
||||||
.iter()
|
.iter()
|
||||||
.find(|cli| matches.subcommand_matches(&cli.subcommand).is_some());
|
.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 {
|
if let Some(handler) = handler {
|
||||||
let log_proxy = FileProxy::new();
|
let log_proxy = FileProxy::new();
|
||||||
if handler.enable_logs {
|
if handler.enable_logs {
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
||||||
<plist version="0.9">
|
<plist version="0.9">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>LSEnvironment</key>
|
||||||
|
<dict>
|
||||||
|
<key>MAC_LAUNCH_CONTEXT</key>
|
||||||
|
<string>bundle</string>
|
||||||
|
</dict>
|
||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user