Small fix for release builds (disable right-click menu)

modified:   src/main.rs
This commit is contained in:
Michael Wain 2025-04-01 02:23:39 +03:00
parent 77db075915
commit a5a5b59719

View File

@ -38,7 +38,7 @@ struct App {
impl ApplicationHandler for App { impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &ActiveEventLoop) { fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let window = event_loop.create_window(Window::default_attributes().with_inner_size(LogicalSize::new(900, 600)).with_min_inner_size(LogicalSize::new(900, 600)).with_title("XCraft")).unwrap(); let window = event_loop.create_window(Window::default_attributes().with_inner_size(LogicalSize::new(900, 600)).with_min_inner_size(LogicalSize::new(900, 600)).with_title("XCraft")).unwrap();
let webview = WebViewBuilder::new() let mut webview_builder = WebViewBuilder::new()
.with_asynchronous_custom_protocol("xcraft".into(), move |_wid, request, responder| { .with_asynchronous_custom_protocol("xcraft".into(), move |_wid, request, responder| {
let uri = request.uri().to_string(); let uri = request.uri().to_string();
if let Ok(msg) = serde_json::from_slice(request.body()) { if let Ok(msg) = serde_json::from_slice(request.body()) {
@ -47,9 +47,17 @@ impl ApplicationHandler for App {
} }
let _ = SENDER.lock().unwrap().as_ref().unwrap().send((uri, None, responder)); let _ = SENDER.lock().unwrap().as_ref().unwrap().send((uri, None, responder));
}) })
.with_url("xcraft://custom/ui") .with_url("xcraft://custom/ui");
.build(&window)
.unwrap(); if !cfg!(debug_assertions) {
webview_builder = webview_builder.with_initialization_script(r#"
document.addEventListener("contextmenu", event => event.preventDefault());
"#);
}
let webview = webview_builder
.build(&window)
.unwrap();
self.window = Some(window); self.window = Some(window);
self.webview = Some(webview); self.webview = Some(webview);