From c8b451896dc601ec04d23851f46f182c326c70c0 Mon Sep 17 00:00:00 2001 From: gaoshuaixing <530353222@qq.com> Date: Tue, 28 Sep 2021 20:27:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=98=E7=9B=98=E5=8A=9F=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/config.js | 4 ++++ electron/lib/tray.js | 37 +++++++++++++++++++++++++++--------- frontend/public/favicon.ico | Bin 4286 -> 0 bytes frontend/public/index.html | 2 -- main.js | 5 ----- 5 files changed, 32 insertions(+), 16 deletions(-) delete mode 100644 frontend/public/favicon.ico 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 df36fcfb72584e00488330b560ebcf34a41c64c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmds*O-Phc6o&64GDVCEQHxsW(p4>LW*W<827=Unuo8sGpRux(DN@jWP-e29Wl%wj zY84_aq9}^Am9-cWTD5GGEo#+5Fi2wX_P*bo+xO!)p*7B;iKlbFd(U~_d(U?#hLj56 zPhFkj-|A6~Qk#@g^#D^U0XT1cu=c-vu1+SElX9NR;kzAUV(q0|dl0|%h|dI$%VICy zJnu2^L*Te9JrJMGh%-P79CL0}dq92RGU6gI{v2~|)p}sG5x0U*z<8U;Ij*hB9z?ei z@g6Xq-pDoPl=MANPiR7%172VA%r)kevtV-_5H*QJKFmd;8yA$98zCxBZYXTNZ#QFk2(TX0;Y2dt&WitL#$96|gJY=3xX zpCoi|YNzgO3R`f@IiEeSmKrPSf#h#Qd<$%Ej^RIeeYfsxhPMOG`S`Pz8q``=511zm zAm)MX5AV^5xIWPyEu7u>qYs?pn$I4nL9J!=K=SGlKLXpE<5x+2cDTXq?brj?n6sp= zphe9;_JHf40^9~}9i08r{XM$7HB!`{Ys~TK0kx<}ZQng`UPvH*11|q7&l9?@FQz;8 zx!=3<4seY*%=OlbCbcae?5^V_}*K>Uo6ZWV8mTyE^B=DKy7-sdLYkR5Z?paTgK-zyIkKjIcpyO z{+uIt&YSa_$QnN_@t~L014dyK(fOOo+W*MIxbA6Ndgr=Y!f#Tokqv}n<7-9qfHkc3 z=>a|HWqcX8fzQCT=dqVbogRq!-S>H%yA{1w#2Pn;=e>JiEj7Hl;zdt-2f+j2%DeVD zsW0Ab)ZK@0cIW%W7z}H{&~yGhn~D;aiP4=;m-HCo`BEI+Kd6 z={Xwx{TKxD#iCLfl2vQGDitKtN>z|-AdCN|$jTFDg0m3O`WLD4_s#$S 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 %>