feat: tweak debug tools to be customizable

This commit is contained in:
Jonathan Kelley committed 2022-02-21 23:45:01 -05:00
1 parent 1b3e865a5a
commit d19ae3ff56
2 files changed
+12 -4

No files matched your search

+8
View File
@@ -17,6 +17,7 @@ pub struct DesktopConfig {
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) type WryProtocol = ( pub(crate) type WryProtocol = (
@@ -29,15 +30,22 @@ impl DesktopConfig {
#[inline] #[inline]
pub fn new() -> Self { pub fn new() -> Self {
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,
pre_rendered: None, pre_rendered: None,
disable_context_menu: !cfg!(debug_assertions),
} }
} }
pub fn with_disable_context_menu(&mut self, disable: bool) -> &mut Self {
self.disable_context_menu = disable;
self
}
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
+4 -4
View File
@@ -172,10 +172,7 @@ pub fn launch_with_props<P: 'static + Send>(
webview = webview.with_custom_protocol(name, handler) webview = webview.with_custom_protocol(name, handler)
} }
if cfg!(debug_assertions) { if cfg.disable_context_menu {
// in debug, we are okay with the reload menu showing and dev tool
webview = webview.with_dev_tool(true);
} else {
// in release mode, we don't want to show the dev tool or reload menus // in release mode, we don't want to show the dev tool or reload menus
webview = webview.with_initialization_script( webview = webview.with_initialization_script(
r#" r#"
@@ -192,6 +189,9 @@ pub fn launch_with_props<P: 'static + Send>(
} }
"#, "#,
) )
} else {
// in debug, we are okay with the reload menu showing and dev tool
webview = webview.with_dev_tool(true);
} }
desktop.webviews.insert(window_id, webview.build().unwrap()); desktop.webviews.insert(window_id, webview.build().unwrap());