From 5173d73b4239aeb330800725590ca6608782343e Mon Sep 17 00:00:00 2001 From: fanchenio Date: Thu, 9 Nov 2023 09:55:10 +0800 Subject: [PATCH] Fixed the bug that the quick search window can still be called up by using shortcut keys when quick search is disabled. --- electron/main/setting/index.ts | 89 ++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/electron/main/setting/index.ts b/electron/main/setting/index.ts index 570a77b..ad61201 100644 --- a/electron/main/setting/index.ts +++ b/electron/main/setting/index.ts @@ -75,32 +75,50 @@ function setShortcutKey(setting: Setting = global.setting) { setting.general.showHideShortcutKey && setting.general.showHideShortcutKey.trim() !== "" ) { - globalShortcut.register(setting.general.showHideShortcutKey, () => { - if (global.mainWindow.isVisible()) { - hideMainWindow(); - } else { - showMainWindowBefore(true); + try { + globalShortcut.register(setting.general.showHideShortcutKey, () => { + if (global.mainWindow.isVisible()) { + hideMainWindow(); + } else { + showMainWindowBefore(true); + } + }); + } catch (e) { + if (process.env.NODE_ENV === "development") { + console.log(e); } - }); + } } // 分类快捷键 let classificationList = selectClassificationList(); for (const classification of classificationList) { if (classification.globalShortcutKey && classification.shortcutKey) { - globalShortcut.register(classification.shortcutKey, () => { - // 分类 - showMainWindowBefore(true, classification.id); - }); + try { + globalShortcut.register(classification.shortcutKey, () => { + // 分类 + showMainWindowBefore(true, classification.id); + }); + } catch (e) { + if (process.env.NODE_ENV === "development") { + console.log(e); + } + } } } // 项目快捷键 let itemList = selectItemList(); for (const item of itemList) { if (item.globalShortcutKey && item.shortcutKey) { - globalShortcut.register(item.shortcutKey, () => { - // 项目 - run("main", "open", item); - }); + try { + globalShortcut.register(item.shortcutKey, () => { + // 项目 + run("main", "open", item); + }); + } catch (e) { + if (process.env.NODE_ENV === "development") { + console.log(e); + } + } } } // 快速搜索 @@ -108,24 +126,35 @@ function setShortcutKey(setting: Setting = global.setting) { setting.quickSearch.showHideShortcutKey && setting.quickSearch.showHideShortcutKey.trim() !== "" ) { - globalShortcut.register(setting.quickSearch.showHideShortcutKey, () => { - // 如果窗口不存在或者被销毁的话,就创建窗口 - if (!global.quickSearchWindow || global.quickSearchWindow.isDestroyed()) { - createQuickSearchWindow(); - } - // 如果初始化完毕并且窗口状态是正常的话,可以进行显示/隐藏 - if ( - global.quickSearchWindowInit && - global.quickSearchWindow && - !global.quickSearchWindow.isDestroyed() - ) { - if (global.quickSearchWindow.isVisible()) { - hideQuickSearchWindow(); - } else { - showQuickSearchWindowBefore(); + try { + globalShortcut.register(setting.quickSearch.showHideShortcutKey, () => { + if (global.setting.quickSearch.enable) { + // 如果窗口不存在或者被销毁的话,就创建窗口 + if ( + !global.quickSearchWindow || + global.quickSearchWindow.isDestroyed() + ) { + createQuickSearchWindow(); + } + // 如果初始化完毕并且窗口状态是正常的话,可以进行显示/隐藏 + if ( + global.quickSearchWindowInit && + global.quickSearchWindow && + !global.quickSearchWindow.isDestroyed() + ) { + if (global.quickSearchWindow.isVisible()) { + hideQuickSearchWindow(); + } else { + showQuickSearchWindowBefore(); + } + } } + }); + } catch (e) { + if (process.env.NODE_ENV === "development") { + console.log(e); } - }); + } } }