🚧 WIP: handle shortcut setting time

This commit is contained in:
PiEgg 2019-09-25 16:34:29 +08:00
parent b63ac03b84
commit 72e6e2aed5
5 changed files with 29 additions and 55 deletions

View File

@ -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 = {

View File

@ -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-')) {

View File

@ -91,29 +91,6 @@
</el-col>
</el-row>
</el-dialog>
<el-dialog
title="修改快捷键"
:visible.sync="keyBindingVisible"
>
<el-form
label-width="80px"
>
<el-form-item
label="快捷上传"
>
<el-input
class="align-center"
@keydown.native.prevent="keyDetect('upload', $event)"
v-model="shortKey.upload"
:autofocus="true"
></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<el-button @click="cancelKeyBinding">取消</el-button>
<el-button type="primary" @click="confirmKeyBinding">确定</el-button>
</span>
</el-dialog>
<el-dialog
title="自定义链接格式"
:visible.sync="customLinkVisible"

View File

@ -120,30 +120,6 @@
</el-row>
</el-col>
</el-row>
<el-dialog
title="修改上传快捷键"
:visible.sync="keyBindingVisible"
:modal-append-to-body="false"
>
<el-form
label-width="80px"
>
<el-form-item
label="快捷上传"
>
<el-input
class="align-center"
@keydown.native.prevent="keyDetect('upload', $event)"
v-model="shortKey.upload"
:autofocus="true"
></el-input>
</el-form-item>
</el-form>
<span slot="footer">
<el-button @click="cancelKeyBinding" round>取消</el-button>
<el-button type="primary" @click="confirmKeyBinding" round>确定</el-button>
</span>
</el-dialog>
<el-dialog
title="自定义链接格式"
:visible.sync="customLinkVisible"

View File

@ -57,7 +57,7 @@
<el-button
class="edit"
size="mini"
@click="openKeyBindingDialog(scope.row.name)"
@click="openKeyBindingDialog(scope.row.name, scope.$index)"
type="text">
编辑
</el-button>
@ -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)
}
}
</script>