Simplify asset code a bit
This commit is contained in:
8 files changed
+84
-96
No files matched your search
@@ -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?,
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user