feat(ui): implement heartbeat on Windows
This commit is contained in:
parent
36400afab4
commit
f494d46fee
|
@ -21,4 +21,5 @@
|
|||
pub enum UIEvent {
|
||||
TrayIconClick,
|
||||
ContextMenuClick(u32),
|
||||
Heartbeat,
|
||||
}
|
||||
|
|
|
@ -46,6 +46,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)]
|
||||
|
@ -342,6 +343,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);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@ using json = nlohmann::json;
|
|||
#define APPWM_SHOW_CONTEXT_MENU (WM_APP + 2)
|
||||
#define APPWM_UPDATE_TRAY_ICON (WM_APP + 3)
|
||||
|
||||
#define HEARTBEAT_TIMER_ID 10001
|
||||
|
||||
const wchar_t *const ui_winclass = L"EspansoUI";
|
||||
|
||||
typedef struct
|
||||
|
@ -153,6 +155,18 @@ LRESULT CALLBACK ui_window_procedure(HWND window, unsigned int msg, WPARAM wp, L
|
|||
break;
|
||||
}
|
||||
}
|
||||
case WM_TIMER: // Regular timer check event
|
||||
{
|
||||
if (wp == HEARTBEAT_TIMER_ID)
|
||||
{
|
||||
event.event_type = UI_EVENT_TYPE_HEARTBEAT;
|
||||
if (variables->event_callback && variables->rust_instance)
|
||||
{
|
||||
variables->event_callback(variables->rust_instance, event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
if (msg == WM_TASKBARCREATED)
|
||||
{ // Explorer crashed, recreate the icon
|
||||
|
@ -241,6 +255,9 @@ void *ui_initialize(void *_self, UIOptions _options, int32_t *error_code)
|
|||
{
|
||||
Shell_NotifyIcon(NIM_ADD, &variables->nid);
|
||||
}
|
||||
|
||||
// Setup heartbeat timer
|
||||
SetTimer(window, HEARTBEAT_TIMER_ID, 1000, (TIMERPROC)NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -29,6 +29,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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user