Create use_muda_event_handler hook (#2367)
* create use_muda_event_handler hook * fix use_muda_event_handler re-export
This commit is contained in:
1 parent
790b984e61
commit
72ef58b95e
3 files changed
+34
-4
No files matched your search
@@ -18,7 +18,7 @@ pub fn use_window() -> DesktopContext {
|
||||
use_hook(consume_context::<DesktopContext>)
|
||||
}
|
||||
|
||||
/// Get a closure that executes any JavaScript in the WebView context.
|
||||
/// Register an event handler that runs when a wry event is processed.
|
||||
pub fn use_wry_event_handler(
|
||||
handler: impl FnMut(&Event<UserWindowEvent>, &EventLoopWindowTarget<UserWindowEvent>) + 'static,
|
||||
) -> WryEventHandler {
|
||||
@@ -28,6 +28,22 @@ pub fn use_wry_event_handler(
|
||||
)
|
||||
}
|
||||
|
||||
/// Register an event handler that runs when a muda event is processed.
|
||||
#[cfg_attr(
|
||||
docsrs,
|
||||
doc(cfg(any(target_os = "windows", target_os = "linux", target_os = "macos")))
|
||||
)]
|
||||
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
|
||||
pub fn use_muda_event_handler(
|
||||
mut handler: impl FnMut(&muda::MenuEvent) + 'static,
|
||||
) -> WryEventHandler {
|
||||
use_wry_event_handler(move |event, _| {
|
||||
if let Event::UserEvent(UserWindowEvent::MudaMenuEvent(event)) = event {
|
||||
handler(event);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Provide a callback to handle asset loading yourself.
|
||||
///
|
||||
/// The callback takes a path as requested by the web view, and it should return `Some(response)`
|
||||
|
||||
@@ -44,6 +44,6 @@ pub use assets::AssetRequest;
|
||||
pub use config::{Config, WindowCloseBehaviour};
|
||||
pub use desktop_context::{window, DesktopContext, DesktopService};
|
||||
pub use event_handlers::WryEventHandler;
|
||||
pub use hooks::{use_asset_handler, use_global_shortcut, use_window, use_wry_event_handler};
|
||||
pub use hooks::*;
|
||||
pub use shortcut::{ShortcutHandle, ShortcutRegistryError};
|
||||
pub use wry::RequestAsyncResponder;
|
||||
Reference in new issue
Block a user