From 93d552870e61cea89bcb6dc2ae0d36b8b5087188 Mon Sep 17 00:00:00 2001 From: YangChengxxyy <45156288+YangChengxxyy@users.noreply.github.com> Date: Wed, 1 Apr 2026 19:11:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=20=E5=A4=8D=E5=88=B6=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=A1=8C=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: YangChengxxyy --- src/main/resolve/shortcut.ts | 21 +++++++++++++++++-- .../components/settings/shortcut-config.tsx | 14 +++++++++++-- src/renderer/src/locales/en-US.json | 2 ++ src/renderer/src/locales/fa-IR.json | 2 ++ src/renderer/src/locales/ru-RU.json | 2 ++ src/renderer/src/locales/zh-CN.json | 2 ++ src/renderer/src/locales/zh-TW.json | 2 ++ src/shared/types.d.ts | 1 + 8 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/resolve/shortcut.ts b/src/main/resolve/shortcut.ts index 4840e1e..379f98f 100644 --- a/src/main/resolve/shortcut.ts +++ b/src/main/resolve/shortcut.ts @@ -11,7 +11,7 @@ import { patchMihomoConfig } from '../core/mihomoApi' import { quitWithoutCore, restartCore } from '../core/manager' import i18next from '../../shared/i18n' import { floatingWindow, triggerFloatingWindow } from './floatingWindow' -import { updateTrayIcon } from './tray' +import { copyEnv, updateTrayIcon } from './tray' export async function registerShortcut( oldShortcut: string, @@ -133,6 +133,15 @@ export async function registerShortcut( app.quit() }) } + case 'copyEnvShortcut': { + return globalShortcut.register(newShortcut, async () => { + const shellType = process.platform === 'win32' ? 'powershell' : 'bash' + await copyEnv(shellType) + new Notification({ + title: i18next.t('common.notification.copyEnvSuccess') + }).show() + }) + } } throw new Error('Unknown action') } @@ -147,7 +156,8 @@ export async function initShortcut(): Promise { globalModeShortcut, directModeShortcut, quitWithoutCoreShortcut, - restartAppShortcut + restartAppShortcut, + copyEnvShortcut } = await getAppConfig() if (showWindowShortcut) { try { @@ -212,4 +222,11 @@ export async function initShortcut(): Promise { // ignore } } + if (copyEnvShortcut) { + try { + await registerShortcut('', copyEnvShortcut, 'copyEnvShortcut') + } catch { + // ignore + } + } } diff --git a/src/renderer/src/components/settings/shortcut-config.tsx b/src/renderer/src/components/settings/shortcut-config.tsx index 08efe9f..658c109 100644 --- a/src/renderer/src/components/settings/shortcut-config.tsx +++ b/src/renderer/src/components/settings/shortcut-config.tsx @@ -53,7 +53,8 @@ const ShortcutConfig: React.FC = () => { globalModeShortcut = '', directModeShortcut = '', quitWithoutCoreShortcut = '', - restartAppShortcut = '' + restartAppShortcut = '', + copyEnvShortcut = '' } = appConfig || {} return ( @@ -130,7 +131,7 @@ const ShortcutConfig: React.FC = () => { /> - +
{ />
+ +
+ +
+
) } diff --git a/src/renderer/src/locales/en-US.json b/src/renderer/src/locales/en-US.json index 4cb0080..31f1a84 100644 --- a/src/renderer/src/locales/en-US.json +++ b/src/renderer/src/locales/en-US.json @@ -24,6 +24,7 @@ "common.notification.restartRequired": "Restart required for changes to take effect", "common.notification.systemProxyEnabled": "System proxy enabled", "common.notification.systemProxyDisabled": "System proxy disabled", + "common.notification.copyEnvSuccess": "Shell env command copied", "common.notification.tunEnabled": "TUN enabled", "common.notification.tunDisabled": "TUN disabled", "common.notification.ruleMode": "Rule Mode", @@ -294,6 +295,7 @@ "shortcuts.toggleDirectMode": "Toggle Direct Mode", "shortcuts.toggleLightMode": "Toggle Light Mode", "shortcuts.restartApp": "Restart App", + "shortcuts.copyEnv": "Copy Shell Env Command", "shortcuts.input.placeholder": "Click to input shortcut", "sider.title": "Sidebar Settings", "sider.cards.systemProxy": "Sys Proxy", diff --git a/src/renderer/src/locales/fa-IR.json b/src/renderer/src/locales/fa-IR.json index 14a8827..daae021 100644 --- a/src/renderer/src/locales/fa-IR.json +++ b/src/renderer/src/locales/fa-IR.json @@ -24,6 +24,7 @@ "common.notification.restartRequired": "برای اعمال تغییرات نیاز به راه‌اندازی مجدد است", "common.notification.systemProxyEnabled": "پراکسی سیستم فعال شد", "common.notification.systemProxyDisabled": "پراکسی سیستم غیرفعال شد", + "common.notification.copyEnvSuccess": "دستور محیطی کپی شد", "common.notification.tunEnabled": "TUN فعال شد", "common.notification.tunDisabled": "TUN غیرفعال شد", "common.notification.ruleMode": "حالت قانون", @@ -269,6 +270,7 @@ "shortcuts.toggleDirectMode": "تغییر وضعیت حالت مستقیم", "shortcuts.toggleLightMode": "تغییر وضعیت حالت روشن", "shortcuts.restartApp": "راه‌اندازی مجدد برنامه", + "shortcuts.copyEnv": "کپی دستور محیطی", "shortcuts.input.placeholder": "برای ورود میانبر کلیک کنید", "sider.title": "تنظیمات نوار کناری", "sider.cards.systemProxy": "پراکسی سیستم", diff --git a/src/renderer/src/locales/ru-RU.json b/src/renderer/src/locales/ru-RU.json index 4faf5e0..ffebf5e 100644 --- a/src/renderer/src/locales/ru-RU.json +++ b/src/renderer/src/locales/ru-RU.json @@ -24,6 +24,7 @@ "common.notification.restartRequired": "Требуется перезапуск для применения изменений", "common.notification.systemProxyEnabled": "Системный прокси включен", "common.notification.systemProxyDisabled": "Системный прокси отключен", + "common.notification.copyEnvSuccess": "Команда env скопирована", "common.notification.tunEnabled": "TUN включен", "common.notification.tunDisabled": "TUN отключен", "common.notification.ruleMode": "Правило", @@ -271,6 +272,7 @@ "shortcuts.toggleDirectMode": "Переключить прямое подключение", "shortcuts.toggleLightMode": "Переключить облегченный режим", "shortcuts.restartApp": "Перезапустить приложение", + "shortcuts.copyEnv": "Копировать команду env", "shortcuts.input.placeholder": "Нажмите для ввода комбинации", "sider.title": "Настройки боковой панели", "sider.cards.systemProxy": "Системный прокси", diff --git a/src/renderer/src/locales/zh-CN.json b/src/renderer/src/locales/zh-CN.json index 06a976a..409df72 100644 --- a/src/renderer/src/locales/zh-CN.json +++ b/src/renderer/src/locales/zh-CN.json @@ -24,6 +24,7 @@ "common.notification.restartRequired": "需要重启应用以使更改生效", "common.notification.systemProxyEnabled": "系统代理已启用", "common.notification.systemProxyDisabled": "系统代理已关闭", + "common.notification.copyEnvSuccess": "命令行命令已复制", "common.notification.tunEnabled": "TUN 已启用", "common.notification.tunDisabled": "TUN 已关闭", "common.notification.ruleMode": "规则模式", @@ -294,6 +295,7 @@ "shortcuts.toggleDirectMode": "切换直连模式", "shortcuts.toggleLightMode": "切换轻量模式", "shortcuts.restartApp": "重启应用", + "shortcuts.copyEnv": "复制命令行命令", "shortcuts.input.placeholder": "点击输入快捷键", "sider.title": "侧边栏设置", "sider.cards.systemProxy": "系统代理", diff --git a/src/renderer/src/locales/zh-TW.json b/src/renderer/src/locales/zh-TW.json index 9a1f189..43d4721 100644 --- a/src/renderer/src/locales/zh-TW.json +++ b/src/renderer/src/locales/zh-TW.json @@ -24,6 +24,7 @@ "common.notification.restartRequired": "需要重新啟動應用以使更改生效", "common.notification.systemProxyEnabled": "系統代理已啟用", "common.notification.systemProxyDisabled": "系統代理已關閉", + "common.notification.copyEnvSuccess": "命令行命令已複製", "common.notification.tunEnabled": "TUN 已啟用", "common.notification.tunDisabled": "TUN 已關閉", "common.notification.ruleMode": "規則模式", @@ -294,6 +295,7 @@ "shortcuts.toggleDirectMode": "切換直連模式", "shortcuts.toggleLightMode": "切換輕量模式", "shortcuts.restartApp": "重啟應用", + "shortcuts.copyEnv": "複製命令行命令", "shortcuts.input.placeholder": "點擊輸入快捷鍵", "sider.title": "側邊欄設置", "sider.cards.systemProxy": "系統代理", diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index 7ab8ad6..f4208fb 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -338,6 +338,7 @@ interface IAppConfig { directModeShortcut?: string restartAppShortcut?: string quitWithoutCoreShortcut?: string + copyEnvShortcut?: string language?: 'zh-CN' | 'zh-TW' | 'en-US' | 'ru-RU' | 'fa-IR' triggerMainWindowBehavior?: 'show' | 'toggle' showMixedPort?: number