feat(ui): implement Heartbeat on macOS

This commit is contained in:
Federico Terzi 2021-08-06 19:41:59 +02:00
parent f494d46fee
commit 02b486dc7a
4 changed files with 21 additions and 0 deletions

View File

@ -35,5 +35,6 @@
- (void) showNotification: (NSString *) message withDelay:(double) delay;
- (IBAction) statusIconClick: (id) sender;
- (IBAction) contextMenuClick: (id) sender;
- (void) heartbeatHandler: (NSTimer *)timer;
@end

View File

@ -33,6 +33,13 @@ void addSubMenu(NSMenu * parent, NSArray * items);
}
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
// Heartbeat timer setup
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(heartbeatHandler:)
userInfo:nil
repeats:YES];
}
- (void) setIcon: (int32_t)iconIndex {
@ -88,6 +95,14 @@ void addSubMenu(NSMenu * parent, NSArray * items);
[[NSUserNotificationCenter defaultUserNotificationCenter] performSelector:@selector(removeDeliveredNotification:) withObject:notification afterDelay:delay];
}
- (void) heartbeatHandler: (NSTimer *)timer {
UIEvent event = {};
event.event_type = UI_EVENT_TYPE_HEARTBEAT;
if (event_callback && rust_instance) {
event_callback(rust_instance, event);
}
}
@end
// Menu utility methods

View File

@ -32,6 +32,7 @@ const MAX_ICON_COUNT: usize = 3;
const UI_EVENT_TYPE_ICON_CLICK: i32 = 1;
const UI_EVENT_TYPE_CONTEXT_MENU_CLICK: i32 = 2;
const UI_EVENT_TYPE_HEARTBEAT: i32 = 3;
// Take a look at the native.h header file for an explanation of the fields
#[repr(C)]
@ -234,6 +235,9 @@ impl From<RawUIEvent> for Option<UIEvent> {
UI_EVENT_TYPE_CONTEXT_MENU_CLICK => {
return Some(UIEvent::ContextMenuClick(raw.context_menu_id));
}
UI_EVENT_TYPE_HEARTBEAT => {
return Some(UIEvent::Heartbeat);
}
_ => {}
}

View File

@ -28,6 +28,7 @@
#define UI_EVENT_TYPE_ICON_CLICK 1
#define UI_EVENT_TYPE_CONTEXT_MENU_CLICK 2
#define UI_EVENT_TYPE_HEARTBEAT 3
typedef struct {
int32_t show_icon;