Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix: block browser context menu and add Reload/DevTools to View menu

esengine2a878db937ae
diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs
index 016da74dc..74bb2d806 100644
--- a/desktop/src-tauri/src/lib.rs
+++ b/desktop/src-tauri/src/lib.rs
@@ -6,7 +6,7 @@ use preview_server::PreviewServer;
use std::path::PathBuf;
use std::process::Stdio;
use std::sync::Mutex;
-use tauri::{AppHandle, Emitter, State};
+use tauri::{AppHandle, Emitter, Manager, State};
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::process::Command;
@@ -42,6 +42,17 @@ struct AppState {
// Commands
// =============================================================================
+#[tauri::command]
+fn toggle_devtools(app: AppHandle) {
+ if let Some(window) = app.get_webview_window("main") {
+ if window.is_devtools_open() {
+ window.close_devtools();
+ } else {
+ window.open_devtools();
+ }
+ }
+}
+
#[tauri::command]
fn start_preview_server(
state: State<AppState>,
@@ -255,6 +266,7 @@ pub fn run() {
preview_server: Mutex::new(None),
})
.invoke_handler(tauri::generate_handler![
+ toggle_devtools,
start_preview_server,
stop_preview_server,
open_preview_in_browser,
diff --git a/editor/src/Editor.ts b/editor/src/Editor.ts
index a91ac33d7..9d3ba0f34 100644
--- a/editor/src/Editor.ts
+++ b/editor/src/Editor.ts
@@ -1033,6 +1033,10 @@ export class Editor {
getGlobalPathResolver().setProjectDir(projectDir);
}
+ this.container_.addEventListener('contextmenu', (e) => {
+ e.preventDefault();
+ });
+
this.setupToolbarEvents();
this.store_.subscribe(() => this.updateToolbarState());
this.store_.subscribe(() => this.updateStatusbar());
diff --git a/editor/src/launcher/ProjectLauncher.ts b/editor/src/launcher/ProjectLauncher.ts
index 2305917f7..09e273d4c 100644
--- a/editor/src/launcher/ProjectLauncher.ts
+++ b/editor/src/launcher/ProjectLauncher.ts
@@ -136,6 +136,10 @@ export class ProjectLauncher {
}
private setupEvents(): void {
+ this.container_.addEventListener('contextmenu', (e) => {
+ e.preventDefault();
+ });
+
const newBtn = this.container_.querySelector('[data-action="new"]');
const openBtn = this.container_.querySelector('[data-action="open"]');
diff --git a/editor/src/menus/builtinMenus.ts b/editor/src/menus/builtinMenus.ts
index 3282dbdfa..b2405ac82 100644
--- a/editor/src/menus/builtinMenus.ts
+++ b/editor/src/menus/builtinMenus.ts
@@ -105,6 +105,19 @@ export function registerBuiltinMenus(editor: Editor): void {
order: 10, separator: true,
action: () => editor.reloadExtensions(),
});
+ registerMenuItem({
+ id: 'view.reload', menu: 'view', label: 'Reload',
+ shortcut: 'Ctrl+R', order: 20, separator: true,
+ action: () => window.location.reload(),
+ });
+ registerMenuItem({
+ id: 'view.devtools', menu: 'view', label: 'Developer Tools',
+ shortcut: 'F12', order: 21,
+ action: () => {
+ const ctx = getEditorContext();
+ ctx.invoke?.('toggle_devtools');
+ },
+ });
registerMenuItem({
id: 'help.docs', menu: 'help', label: 'Documentation', order: 0,
diff --git a/editor/src/ui/ContextMenu.ts b/editor/src/ui/ContextMenu.ts
index 2b15ff50b..27edf0689 100644
--- a/editor/src/ui/ContextMenu.ts
+++ b/editor/src/ui/ContextMenu.ts
@@ -202,6 +202,7 @@ class ContextMenuManager {
private createMenu(items: ContextMenuItem[], x: number, y: number, isRoot: boolean): HTMLElement {
const menu = document.createElement('div');
menu.className = 'es-context-menu';
+ menu.addEventListener('contextmenu', (e) => e.preventDefault());
for (let i = 0; i < items.length; i++) {
const item = items[i];