Permalink
Browse files

Fixed: #17

  • Loading branch information...
Molunerfinn committed Jan 30, 2018
1 parent 16fe016 commit 37a784225e90c9d115367f056957dac88ebcf816
@@ -133,7 +133,8 @@ let rendererConfig = {
resolve: {
alias: {
'@': 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']
},
@@ -75,6 +75,7 @@
"element-ui": "^2.0.5",
"fs-extra": "^4.0.2",
"image-size": "^0.6.1",
"keycode": "^2.1.9",
"lodash-id": "^0.14.0",
"lowdb": "^1.0.0",
"md5": "^2.2.1",
@@ -29,4 +29,10 @@ if (!db.has('picBed').value()) {
}).write()
}
if (!db.has('shortKey').value()) {
db.set('shortKey', {
upload: 'CommandOrControl+Shift+P'
}).write()
}
export default db
@@ -21,6 +21,7 @@ let window
let settingWindow
let tray
let menu
let contextMenu
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080`
: `file://${__dirname}/index.html`
@@ -39,7 +40,7 @@ const uploadFailed = () => {
function createTray () {
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
tray = new Tray(menubarPic)
const contextMenu = Menu.buildFromTemplate([
contextMenu = Menu.buildFromTemplate([
{
label: '关于',
click () {
@@ -308,18 +309,26 @@ const uploadClipboardFiles = async () => {
imgUrl
}
}
img = await uploader(uploadImg, 'imgFromClipboard', window.webContents)
img = await uploader(uploadImg, 'imgFromClipboard', settingWindow.webContents)
if (img !== false) {
const pasteStyle = db.read().get('picBed.pasteStyle').value() || 'markdown'
clipboard.writeText(pasteTemplate(pasteStyle, img[0].imgUrl))
const notification = new Notification({
title: '上传成功',
body: img[0].imgUrl,
icon: img[0].imgUrl
})
notification.show()
window.webContents.send('clipboardFiles', [])
window.webContents.send('uploadFiles', img)
if (img.length > 0) {
const pasteStyle = db.read().get('picBed.pasteStyle').value() || 'markdown'
clipboard.writeText(pasteTemplate(pasteStyle, img[0].imgUrl))
const notification = new Notification({
title: '上传成功',
body: img[0].imgUrl,
icon: img[0].imgUrl
})
notification.show()
window.webContents.send('clipboardFiles', [])
window.webContents.send('uploadFiles', img)
} else {
const notification = new Notification({
title: '上传不成功',
body: '你剪贴板最新的一条记录不是图片哦'
})
notification.show()
}
} else {
uploadFailed()
}
@@ -344,6 +353,10 @@ ipcMain.on('uploadClipboardFiles', async (evt, file) => {
}
})
ipcMain.on('uploadClipboardFilesFromUploadPage', () => {
uploadClipboardFiles()
})
ipcMain.on('uploadChoosedFiles', async (evt, files) => {
const imgs = await uploader(files, 'imgFromUploader', settingWindow.webContents)
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(() => {
if (settingWindow) {
if (settingWindow.isMinimized()) {
@@ -389,7 +431,7 @@ app.on('ready', () => {
createTray()
updateChecker()
globalShortcut.register('CommandOrControl+Shift+P', () => {
globalShortcut.register(db.read().get('shortKey.upload').value(), () => {
uploadClipboardFiles()
})
})
@@ -63,11 +63,36 @@
</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>
</div>
</template>
<script>
import pkg from '../../../package.json'
import keyDetect from 'utils/key-binding'
import { remote } from 'electron'
import db from '../../datastore'
const { Menu, dialog, BrowserWindow } = remote
export default {
name: 'setting-page',
@@ -77,7 +102,11 @@ export default {
defaultActive: 'upload',
menu: null,
visible: false,
os: ''
keyBindingVisible: false,
os: '',
shortKey: {
upload: db.read().get('shortKey.upload').value()
}
}
},
created () {
@@ -117,6 +146,12 @@ export default {
_this.visible = true
}
},
{
label: '修改快捷键',
click () {
_this.keyBindingVisible = true
}
},
{
label: '打开更新助手',
type: 'checkbox',
@@ -131,6 +166,19 @@ export default {
},
openDialog () {
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) => {
@@ -211,4 +259,7 @@ export default {
&-title
text-align center
color #878d99
.align-center
input
text-align center
</style>
@@ -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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 37a7842

Please sign in to comment.