Clean up tray icon on windows when exiting
This commit is contained in:
parent
8e6c536673
commit
7e71baed7e
|
@ -57,6 +57,7 @@ HWND nw = NULL;
|
|||
HWND hwnd_st_u = NULL;
|
||||
HBITMAP g_espanso_bmp = NULL;
|
||||
HICON g_espanso_ico = NULL;
|
||||
NOTIFYICONDATA nid = {};
|
||||
|
||||
// Callbacks
|
||||
|
||||
|
@ -376,7 +377,6 @@ int32_t initialize(void * self, wchar_t * ico_path, wchar_t * bmp_path) {
|
|||
SendMessage(nw, WM_SETICON, ICON_SMALL, (LPARAM)g_espanso_ico);
|
||||
|
||||
//Notification
|
||||
NOTIFYICONDATA nid = {};
|
||||
nid.cbSize = sizeof(nid);
|
||||
nid.hWnd = nw;
|
||||
nid.uID = 1;
|
||||
|
@ -558,6 +558,12 @@ int32_t show_context_menu(MenuItem * items, int32_t count) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
void cleanup_ui() {
|
||||
Shell_NotifyIcon(NIM_DELETE, &nid);
|
||||
}
|
||||
|
||||
// SYSTEM
|
||||
|
||||
int32_t start_daemon_process() {
|
||||
wchar_t cmd[MAX_PATH];
|
||||
swprintf(cmd, MAX_PATH, L"espanso.exe daemon");
|
||||
|
@ -586,6 +592,8 @@ int32_t start_daemon_process() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// CLIPBOARD
|
||||
|
||||
int32_t set_clipboard(wchar_t *text) {
|
||||
const size_t len = wcslen(text) + 1;
|
||||
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len * sizeof(wchar_t));
|
||||
|
|
|
@ -112,6 +112,11 @@ typedef void (*ContextMenuClickCallback)(void * self, int32_t id);
|
|||
extern ContextMenuClickCallback context_menu_click_callback;
|
||||
extern "C" void register_context_menu_click_callback(ContextMenuClickCallback callback);
|
||||
|
||||
/*
|
||||
* Hide the tray icon
|
||||
*/
|
||||
extern "C" void cleanup_ui();
|
||||
|
||||
// NOTIFICATION
|
||||
|
||||
/*
|
||||
|
|
|
@ -42,6 +42,7 @@ extern {
|
|||
pub fn show_context_menu(items: *const WindowsMenuItem, count: i32) -> i32;
|
||||
pub fn register_icon_click_callback(cb: extern fn(_self: *mut c_void));
|
||||
pub fn register_context_menu_click_callback(cb: extern fn(_self: *mut c_void, id: i32));
|
||||
pub fn cleanup_ui();
|
||||
|
||||
// CLIPBOARD
|
||||
pub fn get_clipboard(buffer: *mut u16, size: i32) -> i32;
|
||||
|
|
|
@ -195,6 +195,7 @@ impl <'a, S: KeyboardManager, C: ClipboardManager,
|
|||
},
|
||||
ActionType::Exit => {
|
||||
info!("Terminating espanso.");
|
||||
self.ui_manager.cleanup();
|
||||
exit(0);
|
||||
},
|
||||
_ => {}
|
||||
|
|
|
@ -37,6 +37,10 @@ impl super::UIManager for LinuxUIManager {
|
|||
fn show_menu(&self, _menu: Vec<MenuItem>) {
|
||||
// Not implemented on linux
|
||||
}
|
||||
|
||||
fn cleanup(&self) {
|
||||
// Nothing to do here
|
||||
}
|
||||
}
|
||||
|
||||
impl LinuxUIManager {
|
||||
|
|
|
@ -76,6 +76,10 @@ impl super::UIManager for MacUIManager {
|
|||
|
||||
unsafe { show_context_menu(raw_menu.as_ptr(), raw_menu.len() as i32); }
|
||||
}
|
||||
|
||||
fn cleanup(&self) {
|
||||
// Nothing to do here
|
||||
}
|
||||
}
|
||||
|
||||
impl MacUIManager {
|
||||
|
|
|
@ -29,6 +29,7 @@ mod macos;
|
|||
pub trait UIManager {
|
||||
fn notify(&self, message: &str);
|
||||
fn show_menu(&self, menu: Vec<MenuItem>);
|
||||
fn cleanup(&self);
|
||||
}
|
||||
|
||||
pub enum MenuItemType {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use crate::bridge::windows::{show_notification, close_notification, WindowsMenuItem, show_context_menu};
|
||||
use crate::bridge::windows::{show_notification, close_notification, WindowsMenuItem, show_context_menu, cleanup_ui};
|
||||
use widestring::U16CString;
|
||||
use std::{thread, time};
|
||||
use log::{debug};
|
||||
|
@ -90,6 +90,12 @@ impl super::UIManager for WindowsUIManager {
|
|||
|
||||
unsafe { show_context_menu(raw_menu.as_ptr(), raw_menu.len() as i32); }
|
||||
}
|
||||
|
||||
fn cleanup(&self) {
|
||||
unsafe {
|
||||
cleanup_ui();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WindowsUIManager {
|
||||
|
|
Loading…
Reference in New Issue
Block a user