mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
Fixed: #17
This commit is contained in:
parent
16fe016c70
commit
37a784225e
@ -133,7 +133,8 @@ let rendererConfig = {
|
|||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.join(__dirname, '../src/renderer'),
|
'@': path.join(__dirname, '../src/renderer'),
|
||||||
'vue$': 'vue/dist/vue.esm.js'
|
'vue$': 'vue/dist/vue.esm.js',
|
||||||
|
'utils': path.join(__dirname, '../src/renderer/utils')
|
||||||
},
|
},
|
||||||
extensions: ['.js', '.vue', '.json', '.css', '.node']
|
extensions: ['.js', '.vue', '.json', '.css', '.node']
|
||||||
},
|
},
|
||||||
|
@ -75,6 +75,7 @@
|
|||||||
"element-ui": "^2.0.5",
|
"element-ui": "^2.0.5",
|
||||||
"fs-extra": "^4.0.2",
|
"fs-extra": "^4.0.2",
|
||||||
"image-size": "^0.6.1",
|
"image-size": "^0.6.1",
|
||||||
|
"keycode": "^2.1.9",
|
||||||
"lodash-id": "^0.14.0",
|
"lodash-id": "^0.14.0",
|
||||||
"lowdb": "^1.0.0",
|
"lowdb": "^1.0.0",
|
||||||
"md5": "^2.2.1",
|
"md5": "^2.2.1",
|
||||||
|
@ -29,4 +29,10 @@ if (!db.has('picBed').value()) {
|
|||||||
}).write()
|
}).write()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!db.has('shortKey').value()) {
|
||||||
|
db.set('shortKey', {
|
||||||
|
upload: 'CommandOrControl+Shift+P'
|
||||||
|
}).write()
|
||||||
|
}
|
||||||
|
|
||||||
export default db
|
export default db
|
||||||
|
@ -21,6 +21,7 @@ let window
|
|||||||
let settingWindow
|
let settingWindow
|
||||||
let tray
|
let tray
|
||||||
let menu
|
let menu
|
||||||
|
let contextMenu
|
||||||
const winURL = process.env.NODE_ENV === 'development'
|
const winURL = process.env.NODE_ENV === 'development'
|
||||||
? `http://localhost:9080`
|
? `http://localhost:9080`
|
||||||
: `file://${__dirname}/index.html`
|
: `file://${__dirname}/index.html`
|
||||||
@ -39,7 +40,7 @@ const uploadFailed = () => {
|
|||||||
function createTray () {
|
function createTray () {
|
||||||
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
|
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
|
||||||
tray = new Tray(menubarPic)
|
tray = new Tray(menubarPic)
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
contextMenu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: '关于',
|
label: '关于',
|
||||||
click () {
|
click () {
|
||||||
@ -308,8 +309,9 @@ const uploadClipboardFiles = async () => {
|
|||||||
imgUrl
|
imgUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
img = await uploader(uploadImg, 'imgFromClipboard', window.webContents)
|
img = await uploader(uploadImg, 'imgFromClipboard', settingWindow.webContents)
|
||||||
if (img !== false) {
|
if (img !== false) {
|
||||||
|
if (img.length > 0) {
|
||||||
const pasteStyle = db.read().get('picBed.pasteStyle').value() || 'markdown'
|
const pasteStyle = db.read().get('picBed.pasteStyle').value() || 'markdown'
|
||||||
clipboard.writeText(pasteTemplate(pasteStyle, img[0].imgUrl))
|
clipboard.writeText(pasteTemplate(pasteStyle, img[0].imgUrl))
|
||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
@ -320,6 +322,13 @@ const uploadClipboardFiles = async () => {
|
|||||||
notification.show()
|
notification.show()
|
||||||
window.webContents.send('clipboardFiles', [])
|
window.webContents.send('clipboardFiles', [])
|
||||||
window.webContents.send('uploadFiles', img)
|
window.webContents.send('uploadFiles', img)
|
||||||
|
} else {
|
||||||
|
const notification = new Notification({
|
||||||
|
title: '上传不成功',
|
||||||
|
body: '你剪贴板最新的一条记录不是图片哦'
|
||||||
|
})
|
||||||
|
notification.show()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
uploadFailed()
|
uploadFailed()
|
||||||
}
|
}
|
||||||
@ -344,6 +353,10 @@ ipcMain.on('uploadClipboardFiles', async (evt, file) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('uploadClipboardFilesFromUploadPage', () => {
|
||||||
|
uploadClipboardFiles()
|
||||||
|
})
|
||||||
|
|
||||||
ipcMain.on('uploadChoosedFiles', async (evt, files) => {
|
ipcMain.on('uploadChoosedFiles', async (evt, files) => {
|
||||||
const imgs = await uploader(files, 'imgFromUploader', settingWindow.webContents)
|
const imgs = await uploader(files, 'imgFromUploader', settingWindow.webContents)
|
||||||
if (imgs !== false) {
|
if (imgs !== false) {
|
||||||
@ -367,6 +380,35 @@ ipcMain.on('uploadChoosedFiles', async (evt, files) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('updateShortKey', (evt, oldKey) => {
|
||||||
|
globalShortcut.unregisterAll()
|
||||||
|
for (let key in oldKey) {
|
||||||
|
globalShortcut.register(db.read().get('shortKey').value()[key], () => {
|
||||||
|
return shortKeyHash[key]()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const notification = new Notification({
|
||||||
|
title: '操作成功',
|
||||||
|
body: '你的快捷键已经修改成功'
|
||||||
|
})
|
||||||
|
notification.show()
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('updateDefaultPicBed', (evt) => {
|
||||||
|
const types = ['weibo', 'qiniu', 'tcyun', 'upyun']
|
||||||
|
let submenuItem = contextMenu.items[2].submenu.items
|
||||||
|
submenuItem.forEach((item, index) => {
|
||||||
|
const result = db.read().get('picBed.current').value() === types[index]
|
||||||
|
if (result) {
|
||||||
|
item.click() // It's a bug which can not set checked status
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const shortKeyHash = {
|
||||||
|
upload: uploadClipboardFiles
|
||||||
|
}
|
||||||
|
|
||||||
const isSecondInstance = app.makeSingleInstance(() => {
|
const isSecondInstance = app.makeSingleInstance(() => {
|
||||||
if (settingWindow) {
|
if (settingWindow) {
|
||||||
if (settingWindow.isMinimized()) {
|
if (settingWindow.isMinimized()) {
|
||||||
@ -389,7 +431,7 @@ app.on('ready', () => {
|
|||||||
createTray()
|
createTray()
|
||||||
updateChecker()
|
updateChecker()
|
||||||
|
|
||||||
globalShortcut.register('CommandOrControl+Shift+P', () => {
|
globalShortcut.register(db.read().get('shortKey.upload').value(), () => {
|
||||||
uploadClipboardFiles()
|
uploadClipboardFiles()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -63,11 +63,36 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-dialog>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import pkg from '../../../package.json'
|
import pkg from '../../../package.json'
|
||||||
|
import keyDetect from 'utils/key-binding'
|
||||||
import { remote } from 'electron'
|
import { remote } from 'electron'
|
||||||
|
import db from '../../datastore'
|
||||||
const { Menu, dialog, BrowserWindow } = remote
|
const { Menu, dialog, BrowserWindow } = remote
|
||||||
export default {
|
export default {
|
||||||
name: 'setting-page',
|
name: 'setting-page',
|
||||||
@ -77,7 +102,11 @@ export default {
|
|||||||
defaultActive: 'upload',
|
defaultActive: 'upload',
|
||||||
menu: null,
|
menu: null,
|
||||||
visible: false,
|
visible: false,
|
||||||
os: ''
|
keyBindingVisible: false,
|
||||||
|
os: '',
|
||||||
|
shortKey: {
|
||||||
|
upload: db.read().get('shortKey.upload').value()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
@ -117,6 +146,12 @@ export default {
|
|||||||
_this.visible = true
|
_this.visible = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: '修改快捷键',
|
||||||
|
click () {
|
||||||
|
_this.keyBindingVisible = true
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: '打开更新助手',
|
label: '打开更新助手',
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
@ -131,6 +166,19 @@ export default {
|
|||||||
},
|
},
|
||||||
openDialog () {
|
openDialog () {
|
||||||
this.menu.popup(remote.getCurrentWindow)
|
this.menu.popup(remote.getCurrentWindow)
|
||||||
|
},
|
||||||
|
keyDetect (type, event) {
|
||||||
|
this.shortKey[type] = keyDetect(event).join('+')
|
||||||
|
},
|
||||||
|
cancelKeyBinding () {
|
||||||
|
this.keyBindingVisible = false
|
||||||
|
this.shortKey = db.read().get('shortKey').value()
|
||||||
|
},
|
||||||
|
confirmKeyBinding () {
|
||||||
|
const oldKey = db.read().get('shortKey').value()
|
||||||
|
db.read().set('shortKey', this.shortKey).write()
|
||||||
|
this.keyBindingVisible = false
|
||||||
|
this.$electron.ipcRenderer.send('updateShortKey', oldKey)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeRouteEnter: (to, from, next) => {
|
beforeRouteEnter: (to, from, next) => {
|
||||||
@ -211,4 +259,7 @@ export default {
|
|||||||
&-title
|
&-title
|
||||||
text-align center
|
text-align center
|
||||||
color #878d99
|
color #878d99
|
||||||
|
.align-center
|
||||||
|
input
|
||||||
|
text-align center
|
||||||
</style>
|
</style>
|
38
src/renderer/utils/key-binding.js
Normal file
38
src/renderer/utils/key-binding.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import keycode from 'keycode'
|
||||||
|
|
||||||
|
const isSpecialKey = (keyCode) => {
|
||||||
|
const keyArr = [
|
||||||
|
16, // Shift
|
||||||
|
17, // Ctrl
|
||||||
|
18, // Alt
|
||||||
|
91, // Left Meta
|
||||||
|
93 // Right Meta
|
||||||
|
]
|
||||||
|
|
||||||
|
return keyArr.includes(keyCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
const keyDetect = (event) => {
|
||||||
|
const meta = process.platform === 'darwin' ? 'Cmd' : 'Super'
|
||||||
|
let specialKey = {
|
||||||
|
Ctrl: event.ctrlKey,
|
||||||
|
Shift: event.shiftKey,
|
||||||
|
Alt: event.altKey
|
||||||
|
}
|
||||||
|
specialKey[meta] = event.metaKey
|
||||||
|
|
||||||
|
let pressKey = []
|
||||||
|
|
||||||
|
for (let i in specialKey) {
|
||||||
|
if (specialKey[i]) {
|
||||||
|
pressKey.push(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isSpecialKey(event.keyCode)) {
|
||||||
|
pressKey.push(keycode(event.keyCode).toUpperCase())
|
||||||
|
}
|
||||||
|
return pressKey
|
||||||
|
}
|
||||||
|
|
||||||
|
export default keyDetect
|
@ -4884,6 +4884,10 @@ keyboardevents-areequal@^0.2.1:
|
|||||||
version "0.2.2"
|
version "0.2.2"
|
||||||
resolved "https://registry.yarnpkg.com/keyboardevents-areequal/-/keyboardevents-areequal-0.2.2.tgz#88191ec738ce9f7591c25e9056de928b40277194"
|
resolved "https://registry.yarnpkg.com/keyboardevents-areequal/-/keyboardevents-areequal-0.2.2.tgz#88191ec738ce9f7591c25e9056de928b40277194"
|
||||||
|
|
||||||
|
keycode@^2.1.9:
|
||||||
|
version "2.1.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/keycode/-/keycode-2.1.9.tgz#964a23c54e4889405b4861a5c9f0480d45141dfa"
|
||||||
|
|
||||||
keypress@0.1.x:
|
keypress@0.1.x:
|
||||||
version "0.1.0"
|
version "0.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/keypress/-/keypress-0.1.0.tgz#4a3188d4291b66b4f65edb99f806aa9ae293592a"
|
resolved "https://registry.yarnpkg.com/keypress/-/keypress-0.1.0.tgz#4a3188d4291b66b4f65edb99f806aa9ae293592a"
|
||||||
|
Loading…
Reference in New Issue
Block a user