Skip to content

Commit

Permalink
Merge pull request #271 from DioxusLabs/jk/desktop-no-reload
Browse files Browse the repository at this point in the history
Disable reload context menu in production
  • Loading branch information
jkelleyrtp authored Feb 20, 2022
2 parents 93b4f74 + 5954bba commit 55bb62b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/desktop/src/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Dioxus app</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="main"></div>
<script>
import("./index.js").then(function (module) {
module.main();
});
</script>
</body>
<head>
<title>Dioxus app</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="main"></div>
<script>
import("./index.js").then(function (module) {
module.main();
});
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions packages/desktop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,25 @@ pub fn launch_with_props<P: 'static + Send>(
}

if cfg!(debug_assertions) {
// 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
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());
Expand Down

0 comments on commit 55bb62b

Please sign in to comment.