feat(core): improve icon dock handling on macOS

This commit is contained in:
Federico Terzi 2021-06-29 20:04:19 +02:00
parent ddf8a35aeb
commit 4ee1215fbc
4 changed files with 19 additions and 0 deletions

View File

@ -34,6 +34,7 @@ pub fn new() -> CliModule {
requires_paths: true, requires_paths: true,
enable_logs: false, enable_logs: false,
subcommand: "launcher".to_string(), subcommand: "launcher".to_string(),
show_in_dock: true,
entry: launcher_main, entry: launcher_main,
..Default::default() ..Default::default()
} }
@ -163,6 +164,12 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
// TODO: initialize config directory if not present // TODO: initialize config directory if not present
if should_launch_daemon { if should_launch_daemon {
// We hide the dock icon on macOS to avoid having it around when the daemon is running
#[cfg(target_os = "macos")]
{
espanso_mac_utils::convert_to_background_app();
}
daemon::launch_daemon(&paths_overrides).expect("failed to launch daemon"); daemon::launch_daemon(&paths_overrides).expect("failed to launch daemon");
} }

View File

@ -39,6 +39,7 @@ pub struct CliModule {
pub requires_paths: bool, pub requires_paths: bool,
pub requires_config: bool, pub requires_config: bool,
pub subcommand: String, pub subcommand: String,
pub show_in_dock: bool,
pub entry: fn(CliModuleArgs)->i32, pub entry: fn(CliModuleArgs)->i32,
} }
@ -51,6 +52,7 @@ impl Default for CliModule {
requires_paths: false, requires_paths: false,
requires_config: false, requires_config: false,
subcommand: "".to_string(), subcommand: "".to_string(),
show_in_dock: false,
entry: |_| {0}, entry: |_| {0},
} }
} }

View File

@ -377,6 +377,14 @@ fn main() {
log_panics::init(); log_panics::init();
} }
// If explicitly requested, we show the Dock icon on macOS
// We need to enable this selectively, otherwise we would end up with multiple
// dock icons due to the multi-process nature of espanso.
#[cfg(target_os = "macos")]
if handler.show_in_dock {
espanso_mac_utils::convert_to_foreground_app();
}
let mut cli_args: CliModuleArgs = CliModuleArgs::default(); let mut cli_args: CliModuleArgs = CliModuleArgs::default();
if handler.requires_paths || handler.requires_config { if handler.requires_paths || handler.requires_config {

View File

@ -37,5 +37,7 @@
<string>Copyright 2019-2021 Federico Terzi</string> <string>Copyright 2019-2021 Federico Terzi</string>
<key>LSRequiresCarbon</key> <key>LSRequiresCarbon</key>
<true/> <true/>
<key>LSUIElement</key>
<string>1</string>
</dict> </dict>
</plist> </plist>