Simplify asset code a bit

This commit is contained in:
Jonathan Kelley committed 2024-01-04 18:01:13 -08:00
1 parent fef7b83b79
commit 7444796a85
8 files changed
+84 -96

No files matched your search

+19 -1
View File
@@ -1,6 +1,6 @@
use std::rc::Rc;
use crate::assets::*;
use crate::{assets::*, shortcut::IntoAccelerator, ShortcutHandle, ShortcutRegistryError};
use crate::{desktop_context::UserWindowEvent, window, DesktopContext, WryEventHandler};
use dioxus_core::ScopeState;
use tao::{event::Event, event_loop::EventLoopWindowTarget};
@@ -52,3 +52,21 @@ pub fn use_asset_handler<F: AssetFuture>(
}
})
}
/// Get a closure that executes any JavaScript in the WebView context.
pub fn use_global_shortcut(
cx: &ScopeState,
accelerator: impl IntoAccelerator,
handler: impl FnMut() + 'static,
) -> &Result<ShortcutHandle, ShortcutRegistryError> {
cx.use_hook(move || {
let desktop = window();
let id = desktop.create_shortcut(accelerator.accelerator(), handler);
Ok(ShortcutHandle {
desktop,
shortcut_id: id?,
})
})
}