🚧 WIP: shortcut setting page

This commit is contained in:
PiEgg 2019-09-11 15:31:27 +08:00
parent f491209bd6
commit 1274893154
8 changed files with 203 additions and 32 deletions

View File

@ -27,6 +27,7 @@ import {
updateShortKeyFromVersion212 updateShortKeyFromVersion212
} from './migrate/shortKeyUpdateHelper' } from './migrate/shortKeyUpdateHelper'
import { import {
shortKeyUpdater,
initShortKeyRegister initShortKeyRegister
} from './utils/shortKeyRegister' } from './utils/shortKeyRegister'
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
@ -451,13 +452,8 @@ ipcMain.on('uploadChoosedFiles', async (evt, files) => {
return uploadChoosedFiles(evt.sender, files) return uploadChoosedFiles(evt.sender, files)
}) })
ipcMain.on('updateShortKey', (evt, oldKey) => { ipcMain.on('updateShortKey', (evt, item) => {
globalShortcut.unregisterAll() shortKeyUpdater(globalShortcut, item)
for (let key in oldKey) {
globalShortcut.register(db.read().get('settings.shortKey').value()[key], () => {
return shortKeyHash[key]()
})
}
const notification = new Notification({ const notification = new Notification({
title: '操作成功', title: '操作成功',
body: '你的快捷键已经修改成功' body: '你的快捷键已经修改成功'
@ -510,9 +506,13 @@ ipcMain.on('getPicBeds', (evt) => {
evt.returnValue = picBeds evt.returnValue = picBeds
}) })
const shortKeyHash = { ipcMain.on('updateShortKey', (evt, val) => {
upload: uploadClipboardFiles // console.log(val)
} })
// const shortKeyHash = {
// upload: uploadClipboardFiles
// }
const gotTheLock = app.requestSingleInstanceLock() const gotTheLock = app.requestSingleInstanceLock()

View File

@ -1,17 +1,16 @@
// from v2.1.2 // from v2.1.2
const updateShortKeyFromVersion212 = (db, shortKeyConfig) => { const updateShortKeyFromVersion212 = (db, shortKeyConfig) => {
let needUpgrade = false let needUpgrade = false
Object.keys(shortKeyConfig).forEach(item => { if (shortKeyConfig.upload) {
if (typeof shortKeyConfig[item] === 'string') { needUpgrade = true
needUpgrade = true shortKeyConfig['picgo:upload'] = {
shortKeyConfig[item] = { enable: true,
enable: true, key: shortKeyConfig.upload,
key: shortKeyConfig[item], name: 'picgo:upload',
name: `picgo:${item}`, label: '快捷上传'
lable: '快捷上传'
}
} }
}) delete shortKeyConfig.upload
}
if (needUpgrade) { if (needUpgrade) {
db.read().set('settings.shortKey', shortKeyConfig).write() db.read().set('settings.shortKey', shortKeyConfig).write()
return shortKeyConfig return shortKeyConfig

View File

@ -11,6 +11,16 @@ const shortKeyHandler = (name) => {
} }
} }
const shortKeyUpdater = (globalShortcut, item) => {
if (item.enable === false) {
globalShortcut.unregister(item.key)
} else {
globalShortcut.register(item.key, () => {
shortKeyHandler(item.name)
})
}
}
// 初始化阶段的注册 // 初始化阶段的注册
const initShortKeyRegister = (globalShortcut, shortKeys) => { const initShortKeyRegister = (globalShortcut, shortKeys) => {
let errorList = [] let errorList = []
@ -28,5 +38,6 @@ const initShortKeyRegister = (globalShortcut, shortKeys) => {
} }
export { export {
shortKeyUpdater,
initShortKeyRegister initShortKeyRegister
} }

View File

@ -0,0 +1,31 @@
<template>
<el-dialog
title="设置快捷键"
:visible.sync="visible"
:modal-append-to-body="false"
>
</el-dialog>
</template>
<script>
// import keyDetect from 'utils/key-binding'
export default {
name: '',
props: {
visible: {
type: Boolean,
default: false
}
},
created () {
this.$db.read().get('settings.shortKey')
},
data () {
return {
list: []
}
}
}
</script>
<style lang='stylus'>
</style>

View File

@ -22,9 +22,9 @@
<el-button type="primary" round size="mini" @click="openLogSetting">点击设置</el-button> <el-button type="primary" round size="mini" @click="openLogSetting">点击设置</el-button>
</el-form-item> </el-form-item>
<el-form-item <el-form-item
label="修改上传快捷键" label="修改快捷键"
> >
<el-button type="primary" round size="mini" @click="keyBindingVisible = true">点击设置</el-button> <el-button type="primary" round size="mini" @click="goShortCutPage">点击设置</el-button>
</el-form-item> </el-form-item>
<el-form-item <el-form-item
label="自定义链接格式" label="自定义链接格式"
@ -516,6 +516,9 @@ export default {
}, },
goConfigPage () { goConfigPage () {
this.$electron.remote.shell.openExternal('https://picgo.github.io/PicGo-Doc/zh/guide/config.html#picgo设置') this.$electron.remote.shell.openExternal('https://picgo.github.io/PicGo-Doc/zh/guide/config.html#picgo设置')
},
goShortCutPage () {
this.$router.push('shortcut-page')
} }
}, },
beforeDestroy () { beforeDestroy () {

View File

@ -0,0 +1,109 @@
<template>
<div id="shortcut-page">
<div class="view-title">
快捷键设置
</div>
<el-row>
<el-col :span="20" :offset="2">
<el-table
:data="list"
size="mini"
>
<el-table-column
label="快捷键名称"
>
<template slot-scope="scope">
{{ scope.row.label ? scope.row.label : scope.row.name }}
</template>
</el-table-column>
<el-table-column
label="快捷键绑定"
prop="key"
>
</el-table-column>
<el-table-column
label="状态"
>
<template slot-scope="scope">
<el-tag
size="mini"
:type="scope.row.enable ? 'success' : 'danger'"
>
{{ scope.row.enable ? '已启用' : '已禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column
label="来源"
>
<template slot-scope="scope">
{{ calcOrigin(scope.row.name) }}
</template>
</el-table-column>
<el-table-column
label="操作"
>
<template slot-scope="scope">
<el-button
@click="toggleEnable(scope.row)"
size="mini"
type="text">
{{ scope.row.enable ? '禁用' : '启用' }}
</el-button>
<el-button
size="mini"
type="text">
编辑
</el-button>
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
</div>
</template>
<script>
export default {
name: 'shortcut-page',
data () {
return {
list: []
}
},
created () {
const shortKeyConfig = this.$db.read().get('settings.shortKey').value()
this.list = Object.keys(shortKeyConfig).map(item => shortKeyConfig[item])
},
methods: {
calcOrigin (item) {
const [origin] = item.split(':')
return origin
},
toggleEnable (item) {
const status = !item.enable
item.enable = status
this.$db.set(`settings.shortKey.${item.name}.enable`, status).write()
this.$electron.ipcRenderer.send('updateShortKeyConfig', item)
}
}
}
</script>
<style lang='stylus'>
#shortcut-page
.el-table
background-color: transparent
color #ddd
thead
color #bbb
th,tr
background-color: transparent
&__body
tr.el-table__row--striped
td
background transparent
&--enable-row-hover
.el-table__body
tr:hover
&>td
background #333
</style>

View File

@ -92,6 +92,11 @@ export default new Router({
path: 'plugin', path: 'plugin',
component: require('@/pages/Plugin').default, component: require('@/pages/Plugin').default,
name: 'plugin' name: 'plugin'
},
{
path: 'shortcut-page',
component: require('@/pages/ShortCutPage').default,
name: 'shortcut-page'
} }
] ]
}, },

View File

@ -711,7 +711,8 @@ async-limiter@~1.0.0:
async-validator@~1.8.1: async-validator@~1.8.1:
version "1.8.5" version "1.8.5"
resolved "https://registry.yarnpkg.com/async-validator/-/async-validator-1.8.5.tgz#dc3e08ec1fd0dddb67e60842f02c0cd1cec6d7f0" resolved "https://registry.npm.taobao.org/async-validator/download/async-validator-1.8.5.tgz#dc3e08ec1fd0dddb67e60842f02c0cd1cec6d7f0"
integrity sha1-3D4I7B/Q3dtn5ghC8CwM0c7G1/A=
dependencies: dependencies:
babel-runtime "6.x" babel-runtime "6.x"
@ -959,7 +960,8 @@ babel-helper-to-multiple-sequence-expressions@^0.1.1:
babel-helper-vue-jsx-merge-props@^2.0.0: babel-helper-vue-jsx-merge-props@^2.0.0:
version "2.0.3" version "2.0.3"
resolved "https://registry.yarnpkg.com/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-2.0.3.tgz#22aebd3b33902328e513293a8e4992b384f9f1b6" resolved "https://registry.npm.taobao.org/babel-helper-vue-jsx-merge-props/download/babel-helper-vue-jsx-merge-props-2.0.3.tgz#22aebd3b33902328e513293a8e4992b384f9f1b6"
integrity sha1-Iq69OzOQIyjlEyk6jkmSs4T58bY=
babel-helpers@^6.24.1: babel-helpers@^6.24.1:
version "6.24.1" version "6.24.1"
@ -2853,10 +2855,15 @@ copy-webpack-plugin@^4.0.1:
p-limit "^1.0.0" p-limit "^1.0.0"
serialize-javascript "^1.4.0" serialize-javascript "^1.4.0"
core-js@^2.2.0, core-js@^2.4.0, core-js@^2.5.0: core-js@^2.2.0, core-js@^2.5.0:
version "2.6.5" version "2.6.5"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895" resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.5.tgz#44bc8d249e7fb2ff5d00e0341a7ffb94fbf67895"
core-js@^2.4.0:
version "2.6.9"
resolved "https://registry.npm.taobao.org/core-js/download/core-js-2.6.9.tgz#6b4b214620c834152e179323727fc19741b084f2"
integrity sha1-a0shRiDINBUuF5Mjcn/Bl0GwhPI=
core-util-is@1.0.2, core-util-is@~1.0.0: core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@ -3322,7 +3329,8 @@ deep-is@~0.1.3:
deepmerge@^1.2.0: deepmerge@^1.2.0:
version "1.5.2" version "1.5.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753" resolved "https://registry.npm.taobao.org/deepmerge/download/deepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753"
integrity sha1-EEmdhohEza1P7ghC34x/bwyVp1M=
deepmerge@^2.0.1: deepmerge@^2.0.1:
version "2.2.1" version "2.2.1"
@ -3779,8 +3787,9 @@ electron@^5.0.1:
extract-zip "^1.0.3" extract-zip "^1.0.3"
element-ui@^2.4.11: element-ui@^2.4.11:
version "2.6.1" version "2.12.0"
resolved "https://registry.yarnpkg.com/element-ui/-/element-ui-2.6.1.tgz#86db79ff5de9b1bcc3187b65b3772b0c54074718" resolved "https://registry.npm.taobao.org/element-ui/download/element-ui-2.12.0.tgz#a893bc11ae4f7dbb7e9d541606f23e643f131ee4"
integrity sha1-qJO8Ea5Pfbt+nVQWBvI+ZD8THuQ=
dependencies: dependencies:
async-validator "~1.8.1" async-validator "~1.8.1"
babel-helper-vue-jsx-merge-props "^2.0.0" babel-helper-vue-jsx-merge-props "^2.0.0"
@ -7182,7 +7191,8 @@ normalize-url@^1.4.0:
normalize-wheel@^1.0.1: normalize-wheel@^1.0.1:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/normalize-wheel/-/normalize-wheel-1.0.1.tgz#aec886affdb045070d856447df62ecf86146ec45" resolved "https://registry.npm.taobao.org/normalize-wheel/download/normalize-wheel-1.0.1.tgz#aec886affdb045070d856447df62ecf86146ec45"
integrity sha1-rsiGr/2wRQcNhWRH32Ls+GFG7EU=
npm-bundled@^1.0.1: npm-bundled@^1.0.1:
version "1.0.6" version "1.0.6"
@ -8556,7 +8566,8 @@ regenerator-runtime@^0.10.5:
regenerator-runtime@^0.11.0: regenerator-runtime@^0.11.0:
version "0.11.1" version "0.11.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" resolved "https://registry.npm.taobao.org/regenerator-runtime/download/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
integrity sha1-vgWtf5v30i4Fb5cmzuUBf78Z4uk=
regenerator-transform@^0.10.0: regenerator-transform@^0.10.0:
version "0.10.1" version "0.10.1"
@ -8731,7 +8742,8 @@ requires-port@^1.0.0:
resize-observer-polyfill@^1.5.0: resize-observer-polyfill@^1.5.0:
version "1.5.1" version "1.5.1"
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464" resolved "https://registry.npm.taobao.org/resize-observer-polyfill/download/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
integrity sha1-DpAg3T0hAkRY1OvSfiPkAmmBBGQ=
resolve-cwd@^2.0.0: resolve-cwd@^2.0.0:
version "2.0.0" version "2.0.0"
@ -9708,7 +9720,8 @@ text-table@^0.2.0, text-table@~0.2.0:
throttle-debounce@^1.0.1: throttle-debounce@^1.0.1:
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-1.1.0.tgz#51853da37be68a155cb6e827b3514a3c422e89cd" resolved "https://registry.npm.taobao.org/throttle-debounce/download/throttle-debounce-1.1.0.tgz#51853da37be68a155cb6e827b3514a3c422e89cd"
integrity sha1-UYU9o3vmihVctugns1FKPEIuic0=
throttleit@0.0.2: throttleit@0.0.2:
version "0.0.2" version "0.0.2"