diff --git a/espanso-ui/src/mac/mod.rs b/espanso-ui/src/mac/mod.rs index 042a855..3eaed31 100644 --- a/espanso-ui/src/mac/mod.rs +++ b/espanso-ui/src/mac/mod.rs @@ -55,6 +55,7 @@ extern "C" { pub fn ui_eventloop( event_callback: extern "C" fn(_self: *mut MacEventLoop, event: RawUIEvent), ) -> i32; + pub fn ui_exit(); pub fn ui_update_tray_icon(index: i32); pub fn ui_show_notification(message: *const c_char, delay: f64); pub fn ui_show_context_menu(payload: *const c_char); @@ -217,6 +218,10 @@ impl UIRemote for MacRemote { } } } + + fn exit(&self) { + unsafe { ui_exit() }; + } } #[allow(clippy::single_match)] // TODO: remove after another match is used diff --git a/espanso-ui/src/mac/native.h b/espanso-ui/src/mac/native.h index 5b3b455..da7c5fa 100644 --- a/espanso-ui/src/mac/native.h +++ b/espanso-ui/src/mac/native.h @@ -58,6 +58,9 @@ extern "C" void ui_initialize(void * self, UIOptions options); // Run the event loop. Blocking call. extern "C" int32_t ui_eventloop(EventCallback callback); +// Stops the application eventloop. +extern "C" void ui_exit(); + // Updates the tray icon to the given one. The method accepts an index that refers to // the icon within the UIOptions.icon_paths array. extern "C" void ui_update_tray_icon(int32_t index); diff --git a/espanso-ui/src/mac/native.mm b/espanso-ui/src/mac/native.mm index 31ea82d..5078126 100644 --- a/espanso-ui/src/mac/native.mm +++ b/espanso-ui/src/mac/native.mm @@ -45,6 +45,11 @@ int32_t ui_eventloop(EventCallback _callback) return 1; } +void ui_exit() { + [NSApp stop:nil]; + [NSApp abortModal]; +} + void ui_update_tray_icon(int32_t index) { dispatch_async(dispatch_get_main_queue(), ^(void) {