diff --git a/electron/config.js b/electron/config.js index 227c6ca..4ad0f98 100644 --- a/electron/config.js +++ b/electron/config.js @@ -76,6 +76,10 @@ const config = { enable: false, url: 'https://discuz.chat/' // Any web url }, + tray: { + title: 'EE程序', // 托盘显示标题 + icon: '/asset/images/tray_logo.png' // 托盘图标 + } } exports.get = function (flag = '', env = 'prod') { diff --git a/electron/lib/tray.js b/electron/lib/tray.js index c2cfaf9..7a4b23a 100644 --- a/electron/lib/tray.js +++ b/electron/lib/tray.js @@ -2,10 +2,32 @@ const {app, Tray, Menu} = require('electron'); const path = require('path'); -const pkg = require('../../package.json'); const helper = require('./helper'); +const config = require('../config'); exports.setup = function () { + const cfg = config.get('tray'); + + // 托盘图标 + let iconPath = path.join(app.getAppPath(), cfg.icon); + + // 托盘菜单功能列表 + let trayMenuTemplate = [ + { + label: '显示', + click: function () { + MAIN_WINDOW.show(); + } + }, + { + label: '退出', + click: function () { + helper.appQuit(); + } + } + ] + + // 点击关闭,最小化到托盘 MAIN_WINDOW.on('close', (event) => { if (!CAN_QUIT) { MAIN_WINDOW.hide(); @@ -14,17 +36,13 @@ exports.setup = function () { } }); MAIN_WINDOW.show(); - let trayMenuTemplate = [{ - label: '退出', - click: function () { - helper.appQuit(); - } - }] - let iconPath = path.join(app.getAppPath(), '/asset/images/tray_logo.png'); + APP_TRAY = new Tray(iconPath); + APP_TRAY.setToolTip(cfg.title); // 托盘标题 const contextMenu = Menu.buildFromTemplate(trayMenuTemplate); - APP_TRAY.setToolTip(pkg.name); APP_TRAY.setContextMenu(contextMenu); + + // 监听 显示/隐藏 APP_TRAY.on('click', function(){ if (MAIN_WINDOW.isVisible()) { MAIN_WINDOW.hide(); @@ -34,6 +52,7 @@ exports.setup = function () { MAIN_WINDOW.setSkipTaskbar(true); } }); + return APP_TRAY; } diff --git a/frontend/public/favicon.ico b/frontend/public/favicon.ico deleted file mode 100644 index df36fcf..0000000 Binary files a/frontend/public/favicon.ico and /dev/null differ diff --git a/frontend/public/index.html b/frontend/public/index.html index 479f39f..c0d5817 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -4,7 +4,6 @@ - <%= htmlWebpackPlugin.options.title %>