Fixed: tray bug on ubuntu & hide tray icon on linux

This commit is contained in:
Molunerfinn 2018-06-26 17:03:46 +08:00
parent ed187f4438
commit 62b0c2113c
3 changed files with 27 additions and 11 deletions

View File

@ -67,7 +67,7 @@
"allowToChangeInstallationDirectory": true "allowToChangeInstallationDirectory": true
}, },
"linux": { "linux": {
"icon": "build/icons" "icon": "build/icons/256x256.png"
} }
}, },
"dependencies": { "dependencies": {

View File

@ -94,7 +94,9 @@ function createTray () {
} }
]) ])
tray.on('right-click', () => { tray.on('right-click', () => {
window.hide() if (window) {
window.hide()
}
tray.popUpContextMenu(contextMenu) tray.popUpContextMenu(contextMenu)
}) })
tray.on('click', () => { tray.on('click', () => {
@ -115,7 +117,9 @@ function createTray () {
window.webContents.send('clipboardFiles', obj) window.webContents.send('clipboardFiles', obj)
}, 0) }, 0)
} else { } else {
window.hide() if (window) {
window.hide()
}
if (settingWindow === null) { if (settingWindow === null) {
createSettingWindow() createSettingWindow()
settingWindow.show() settingWindow.show()
@ -158,6 +162,9 @@ function createTray () {
} }
const createWindow = () => { const createWindow = () => {
if (process.platform !== 'darwin' && process.platform !== 'win32') {
return
}
window = new BrowserWindow({ window = new BrowserWindow({
height: 350, height: 350,
width: 196, // 196 width: 196, // 196
@ -181,9 +188,6 @@ const createWindow = () => {
window.on('blur', () => { window.on('blur', () => {
window.hide() window.hide()
}) })
createSettingWindow()
createMenu()
} }
const createSettingWindow = () => { const createSettingWindow = () => {
@ -208,6 +212,7 @@ const createSettingWindow = () => {
options.frame = false options.frame = false
options.backgroundColor = '#3f3c37' options.backgroundColor = '#3f3c37'
options.transparent = false options.transparent = false
options.icon = `${__static}/256x256.png`
} }
settingWindow = new BrowserWindow(options) settingWindow = new BrowserWindow(options)
@ -216,6 +221,7 @@ const createSettingWindow = () => {
settingWindow.on('closed', () => { settingWindow.on('closed', () => {
settingWindow = null settingWindow = null
}) })
createMenu()
} }
const createMenu = () => { const createMenu = () => {
@ -378,8 +384,8 @@ ipcMain.on('updateCustomLink', (evt, oldLink) => {
notification.show() notification.show()
}) })
ipcMain.on('updteDefaultPicBed', (evt) => { ipcMain.on('updateDefaultPicBed', (evt) => {
const types = ['weibo', 'qiniu', 'tcyun', 'upyun'] const types = picBed.map(item => item.type)
let submenuItem = contextMenu.items[2].submenu.items let submenuItem = contextMenu.items[2].submenu.items
submenuItem.forEach((item, index) => { submenuItem.forEach((item, index) => {
const result = db.read().get('picBed.current').value() === types[index] const result = db.read().get('picBed.current').value() === types[index]
@ -416,9 +422,16 @@ if (process.platform === 'win32') {
app.setAppUserModelId(pkg.build.appId) 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', () => { app.on('ready', () => {
createWindow() createWindow()
createTray() createSettingWindow()
if (process.platform === 'darwin' || process.platform === 'win32') {
createTray()
}
updateChecker() updateChecker()
globalShortcut.register(db.read().get('shortKey.upload').value(), () => { globalShortcut.register(db.read().get('shortKey.upload').value(), () => {
@ -433,9 +446,12 @@ app.on('window-all-closed', () => {
}) })
app.on('activate', () => { app.on('activate', () => {
if (window === null || settingWindow === null) { if (window === null) {
createWindow() createWindow()
} }
if (settingWindow === null) {
createSettingWindow()
}
}) })
app.on('will-quit', () => { app.on('will-quit', () => {

View File

@ -25,7 +25,7 @@ export default {
setDefaultPicBed (type) { setDefaultPicBed (type) {
db.read().set('picBed.current', type).write() db.read().set('picBed.current', type).write()
this.defaultPicBed = type this.defaultPicBed = type
this.$electron.ipcRenderer.send('updateDefaultPicBed') this.$electron.ipcRenderer.send('updateDefaultPicBed', type)
const successNotification = new window.Notification('设置默认图床', { const successNotification = new window.Notification('设置默认图床', {
body: '设置成功' body: '设置成功'
}) })