mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 17:18:32 +02:00
Unlisten to window event and fix hotkeys
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use hex_color::HexColor;
|
use hex_color::HexColor;
|
||||||
use objc::{msg_send, sel, sel_impl};
|
use objc::{msg_send, sel, sel_impl};
|
||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use tauri::{Manager, plugin::{Builder, TauriPlugin}, Runtime, Window};
|
use tauri::{Manager, plugin::{Builder, TauriPlugin}, Runtime, Window, WindowEvent};
|
||||||
|
|
||||||
const WINDOW_CONTROL_PAD_X: f64 = 13.0;
|
const WINDOW_CONTROL_PAD_X: f64 = 13.0;
|
||||||
const WINDOW_CONTROL_PAD_Y: f64 = 18.0;
|
const WINDOW_CONTROL_PAD_Y: f64 = 18.0;
|
||||||
@@ -20,7 +20,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|||||||
let h = window.app_handle();
|
let h = window.app_handle();
|
||||||
|
|
||||||
let window_for_theme = window.clone();
|
let window_for_theme = window.clone();
|
||||||
h.listen("yaak_bg_changed", move |ev| {
|
let id1 = h.listen("yaak_bg_changed", move |ev| {
|
||||||
let payload = serde_json::from_str::<&str>(ev.payload())
|
let payload = serde_json::from_str::<&str>(ev.payload())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.trim();
|
.trim();
|
||||||
@@ -29,12 +29,23 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let window_for_title = window.clone();
|
let window_for_title = window.clone();
|
||||||
h.listen("yaak_title_changed", move |ev| {
|
let id2 = h.listen("yaak_title_changed", move |ev| {
|
||||||
let payload = serde_json::from_str::<&str>(ev.payload())
|
let payload = serde_json::from_str::<&str>(ev.payload())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.trim();
|
.trim();
|
||||||
update_window_title(window_for_title.clone(), payload.to_string());
|
update_window_title(window_for_title.clone(), payload.to_string());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let h = h.clone();
|
||||||
|
window.on_window_event(move |e| {
|
||||||
|
match e {
|
||||||
|
WindowEvent::Destroyed => {
|
||||||
|
h.unlisten(id1);
|
||||||
|
h.unlisten(id2);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
})
|
})
|
||||||
@@ -78,7 +89,6 @@ fn update_window_theme<R: Runtime>(window: Window<R>, color: HexColor) {
|
|||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let window_handle = UnsafeWindowHandle(window.ns_window().unwrap());
|
let window_handle = UnsafeWindowHandle(window.ns_window().unwrap());
|
||||||
|
|
||||||
let window2 = window.clone();
|
let window2 = window.clone();
|
||||||
let _ = window.run_on_main_thread(move || {
|
let _ = window.run_on_main_thread(move || {
|
||||||
let handle = window_handle;
|
let handle = window_handle;
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ export function useHotKey(
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
callbackRef.current(e);
|
callbackRef.current(e);
|
||||||
|
currentKeys.current.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user