feat(ui): implement exit method on macOS

This commit is contained in:
Federico Terzi 2021-05-18 21:50:14 +02:00
parent 4ab040da3c
commit 8c2e02030a
3 changed files with 13 additions and 0 deletions

View File

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

View File

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

View File

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