Pārlūkot izejas kodu

托盘功能修改

gaoshuaixing 4 gadi atpakaļ
vecāks
revīzija
c8b451896d
5 mainītis faili ar 32 papildinājumiem un 16 dzēšanām
  1. 4 0
      electron/config.js
  2. 28 9
      electron/lib/tray.js
  3. BIN
      frontend/public/favicon.ico
  4. 0 2
      frontend/public/index.html
  5. 0 5
      main.js

+ 4 - 0
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') {

+ 28 - 9
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;
 }
 

BIN
frontend/public/favicon.ico


+ 0 - 2
frontend/public/index.html

@@ -4,7 +4,6 @@
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
-    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
     <title><%= htmlWebpackPlugin.options.title %></title>
     <style>
       /* 滚动条 */
@@ -21,6 +20,5 @@
       <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
     </noscript>
     <div id="app"></div>
-    <!-- built files will be auto injected -->
   </body>
 </html>

+ 0 - 5
main.js

@@ -5,7 +5,6 @@ const setup = require('./electron/setup')
 const electronConfig = require('./electron/config')
 const storage = require('./electron/lib/storage')
 const preferences = require('./electron/preferences')
-const pkg = require('./package.json');
 const helper = require('./electron/lib/helper');
 
 // main window
@@ -33,10 +32,6 @@ const eLogger = require('./electron/lib/eLogger').get()
 // loading html
 const loadingHtml = path.join('file://', __dirname, '/asset/loading.html')
 
-if (process.mas) {
-  app.setName(pkg.name)
-}
-
 async function initialize () {
   app.whenReady().then(() => {
     createWindow()