|
@@ -2,10 +2,32 @@
|
|
|
|
|
|
|
|
const {app, Tray, Menu} = require('electron');
|
|
const {app, Tray, Menu} = require('electron');
|
|
|
const path = require('path');
|
|
const path = require('path');
|
|
|
-const pkg = require('../../package.json');
|
|
|
|
|
const helper = require('./helper');
|
|
const helper = require('./helper');
|
|
|
|
|
+const config = require('../config');
|
|
|
|
|
|
|
|
exports.setup = function () {
|
|
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) => {
|
|
MAIN_WINDOW.on('close', (event) => {
|
|
|
if (!CAN_QUIT) {
|
|
if (!CAN_QUIT) {
|
|
|
MAIN_WINDOW.hide();
|
|
MAIN_WINDOW.hide();
|
|
@@ -14,17 +36,13 @@ exports.setup = function () {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
MAIN_WINDOW.show();
|
|
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 = new Tray(iconPath);
|
|
|
|
|
+ APP_TRAY.setToolTip(cfg.title); // 托盘标题
|
|
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate);
|
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate);
|
|
|
- APP_TRAY.setToolTip(pkg.name);
|
|
|
|
|
APP_TRAY.setContextMenu(contextMenu);
|
|
APP_TRAY.setContextMenu(contextMenu);
|
|
|
|
|
+
|
|
|
|
|
+ // 监听 显示/隐藏
|
|
|
APP_TRAY.on('click', function(){
|
|
APP_TRAY.on('click', function(){
|
|
|
if (MAIN_WINDOW.isVisible()) {
|
|
if (MAIN_WINDOW.isVisible()) {
|
|
|
MAIN_WINDOW.hide();
|
|
MAIN_WINDOW.hide();
|
|
@@ -34,6 +52,7 @@ exports.setup = function () {
|
|
|
MAIN_WINDOW.setSkipTaskbar(true);
|
|
MAIN_WINDOW.setSkipTaskbar(true);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
return APP_TRAY;
|
|
return APP_TRAY;
|
|
|
}
|
|
}
|
|
|
|
|
|