From 3a36da1bf94c58882c46f7e3f01e96dbe8b1b0ea Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Fri, 9 May 2025 22:12:16 +0800 Subject: [PATCH] feat: add inspect option to context menu with localization support (#5807) * implemented a new inspect menu item in the context menu that toggles developer tools * added localization for the inspect option in English, Japanese, Russian, and Chinese (both simplified and traditional) --- src/main/services/ContextMenu.ts | 19 ++++++++++++++++++- src/renderer/src/i18n/locales/en-us.json | 1 + src/renderer/src/i18n/locales/ja-jp.json | 1 + src/renderer/src/i18n/locales/ru-ru.json | 1 + src/renderer/src/i18n/locales/zh-cn.json | 1 + src/renderer/src/i18n/locales/zh-tw.json | 1 + 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/services/ContextMenu.ts b/src/main/services/ContextMenu.ts index 503af88db2..2f4f5aa20f 100644 --- a/src/main/services/ContextMenu.ts +++ b/src/main/services/ContextMenu.ts @@ -9,12 +9,29 @@ class ContextMenu { const template: MenuItemConstructorOptions[] = this.createEditMenuItems(properties) const filtered = template.filter((item) => item.visible !== false) if (filtered.length > 0) { - const menu = Menu.buildFromTemplate(filtered) + const menu = Menu.buildFromTemplate([...filtered, ...this.createInspectMenuItems(w)]) menu.popup() } }) } + private createInspectMenuItems(w: Electron.BrowserWindow): MenuItemConstructorOptions[] { + const locale = locales[configManager.getLanguage()] + const { common } = locale.translation + const template: MenuItemConstructorOptions[] = [ + { + id: 'inspect', + label: common.inspect, + click: () => { + w.webContents.toggleDevTools() + }, + enabled: true + } + ] + + return template + } + private createEditMenuItems(properties: Electron.ContextMenuParams): MenuItemConstructorOptions[] { const locale = locales[configManager.getLanguage()] const { common } = locale.translation diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 3d8ab74b96..0dffe56035 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -304,6 +304,7 @@ "confirm": "Confirm", "copied": "Copied", "copy": "Copy", + "inspect": "Inspect", "cut": "Cut", "default": "Default", "delete": "Delete", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index f1b12358d8..b813ededfc 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -304,6 +304,7 @@ "confirm": "確認", "copied": "コピーされました", "copy": "コピー", + "inspect": "検査", "cut": "切り取り", "default": "デフォルト", "delete": "削除", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index 2692e1c270..803be36eac 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -304,6 +304,7 @@ "confirm": "Подтверждение", "copied": "Скопировано", "copy": "Копировать", + "inspect": "Осмотреть", "cut": "Вырезать", "default": "По умолчанию", "delete": "Удалить", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index e68409a642..86c9ac34b8 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -304,6 +304,7 @@ "confirm": "确认", "copied": "已复制", "copy": "复制", + "inspect": "检查", "cut": "剪切", "default": "默认", "delete": "删除", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 893a7b75a1..4bec777b83 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -304,6 +304,7 @@ "confirm": "確認", "copied": "已複製", "copy": "複製", + "inspect": "檢查", "cut": "剪下", "default": "預設", "delete": "刪除",