feat: Make devtools a feature

Users can now enable DevTools easily,
without worrying about forgetting 'uncomment' that function.
This commit is contained in:
pan93412
2022-11-08 15:32:36 +08:00
parent ec782240f6
commit a3180fbd4d
2 changed files with 9 additions and 4 deletions

View File

@@ -28,3 +28,5 @@ default = [ "custom-protocol" ]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]
# Enable DevTools for debugging.
devtools = []

View File

@@ -74,14 +74,17 @@ fn main() -> wry::Result<()> {
}
};
let _webview = WebViewBuilder::new(window)?
let webview = WebViewBuilder::new(window)?
.with_url(&url.to_string())?
// .with_devtools(true)
.with_devtools(cfg!(feature = "devtools"))
.with_initialization_script(include_str!("pake.js"))
.with_ipc_handler(handler)
.build()?;
// _webview.open_devtools();
#[cfg(feature = "devtools")] {
webview.open_devtools();
}
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
@@ -97,7 +100,7 @@ fn main() -> wry::Result<()> {
..
} => {
if menu_id == close_item.clone().id() {
_webview.window().set_minimized(true);
webview.window().set_minimized(true);
}
println!("Clicked on {:?}", menu_id);
}