diff --git a/src/main/index.js b/src/main/index.js index c72da4b..05075e0 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -452,8 +452,8 @@ ipcMain.on('uploadChoosedFiles', async (evt, files) => { return uploadChoosedFiles(evt.sender, files) }) -ipcMain.on('updateShortKey', (evt, item) => { - shortKeyUpdater(globalShortcut, item) +ipcMain.on('updateShortKey', (evt, item, oldKey) => { + shortKeyUpdater(globalShortcut, item, oldKey) const notification = new Notification({ title: '操作成功', body: '你的快捷键已经修改成功' diff --git a/src/main/utils/shortKeyRegister.js b/src/main/utils/shortKeyRegister.js index 00819cf..f608155 100644 --- a/src/main/utils/shortKeyRegister.js +++ b/src/main/utils/shortKeyRegister.js @@ -11,7 +11,17 @@ const shortKeyHandler = (name) => { } } -const shortKeyUpdater = (globalShortcut, item) => { +/** + * 用于更新快捷键绑定 + * @param {globalShortcut} globalShortcut + * @param {keyObject} item + * @param {string} oldKey + */ +const shortKeyUpdater = (globalShortcut, item, oldKey) => { + // 如果提供了旧key,则解绑 + if (oldKey) { + globalShortcut.unregister(oldKey) + } if (item.enable === false) { globalShortcut.unregister(item.key) } else { diff --git a/src/renderer/layouts/SettingPage.vue b/src/renderer/layouts/SettingPage.vue index d0fd3be..421952e 100644 --- a/src/renderer/layouts/SettingPage.vue +++ b/src/renderer/layouts/SettingPage.vue @@ -281,12 +281,6 @@ export default { this.keyBindingVisible = false this.shortKey = db.get('shortKey') }, - confirmKeyBinding () { - const oldKey = db.get('shortKey') - db.set('shortKey', this.shortKey) - this.keyBindingVisible = false - this.$electron.ipcRenderer.send('updateShortKey', oldKey) - }, cancelCustomLink () { this.customLinkVisible = false this.customLink.value = db.get('customLink') || '$url' diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index e5e18f1..dad9153 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -370,12 +370,6 @@ export default { this.keyBindingVisible = false this.shortKey = this.$db.get('settings.shortKey') }, - confirmKeyBinding () { - const oldKey = this.$db.get('settings.shortKey') - this.$db.set('settings.shortKey', this.shortKey) - this.keyBindingVisible = false - this.$electron.ipcRenderer.send('updateShortKey', oldKey) - }, cancelCustomLink () { this.customLinkVisible = false this.customLink.value = this.$db.get('settings.customLink') || '$url' diff --git a/src/renderer/pages/ShortCutPage.vue b/src/renderer/pages/ShortCutPage.vue index 9f3044e..eb6c035 100644 --- a/src/renderer/pages/ShortCutPage.vue +++ b/src/renderer/pages/ShortCutPage.vue @@ -17,6 +17,7 @@ @@ -47,11 +48,16 @@ {{ scope.row.enable ? '禁用' : '启用' }} 编辑 @@ -60,14 +66,43 @@ + + + + + + + + 取消 + 确定 + +