From 81db068971019f6588e00dc68866bdbabb58cbcb Mon Sep 17 00:00:00 2001 From: Lasy <1255352506@qq.com> Date: Fri, 27 Mar 2020 17:58:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=9C=80=E5=B0=8F=E5=8C=96?= =?UTF-8?q?=E5=88=B0=E6=89=98=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/index.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 59c46d88..383b9426 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow, Menu } = require('electron') +const { app, BrowserWindow, Menu, Tray } = require('electron') const path = require('path') // 单例应用程序 @@ -30,10 +30,10 @@ const winEvent = require('./events/winEvent') const autoUpdate = require('./utils/autoUpdate') const { isLinux, isMac } = require('../common/utils') - let mainWindow let winURL let isFirstCheckedUpdate = true +let tray if (isDev) { global.__static = path.join(__dirname, '../static') @@ -66,6 +66,32 @@ function createWindow() { }, }) + // 托盘 + tray = new Tray('./resources/icons/256x256.ico') + const contextMenu = Menu.buildFromTemplate([ + { + label: '退出', + click: () => { + mainWindow.destroy() + }, + }, + ]) + tray.setToolTip('洛雪音乐助手') + tray.setContextMenu(contextMenu) + tray.on('click', () => { + mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show() + mainWindow.isVisible() + ? mainWindow.setSkipTaskbar(false) + : mainWindow.setSkipTaskbar(true) + }) + + // 关闭事件处理 + mainWindow.on('close', e => { + e.preventDefault() + mainWindow.hide() + mainWindow.setSkipTaskbar(true) + }) + mainWindow.loadURL(winURL) winEvent(mainWindow)