Fix shortcut by wrapping callback

This commit is contained in:
Jonathan Kelley committed 2024-02-05 18:50:13 -08:00
1 parent f2ec5c5cb8
commit 2ade193a5b
2 files changed
+17 -6

No files matched your search

+5 -1
View File
@@ -9,6 +9,7 @@ use dioxus_core::{
use_hook,
};
use dioxus_hooks::use_callback;
use tao::{event::Event, event_loop::EventLoopWindowTarget};
use wry::RequestAsyncResponder;
@@ -56,8 +57,11 @@ pub fn use_global_shortcut(
accelerator: impl IntoAccelerator,
handler: impl FnMut() + 'static,
) -> Result<ShortcutHandle, ShortcutRegistryError> {
// wrap the user's handler in something that will carry the scope/runtime with it
let mut cb = use_callback(handler);
use_hook_with_cleanup(
move || window().create_shortcut(accelerator.accelerator(), handler),
move || window().create_shortcut(accelerator.accelerator(), move || cb.call()),
|handle| {
if let Ok(handle) = handle {
handle.remove();