expose desktopconfig in public interface (#529)
This commit is contained in:
1 parent
baf1807338
commit
a9e71cb001
2 files changed
+22
-19
No files matched your search
+20
-18
@@ -2,23 +2,21 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use wry::application::window::Icon;
|
use wry::application::window::Icon;
|
||||||
use wry::{
|
use wry::{
|
||||||
application::{
|
application::window::{Window, WindowBuilder},
|
||||||
event_loop::EventLoop,
|
|
||||||
window::{Window, WindowBuilder},
|
|
||||||
},
|
|
||||||
http::{Request as HttpRequest, Response as HttpResponse},
|
http::{Request as HttpRequest, Response as HttpResponse},
|
||||||
webview::{FileDropEvent, WebView},
|
webview::FileDropEvent,
|
||||||
Result as WryResult,
|
Result as WryResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) type DynEventHandlerFn = dyn Fn(&mut EventLoop<()>, &mut WebView);
|
// pub(crate) type DynEventHandlerFn = dyn Fn(&mut EventLoop<()>, &mut WebView);
|
||||||
|
|
||||||
|
/// The configuration for the desktop application.
|
||||||
pub struct DesktopConfig {
|
pub struct DesktopConfig {
|
||||||
pub(crate) window: WindowBuilder,
|
pub(crate) window: WindowBuilder,
|
||||||
pub(crate) file_drop_handler: Option<Box<dyn Fn(&Window, FileDropEvent) -> bool>>,
|
pub(crate) file_drop_handler: Option<Box<dyn Fn(&Window, FileDropEvent) -> bool>>,
|
||||||
pub(crate) protocols: Vec<WryProtocol>,
|
pub(crate) protocols: Vec<WryProtocol>,
|
||||||
pub(crate) pre_rendered: Option<String>,
|
pub(crate) pre_rendered: Option<String>,
|
||||||
pub(crate) event_handler: Option<Box<DynEventHandlerFn>>,
|
// pub(crate) event_handler: Option<Box<DynEventHandlerFn>>,
|
||||||
pub(crate) disable_context_menu: bool,
|
pub(crate) disable_context_menu: bool,
|
||||||
pub(crate) resource_dir: Option<PathBuf>,
|
pub(crate) resource_dir: Option<PathBuf>,
|
||||||
pub(crate) custom_head: Option<String>,
|
pub(crate) custom_head: Option<String>,
|
||||||
@@ -37,7 +35,7 @@ impl DesktopConfig {
|
|||||||
let window = WindowBuilder::new().with_title("Dioxus app");
|
let window = WindowBuilder::new().with_title("Dioxus app");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
event_handler: None,
|
// event_handler: None,
|
||||||
window,
|
window,
|
||||||
protocols: Vec::new(),
|
protocols: Vec::new(),
|
||||||
file_drop_handler: None,
|
file_drop_handler: None,
|
||||||
@@ -50,7 +48,7 @@ impl DesktopConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// set the directory from which assets will be searched in release mode
|
/// set the directory from which assets will be searched in release mode
|
||||||
pub fn with_resource_directory(mut self, path: impl Into<PathBuf>) -> Self {
|
pub fn with_resource_directory(&mut self, path: impl Into<PathBuf>) -> &mut Self {
|
||||||
self.resource_dir = Some(path.into());
|
self.resource_dir = Some(path.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -61,12 +59,13 @@ impl DesktopConfig {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// With pre-rendered HTML content
|
/// Set the pre-rendered HTML content
|
||||||
pub fn with_prerendered(&mut self, content: String) -> &mut Self {
|
pub fn with_prerendered(&mut self, content: String) -> &mut Self {
|
||||||
self.pre_rendered = Some(content);
|
self.pre_rendered = Some(content);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the configuration for the window.
|
||||||
pub fn with_window(
|
pub fn with_window(
|
||||||
&mut self,
|
&mut self,
|
||||||
configure: impl FnOnce(WindowBuilder) -> WindowBuilder,
|
configure: impl FnOnce(WindowBuilder) -> WindowBuilder,
|
||||||
@@ -80,14 +79,16 @@ impl DesktopConfig {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_event_handler(
|
// /// Set a custom event handler
|
||||||
&mut self,
|
// pub fn with_event_handler(
|
||||||
handler: impl Fn(&mut EventLoop<()>, &mut WebView) + 'static,
|
// &mut self,
|
||||||
) -> &mut Self {
|
// handler: impl Fn(&mut EventLoop<()>, &mut WebView) + 'static,
|
||||||
self.event_handler = Some(Box::new(handler));
|
// ) -> &mut Self {
|
||||||
self
|
// self.event_handler = Some(Box::new(handler));
|
||||||
}
|
// self
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// Set a file drop handler
|
||||||
pub fn with_file_drop_handler(
|
pub fn with_file_drop_handler(
|
||||||
&mut self,
|
&mut self,
|
||||||
handler: impl Fn(&Window, FileDropEvent) -> bool + 'static,
|
handler: impl Fn(&Window, FileDropEvent) -> bool + 'static,
|
||||||
@@ -96,6 +97,7 @@ impl DesktopConfig {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set a custom protocol
|
||||||
pub fn with_custom_protocol<F>(&mut self, name: String, handler: F) -> &mut Self
|
pub fn with_custom_protocol<F>(&mut self, name: String, handler: F) -> &mut Self
|
||||||
where
|
where
|
||||||
F: Fn(&HttpRequest) -> WryResult<HttpResponse> + 'static,
|
F: Fn(&HttpRequest) -> WryResult<HttpResponse> + 'static,
|
||||||
@@ -104,7 +106,7 @@ impl DesktopConfig {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a custom icon for this application
|
/// Set a custom icon for this application
|
||||||
pub fn with_icon(&mut self, icon: Icon) -> &mut Self {
|
pub fn with_icon(&mut self, icon: Icon) -> &mut Self {
|
||||||
self.window.window.window_icon = Some(icon);
|
self.window.window.window_icon = Some(icon);
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ pub use wry;
|
|||||||
pub use wry::application as tao;
|
pub use wry::application as tao;
|
||||||
|
|
||||||
use crate::events::trigger_from_serialized;
|
use crate::events::trigger_from_serialized;
|
||||||
use cfg::DesktopConfig;
|
pub use cfg::DesktopConfig;
|
||||||
use controller::DesktopController;
|
use controller::DesktopController;
|
||||||
use dioxus_core::*;
|
use dioxus_core::*;
|
||||||
use events::parse_ipc_message;
|
use events::parse_ipc_message;
|
||||||
|
pub use tao::window::WindowBuilder;
|
||||||
use tao::{
|
use tao::{
|
||||||
event::{Event, StartCause, WindowEvent},
|
event::{Event, StartCause, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
|
|||||||
Reference in new issue
Block a user