Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface GlobalShortcut {
autoCopy?: boolean
}

type BuiltInShortcutKey = 'search' | 'closePlugin' | 'killPlugin'
type BuiltInShortcutKey = 'search' | 'closePlugin' | 'killPlugin' | 'esc'

type BuiltInShortcutConfig = Record<BuiltInShortcutKey, boolean>

Expand All @@ -49,7 +49,8 @@ interface AliasRow {
const DEFAULT_BUILTIN_SHORTCUTS_ENABLED: BuiltInShortcutConfig = {
search: true,
closePlugin: true,
killPlugin: true
killPlugin: true,
esc: true
}

// 获取平台信息
Expand Down Expand Up @@ -100,6 +101,14 @@ const baseBuiltInShortcuts: GlobalShortcut[] = [
configurable: true,
configKey: 'closePlugin'
},
{
id: 'builtin-esc',
shortcut: 'ESC',
target: '清空输入/退出插件/隐藏窗口',
enabled: true,
configurable: true,
configKey: 'esc'
},
{
id: 'builtin-devtools',
shortcut: 'DEVTOOLS',
Expand Down
6 changes: 6 additions & 0 deletions src/main/api/plugin/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export class PluginUIAPI {

// 插件 ESC 按键事件(由插件 preload 通过 JS 拦截后上报)
ipcMain.on('plugin-esc-pressed', () => {
const settings = databaseAPI.dbGet('settings-general') || {}
const escShortcutEnabled = settings?.builtinAppShortcutsEnabled?.esc !== false
if (!escShortcutEnabled) {
return
}

if (this.pluginManager && typeof this.pluginManager.handlePluginEsc === 'function') {
this.pluginManager.handlePluginEsc()
}
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ async function handleKeydown(event: KeyboardEvent): Promise<void> {

// Escape 键特殊处理
if (event.key === 'Escape') {
if (!windowStore.builtInEscShortcutEnabled) {
return
}

event.preventDefault()

if (currentView.value === ViewMode.Plugin) {
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/src/stores/windowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type AutoClearOption = 'immediately' | '1m' | '2m' | '3m' | '5m' | '10m'
// 搜索框模式选项
export type SearchMode = 'aggregate' | 'list'
export type TabKeyFunction = 'navigate' | 'target-command'
export type BuiltInShortcutKey = 'search' | 'closePlugin' | 'killPlugin'
export type BuiltInShortcutKey = 'search' | 'closePlugin' | 'killPlugin' | 'esc'

// 更新下载状态
interface UpdateDownloadInfo {
Expand Down Expand Up @@ -70,6 +70,7 @@ export const useWindowStore = defineStore('window', () => {
const builtInSearchShortcutEnabled = ref(true)
const builtInClosePluginShortcutEnabled = ref(true)
const builtInKillPluginShortcutEnabled = ref(true)
const builtInEscShortcutEnabled = ref(true)

// 悬浮球双击目标指令
const floatingBallDoubleClickCommand = ref('')
Expand Down Expand Up @@ -232,7 +233,11 @@ export const useWindowStore = defineStore('window', () => {
builtInClosePluginShortcutEnabled.value = value
return
}
builtInKillPluginShortcutEnabled.value = value
if (key === 'killPlugin') {
builtInKillPluginShortcutEnabled.value = value
return
}
builtInEscShortcutEnabled.value = value
}

function updateFloatingBallDoubleClickCommand(value: string): void {
Expand Down Expand Up @@ -569,6 +574,7 @@ export const useWindowStore = defineStore('window', () => {
builtInSearchShortcutEnabled.value = config.search !== false
builtInClosePluginShortcutEnabled.value = config.closePlugin !== false
builtInKillPluginShortcutEnabled.value = config.killPlugin !== false
builtInEscShortcutEnabled.value = config.esc !== false
}
} else {
// 默认蓝色
Expand Down Expand Up @@ -632,6 +638,7 @@ export const useWindowStore = defineStore('window', () => {
builtInSearchShortcutEnabled,
builtInClosePluginShortcutEnabled,
builtInKillPluginShortcutEnabled,
builtInEscShortcutEnabled,
updateBuiltInShortcutEnabled,
floatingBallDoubleClickCommand,
updateFloatingBallDoubleClickCommand,
Expand Down