将托盘挂到全局变量中
parent
36d140d4bd
commit
afc81b6308
|
@ -9,19 +9,18 @@ global.lx_event.tray.on(TRAY_EVENT_NAME.destroy, () => {
|
||||||
destroyTray()
|
destroyTray()
|
||||||
})
|
})
|
||||||
|
|
||||||
let tray
|
|
||||||
const createTray = () => {
|
const createTray = () => {
|
||||||
if ((tray && !tray.isDestroyed()) || !global.appSetting.tray || !global.appSetting.tray.isShow) return
|
if ((global.tray && !global.tray.isDestroyed()) || !global.appSetting.tray || !global.appSetting.tray.isShow) return
|
||||||
|
|
||||||
const iconPath = path.join(global.__static, 'images/tray', isWin ? 'trayTemplate.ico' : 'trayTemplate.png')
|
const iconPath = path.join(global.__static, 'images/tray', isWin ? 'trayTemplate.ico' : 'trayTemplate.png')
|
||||||
|
|
||||||
// 托盘
|
// 托盘
|
||||||
tray = new Tray(iconPath)
|
global.tray = new Tray(iconPath)
|
||||||
|
|
||||||
tray.setToolTip('洛雪音乐助手')
|
global.tray.setToolTip('洛雪音乐助手')
|
||||||
if (isWin) createMenu(tray)
|
if (isWin) createMenu(global.tray)
|
||||||
tray.setIgnoreDoubleClickEvents(true)
|
global.tray.setIgnoreDoubleClickEvents(true)
|
||||||
tray.on('click', () => {
|
global.tray.on('click', () => {
|
||||||
const mainWindow = global.mainWindow
|
const mainWindow = global.mainWindow
|
||||||
if (!mainWindow) return
|
if (!mainWindow) return
|
||||||
mainWindow.isVisible()
|
mainWindow.isVisible()
|
||||||
|
@ -31,9 +30,9 @@ const createTray = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const destroyTray = () => {
|
const destroyTray = () => {
|
||||||
if (!tray) return
|
if (!global.tray) return
|
||||||
tray.destroy()
|
global.tray.destroy()
|
||||||
tray = null
|
global.tray = null
|
||||||
}
|
}
|
||||||
|
|
||||||
const createMenu = tray => {
|
const createMenu = tray => {
|
||||||
|
|
Loading…
Reference in New Issue