Merge pull request #271 from DioxusLabs/jk/desktop-no-reload

Disable reload context menu in production
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2022-02-20 16:07:35 -05:00
commit 55bb62bbc8
1 file changed
+18
+18
View File
@@ -174,7 +174,25 @@ pub fn launch_with_props<P: 'static + Send>(
} }
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
// in debug, we are okay with the reload menu showing and dev tool
webview = webview.with_dev_tool(true); webview = webview.with_dev_tool(true);
} else {
// in release mode, we don't want to show the dev tool or reload menus
webview = webview.with_initialization_script(
r#"
if (document.addEventListener) {
document.addEventListener('contextmenu', function(e) {
alert("You've tried to open context menu");
e.preventDefault();
}, false);
} else {
document.attachEvent('oncontextmenu', function() {
alert("You've tried to open context menu");
window.event.returnValue = false;
});
}
"#,
)
} }
desktop.webviews.insert(window_id, webview.build().unwrap()); desktop.webviews.insert(window_id, webview.build().unwrap());