Finished: dynamic sync default picbed in menu

This commit is contained in:
Molunerfinn
2018-12-25 16:11:10 +08:00
parent 51cea7cdf0
commit 60ccd10e1a
4 changed files with 12 additions and 42 deletions
+8 -26
View File
@@ -35,9 +35,7 @@ const miniWinURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080/#mini-page` ? `http://localhost:9080/#mini-page`
: `file://${__dirname}/index.html#mini-page` : `file://${__dirname}/index.html#mini-page`
function createTray () { function createContextMenu () {
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
tray = new Tray(menubarPic)
const picBeds = getPicBeds(app) const picBeds = getPicBeds(app)
const submenu = picBeds.map(item => { const submenu = picBeds.map(item => {
return { return {
@@ -97,10 +95,16 @@ function createTray () {
label: '退出' label: '退出'
} }
]) ])
}
function createTray () {
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
tray = new Tray(menubarPic)
tray.on('right-click', () => { tray.on('right-click', () => {
if (window) { if (window) {
window.hide() window.hide()
} }
createContextMenu()
tray.popUpContextMenu(contextMenu) tray.popUpContextMenu(contextMenu)
}) })
tray.on('click', (event, bounds) => { tray.on('click', (event, bounds) => {
@@ -353,23 +357,6 @@ const uploadClipboardFiles = async () => {
} }
} }
const updateDefaultPicBed = () => {
if (process.platform === 'darwin' || process.platform === 'win32') {
const picBeds = getPicBeds(app)
const types = picBeds.map(item => item.type)
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
return true
}
})
} else {
return false
}
}
picgoCoreIPC(app, ipcMain) picgoCoreIPC(app, ipcMain)
ipcMain.on('uploadClipboardFiles', async (evt, file) => { ipcMain.on('uploadClipboardFiles', async (evt, file) => {
@@ -473,22 +460,17 @@ ipcMain.on('openMiniWindow', (evt) => {
settingWindow.hide() settingWindow.hide()
}) })
// update
ipcMain.on('updateDefaultPicBed', (evt) => {
updateDefaultPicBed()
})
// from mini window // from mini window
ipcMain.on('syncPicBed', (evt) => { ipcMain.on('syncPicBed', (evt) => {
if (settingWindow) { if (settingWindow) {
settingWindow.webContents.send('syncPicBed') settingWindow.webContents.send('syncPicBed')
} }
updateDefaultPicBed()
}) })
ipcMain.on('getPicBeds', (evt) => { ipcMain.on('getPicBeds', (evt) => {
const picBeds = getPicBeds(app) const picBeds = getPicBeds(app)
evt.sender.send('getPicBeds', picBeds) evt.sender.send('getPicBeds', picBeds)
evt.returnValue = picBeds
}) })
const shortKeyHash = { const shortKeyHash = {
+4 -14
View File
@@ -48,8 +48,7 @@ export default {
this.showError = true this.showError = true
} }
}) })
this.$electron.ipcRenderer.send('getPicBeds') this.getPicBeds()
this.$electron.ipcRenderer.on('getPicBeds', this.getPicBeds)
}, },
mounted () { mounted () {
window.addEventListener('mousedown', this.handleMouseDown, false) window.addEventListener('mousedown', this.handleMouseDown, false)
@@ -70,8 +69,8 @@ export default {
} }
}, },
methods: { methods: {
getPicBeds (event, picBeds) { getPicBeds () {
this.picBed = picBeds this.picBed = this.$electron.ipcRenderer.sendSync('getPicBeds')
this.buildMenu() this.buildMenu()
}, },
onDrop (e) { onDrop (e) {
@@ -123,16 +122,7 @@ export default {
if (e.button === 0) { // left mouse if (e.button === 0) { // left mouse
this.openUploadWindow() this.openUploadWindow()
} else { } else {
let _this = this this.getPicBeds()
const types = this.picBed.map(item => item.type)
let submenuItem = this.menu.items[1].submenu.items
submenuItem.forEach((item, index) => {
const result = _this.$db.read().get('picBed.current').value() === types[index]
if (result) {
item.click()
return true
}
})
this.openContextMenu() this.openContextMenu()
} }
} }
-1
View File
@@ -64,7 +64,6 @@ export default {
setDefaultPicBed (type) { setDefaultPicBed (type) {
this.$db.read().set('picBed.current', type).write() this.$db.read().set('picBed.current', type).write()
this.defaultPicBed = type this.defaultPicBed = type
this.$electron.ipcRenderer.send('updateDefaultPicBed', type)
const successNotification = new window.Notification('设置默认图床', { const successNotification = new window.Notification('设置默认图床', {
body: '设置成功' body: '设置成功'
}) })
-1
View File
@@ -9,7 +9,6 @@ export default {
setDefaultPicBed (type) { setDefaultPicBed (type) {
this.$db.read().set('picBed.current', type).write() this.$db.read().set('picBed.current', type).write()
this.defaultPicBed = type this.defaultPicBed = type
this.$electron.ipcRenderer.send('updateDefaultPicBed', type)
const successNotification = new window.Notification('设置默认图床', { const successNotification = new window.Notification('设置默认图床', {
body: '设置成功' body: '设置成功'
}) })