From 72e6e2aed521f9c83ef5deedb9517bee2978c0a6 Mon Sep 17 00:00:00 2001 From: PiEgg Date: Wed, 25 Sep 2019 16:34:29 +0800 Subject: [PATCH] :construction: WIP: handle shortcut setting time --- src/main/index.js | 11 +++++---- ...shortKeyRegister.js => shortKeyHandler.js} | 9 ++++++- src/renderer/layouts/SettingPage.vue | 23 ------------------ src/renderer/pages/PicGoSetting.vue | 24 ------------------- src/renderer/pages/ShortCutPage.vue | 17 ++++++++++--- 5 files changed, 29 insertions(+), 55 deletions(-) rename src/main/utils/{shortKeyRegister.js => shortKeyHandler.js} (84%) diff --git a/src/main/index.js b/src/main/index.js index 05075e0..d50bea0 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -29,7 +29,7 @@ import { import { shortKeyUpdater, initShortKeyRegister -} from './utils/shortKeyRegister' +} from './utils/shortKeyHandler' if (process.platform === 'darwin') { beforeOpen() } @@ -309,9 +309,12 @@ const createSettingWindow = () => { settingWindow.loadURL(settingWinURL) settingWindow.on('closed', () => { + bus.emit('toggleShortKeyModifiedMode', false) settingWindow = null if (process.platform === 'linux') { - app.quit() + process.nextTick(() => { + app.quit() + }) } }) createMenu() @@ -506,8 +509,8 @@ ipcMain.on('getPicBeds', (evt) => { evt.returnValue = picBeds }) -ipcMain.on('updateShortKey', (evt, val) => { - // console.log(val) +ipcMain.on('toggleShortKeyModifiedMode', (evt, val) => { + bus.emit('toggleShortKeyModifiedMode', val) }) // const shortKeyHash = { diff --git a/src/main/utils/shortKeyRegister.js b/src/main/utils/shortKeyHandler.js similarity index 84% rename from src/main/utils/shortKeyRegister.js rename to src/main/utils/shortKeyHandler.js index f608155..7aefe3b 100644 --- a/src/main/utils/shortKeyRegister.js +++ b/src/main/utils/shortKeyHandler.js @@ -1,9 +1,16 @@ -import bus from '../utils/eventBus' +import bus from './eventBus' +let isInModifiedMode = false // 修改快捷键模式 +bus.on('toggleShortKeyModifiedMode', flag => { + isInModifiedMode = flag +}) /** * * @param {string} name */ const shortKeyHandler = (name) => { + if (isInModifiedMode) { + return + } if (name.includes('picgo:')) { bus.emit(name) } else if (name.includes('picgo-plugin-')) { diff --git a/src/renderer/layouts/SettingPage.vue b/src/renderer/layouts/SettingPage.vue index 421952e..f86228c 100644 --- a/src/renderer/layouts/SettingPage.vue +++ b/src/renderer/layouts/SettingPage.vue @@ -91,29 +91,6 @@ - - - - - - - - 取消 - 确定 - - - - - - - - - - 取消 - 确定 - - 编辑 @@ -102,13 +102,19 @@ export default { list: [], keyBindingVisible: false, shortKeyName: '', - shortKey: '' + shortKey: '', + currentIndex: 0 } }, created () { const shortKeyConfig = this.$db.get('settings.shortKey') this.list = Object.keys(shortKeyConfig).map(item => shortKeyConfig[item]) }, + watch: { + keyBindingVisible (val) { + this.$electron.ipcRenderer.send('toggleShortKeyModifiedMode', val) + } + }, methods: { calcOrigin (item) { const [origin] = item.split(':') @@ -123,9 +129,10 @@ export default { keyDetect (event) { this.shortKey = keyDetect(event).join('+') }, - openKeyBindingDialog (name) { + openKeyBindingDialog (name, index) { this.shortKeyName = name this.shortKey = this.$db.get(`settings.shortKey.${name}.key`) + this.currentIndex = index this.keyBindingVisible = true }, cancelKeyBinding () { @@ -137,8 +144,12 @@ export default { this.$db.set(`settings.shortKey.${this.shortKeyName}.key`, this.shortKey) const newKey = this.$db.get(`settings.shortKey.${this.shortKeyName}`) this.$electron.ipcRenderer.send('updateShortKey', newKey, oldKey) + this.list[this.currentIndex].key = this.shortKey this.keyBindingVisible = false } + }, + beforeDestroy () { + this.$electron.ipcRenderer.send('toggleShortKeyModifiedMode', false) } }