From f48021d92858780c230642c73f97adadc2654201 Mon Sep 17 00:00:00 2001 From: Molunerfinn Date: Tue, 10 Jul 2018 22:37:29 +0800 Subject: [PATCH] Fixed: sync picbed status --- src/main/index.js | 47 +++++++++++++------ src/renderer/components/MiniPage.vue | 27 +++++++++++ .../components/SettingView/Upload.vue | 4 ++ 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index b4c4e04b..65e7b441 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -52,6 +52,9 @@ function createTray () { checked: db.read().get('picBed.current').value() === item.type, click () { db.read().set('picBed.current', item.type).write() + if (settingWindow) { + settingWindow.webContents.send('syncPicBed') + } } } }) @@ -354,6 +357,22 @@ const uploadClipboardFiles = async () => { } } +const updateDefaultPicBed = () => { + if (process.platform === 'darwin' || process.platform === 'win32') { + const types = picBed.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 + } +} + ipcMain.on('uploadClipboardFiles', async (evt, file) => { const img = await uploader(file, 'imgFromClipboard', window.webContents) if (img !== false) { @@ -422,21 +441,6 @@ ipcMain.on('updateCustomLink', (evt, oldLink) => { notification.show() }) -ipcMain.on('updateDefaultPicBed', (evt) => { - if (process.platform === 'darwin' || process.platform === 'win32') { - const types = picBed.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 - } - }) - } else { - return false - } -}) - ipcMain.on('autoStart', (evt, val) => { app.setLoginItemSettings({ openAtLogin: val @@ -461,6 +465,19 @@ ipcMain.on('openMiniWindow', (evt) => { settingWindow.hide() }) +// update +ipcMain.on('updateDefaultPicBed', (evt) => { + updateDefaultPicBed() +}) + +// from mini window +ipcMain.on('syncPicBed', (evt) => { + if (settingWindow) { + settingWindow.webContents.send('syncPicBed') + } + updateDefaultPicBed() +}) + const shortKeyHash = { upload: uploadClipboardFiles } diff --git a/src/renderer/components/MiniPage.vue b/src/renderer/components/MiniPage.vue index efefc1c5..7d256beb 100644 --- a/src/renderer/components/MiniPage.vue +++ b/src/renderer/components/MiniPage.vue @@ -16,6 +16,7 @@