change to hook api

This commit is contained in:
Evan Almloff committed 2023-01-12 18:48:23 -06:00
1 parent 2772b86629
commit cd17f515d4
5 files changed
+187 -26

No files matched your search

-18
View File
@@ -1,7 +1,5 @@
use std::path::PathBuf;
use wry::application::event::Event;
use wry::application::event_loop::EventLoopWindowTarget;
use wry::application::window::Icon;
use wry::{
application::window::{Window, WindowBuilder},
@@ -10,18 +8,14 @@ use wry::{
Result as WryResult,
};
use crate::desktop_context::UserWindowEvent;
// pub(crate) type DynEventHandlerFn = dyn Fn(&mut EventLoop<()>, &mut WebView);
/// The configuration for the desktop application.
pub struct Config {
pub(crate) window: WindowBuilder,
pub(crate) file_drop_handler: Option<DropHandler>,
pub(crate) event_handler: Option<EventHandler>,
pub(crate) protocols: Vec<WryProtocol>,
pub(crate) pre_rendered: Option<String>,
// pub(crate) event_handler: Option<Box<DynEventHandlerFn>>,
pub(crate) disable_context_menu: bool,
pub(crate) resource_dir: Option<PathBuf>,
pub(crate) custom_head: Option<String>,
@@ -30,7 +24,6 @@ pub struct Config {
}
type DropHandler = Box<dyn Fn(&Window, FileDropEvent) -> bool>;
type EventHandler = Box<dyn Fn(&Event<UserWindowEvent>, &EventLoopWindowTarget<UserWindowEvent>)>;
pub(crate) type WryProtocol = (
String,
@@ -48,7 +41,6 @@ impl Config {
window,
protocols: Vec::new(),
file_drop_handler: None,
event_handler: None,
pre_rendered: None,
disable_context_menu: !cfg!(debug_assertions),
resource_dir: None,
@@ -84,16 +76,6 @@ impl Config {
self
}
/// Set a custom wry event handler. This can be used to listen to window and webview events
/// This only has an effect on the main window
pub fn with_event_handler(
mut self,
handler: impl Fn(&Event<UserWindowEvent>, &EventLoopWindowTarget<UserWindowEvent>) + 'static,
) -> Self {
self.event_handler = Some(Box::new(handler));
self
}
/// Set a file drop handler
pub fn with_file_drop_handler(
mut self,