Add argument to use_callback (#2774)

This commit is contained in:
Matt Hunzinger authored and GitHub committed 2024-08-02 16:15:59 -07:00
1 parent 14081e7e45
commit 205d8e9070
6 files changed
+34 -33

No files matched your search

+3 -3
View File
@@ -71,13 +71,13 @@ pub fn use_asset_handler(
/// Get a closure that executes any JavaScript in the WebView context.
pub fn use_global_shortcut(
accelerator: impl IntoAccelerator,
handler: impl FnMut() + 'static,
mut handler: impl FnMut() + 'static,
) -> Result<ShortcutHandle, ShortcutRegistryError> {
// wrap the user's handler in something that will carry the scope/runtime with it
let cb = use_callback(handler);
let cb = use_callback(move |_| handler());
use_hook_with_cleanup(
move || window().create_shortcut(accelerator.accelerator(), move || cb.call()),
move || window().create_shortcut(accelerator.accelerator(), move || cb.call(())),
|handle| {
if let Ok(handle) = handle {
handle.remove();