From 62b0c2113c0b4cc6fcad645375291feacab6d962 Mon Sep 17 00:00:00 2001 From: Molunerfinn Date: Tue, 26 Jun 2018 17:03:46 +0800 Subject: [PATCH] Fixed: tray bug on ubuntu & hide tray icon on linux --- package.json | 2 +- src/main/index.js | 34 +++++++++++++++++++++++--------- src/renderer/components/mixin.js | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index a555fe2..486260c 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "allowToChangeInstallationDirectory": true }, "linux": { - "icon": "build/icons" + "icon": "build/icons/256x256.png" } }, "dependencies": { diff --git a/src/main/index.js b/src/main/index.js index 2ca3c79..d7d5f62 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -94,7 +94,9 @@ function createTray () { } ]) tray.on('right-click', () => { - window.hide() + if (window) { + window.hide() + } tray.popUpContextMenu(contextMenu) }) tray.on('click', () => { @@ -115,7 +117,9 @@ function createTray () { window.webContents.send('clipboardFiles', obj) }, 0) } else { - window.hide() + if (window) { + window.hide() + } if (settingWindow === null) { createSettingWindow() settingWindow.show() @@ -158,6 +162,9 @@ function createTray () { } const createWindow = () => { + if (process.platform !== 'darwin' && process.platform !== 'win32') { + return + } window = new BrowserWindow({ height: 350, width: 196, // 196 @@ -181,9 +188,6 @@ const createWindow = () => { window.on('blur', () => { window.hide() }) - - createSettingWindow() - createMenu() } const createSettingWindow = () => { @@ -208,6 +212,7 @@ const createSettingWindow = () => { options.frame = false options.backgroundColor = '#3f3c37' options.transparent = false + options.icon = `${__static}/256x256.png` } settingWindow = new BrowserWindow(options) @@ -216,6 +221,7 @@ const createSettingWindow = () => { settingWindow.on('closed', () => { settingWindow = null }) + createMenu() } const createMenu = () => { @@ -378,8 +384,8 @@ ipcMain.on('updateCustomLink', (evt, oldLink) => { notification.show() }) -ipcMain.on('updteDefaultPicBed', (evt) => { - const types = ['weibo', 'qiniu', 'tcyun', 'upyun'] +ipcMain.on('updateDefaultPicBed', (evt) => { + 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] @@ -416,9 +422,16 @@ if (process.platform === 'win32') { app.setAppUserModelId(pkg.build.appId) } +if (process.env.XDG_CURRENT_DESKTOP && process.env.XDG_CURRENT_DESKTOP.includes('Unity')) { + process.env.XDG_CURRENT_DESKTOP = 'Unity' +} + app.on('ready', () => { createWindow() - createTray() + createSettingWindow() + if (process.platform === 'darwin' || process.platform === 'win32') { + createTray() + } updateChecker() globalShortcut.register(db.read().get('shortKey.upload').value(), () => { @@ -433,9 +446,12 @@ app.on('window-all-closed', () => { }) app.on('activate', () => { - if (window === null || settingWindow === null) { + if (window === null) { createWindow() } + if (settingWindow === null) { + createSettingWindow() + } }) app.on('will-quit', () => { diff --git a/src/renderer/components/mixin.js b/src/renderer/components/mixin.js index 295c009..dc7343f 100644 --- a/src/renderer/components/mixin.js +++ b/src/renderer/components/mixin.js @@ -25,7 +25,7 @@ export default { setDefaultPicBed (type) { db.read().set('picBed.current', type).write() this.defaultPicBed = type - this.$electron.ipcRenderer.send('updateDefaultPicBed') + this.$electron.ipcRenderer.send('updateDefaultPicBed', type) const successNotification = new window.Notification('设置默认图床', { body: '设置成功' })