diff --git a/README.md b/README.md
index 45184796..6e11158d 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
[![star](https://gitee.com/dromara/electron-egg/badge/star.svg?theme=gvp)](https://gitee.com/dromara/electron-egg/stargazers)
-
🎉🎉🎉 ElectronEgg V3.10.0已发布! 🎉🎉🎉
+🎉🎉🎉 ElectronEgg V3.11.0已发布! 🎉🎉🎉
@@ -22,7 +22,7 @@
- 🍩 **为什么使用?** 桌面软件(办公方向、 个人工具),仍然是未来十几年PC端需求之一,提高工作效率
- 🍉 **简单:** 只需懂 JavaScript
- 🍑 **愿景:** 所有开发者都能学会桌面软件研发
-- 🍰 **gitee:** https://gitee.com/dromara/electron-egg **4300+**
+- 🍰 **gitee:** https://gitee.com/dromara/electron-egg **4400+**
- 🍨 **github:** https://github.com/dromara/electron-egg **1400+**
- 🏆 码云最有价值开源项目
![](https://wallace5303.gitee.io/ee/images/electron-egg/ee-zs.png)
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 45184796..6e11158d 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -1,7 +1,7 @@
[![star](https://gitee.com/dromara/electron-egg/badge/star.svg?theme=gvp)](https://gitee.com/dromara/electron-egg/stargazers)
-
🎉🎉🎉 ElectronEgg V3.10.0已发布! 🎉🎉🎉
+🎉🎉🎉 ElectronEgg V3.11.0已发布! 🎉🎉🎉
@@ -22,7 +22,7 @@
- 🍩 **为什么使用?** 桌面软件(办公方向、 个人工具),仍然是未来十几年PC端需求之一,提高工作效率
- 🍉 **简单:** 只需懂 JavaScript
- 🍑 **愿景:** 所有开发者都能学会桌面软件研发
-- 🍰 **gitee:** https://gitee.com/dromara/electron-egg **4300+**
+- 🍰 **gitee:** https://gitee.com/dromara/electron-egg **4400+**
- 🍨 **github:** https://github.com/dromara/electron-egg **1400+**
- 🏆 码云最有价值开源项目
![](https://wallace5303.gitee.io/ee/images/electron-egg/ee-zs.png)
diff --git a/electron/addon/autoUpdater/index.js b/electron/addon/autoUpdater/index.js
index 2ab4cf39..e62a1184 100644
--- a/electron/addon/autoUpdater/index.js
+++ b/electron/addon/autoUpdater/index.js
@@ -1,165 +1,73 @@
-const { app: electronApp } = require('electron');
-const { autoUpdater } = require("electron-updater");
-const is = require('ee-core/utils/is');
+const { Tray, Menu } = require('electron');
+const path = require('path');
+const Ps = require('ee-core/ps');
const Log = require('ee-core/log');
-const Conf = require('ee-core/config');
+const Electron = require('ee-core/electron');
const CoreWindow = require('ee-core/electron/window');
+const Conf = require('ee-core/config');
+const EE = require('ee-core/ee');
/**
- * 自动升级插件
+ * 托盘插件
* @class
*/
-class AutoUpdaterAddon {
+class TrayAddon {
constructor() {
+ this.tray = null;
}
/**
- * 创建
+ * 创建托盘
*/
create () {
- Log.info('[addon:autoUpdater] load');
- const cfg = Conf.getValue('addons.autoUpdater');
- if ((is.windows() && cfg.windows)
- || (is.macOS() && cfg.macOS)
- || (is.linux() && cfg.linux))
- {
- // continue
- } else {
- return
- }
-
- // 是否检查更新
- if (cfg.force) {
- this.checkUpdate();
- }
-
- const status = {
- error: -1,
- available: 1,
- noAvailable: 2,
- downloading: 3,
- downloaded: 4,
- }
+ // 开发环境,代码热更新开启时,会导致托盘中有残影
+ if (Ps.isDev() && Ps.isHotReload()) return;
+
+ Log.info('[addon:tray] load');
+ const { CoreApp } = EE;
+ const cfg = Conf.getValue('addons.tray');
+ const mainWindow = CoreWindow.getMainWindow();
- const version = electronApp.getVersion();
- Log.info('[addon:autoUpdater] current version: ', version);
+ // 托盘图标
+ let iconPath = path.join(Ps.getHomeDir(), cfg.icon);
- // 设置下载服务器地址
- let server = cfg.options.url;
- let lastChar = server.substring(server.length - 1);
- server = lastChar === '/' ? server : server + "/";
- //Log.info('[addon:autoUpdater] server: ', server);
- cfg.options.url = server;
-
- // 是否后台自动下载
- autoUpdater.autoDownload = cfg.force ? true : false;
-
- try {
- autoUpdater.setFeedURL(cfg.options);
- } catch (error) {
- Log.error('[addon:autoUpdater] setFeedURL error : ', error);
- }
-
- autoUpdater.on('checking-for-update', () => {
- //sendStatusToWindow('正在检查更新...');
- })
- autoUpdater.on('update-available', (info) => {
- info.status = status.available;
- info.desc = '有可用更新';
- this.sendStatusToWindow(info);
- })
- autoUpdater.on('update-not-available', (info) => {
- info.status = status.noAvailable;
- info.desc = '没有可用更新';
- this.sendStatusToWindow(info);
- })
- autoUpdater.on('error', (err) => {
- let info = {
- status: status.error,
- desc: err
+ // 托盘菜单功能列表
+ let trayMenuTemplate = [
+ {
+ label: '显示',
+ click: function () {
+ mainWindow.show();
+ }
+ },
+ {
+ label: '退出',
+ click: function () {
+ CoreApp.appQuit();
+ }
}
- this.sendStatusToWindow(info);
- })
- autoUpdater.on('download-progress', (progressObj) => {
- let percentNumber = parseInt(progressObj.percent);
- let totalSize = this.bytesChange(progressObj.total);
- let transferredSize = this.bytesChange(progressObj.transferred);
- let text = '已下载 ' + percentNumber + '%';
- text = text + ' (' + transferredSize + "/" + totalSize + ')';
+ ]
- let info = {
- status: status.downloading,
- desc: text,
- percentNumber: percentNumber,
- totalSize: totalSize,
- transferredSize: transferredSize
+ // 点击关闭,最小化到托盘
+ mainWindow.on('close', (event) => {
+ if (Electron.extra.closeWindow == true) {
+ return;
}
- Log.info('[addon:autoUpdater] progress: ', text);
- this.sendStatusToWindow(info);
- })
- autoUpdater.on('update-downloaded', (info) => {
- info.status = status.downloaded;
- info.desc = '下载完成';
- this.sendStatusToWindow(info);
- autoUpdater.quitAndInstall();
- // const mainWindow = CoreWindow.getMainWindow();
- // if (mainWindow) {
- // mainWindow.destroy()
- // }
- // electronApp.appQuit()
+ mainWindow.hide();
+ event.preventDefault();
});
+
+ // 实例化托盘
+ this.tray = new Tray(iconPath);
+ this.tray.setToolTip(cfg.title);
+ const contextMenu = Menu.buildFromTemplate(trayMenuTemplate);
+ this.tray.setContextMenu(contextMenu);
+ // 左键单击的时候能够显示主窗口
+ this.tray.on('click', () => {
+ mainWindow.show()
+ })
}
-
- /**
- * 检查更新
- */
- checkUpdate () {
- autoUpdater.checkForUpdates();
- }
-
- /**
- * 下载更新
- */
- download () {
- autoUpdater.downloadUpdate();
- }
-
- /**
- * 向前端发消息
- */
- sendStatusToWindow(content = {}) {
- const textJson = JSON.stringify(content);
- const channel = 'app.updater';
- const win = CoreWindow.getMainWindow();
- win.webContents.send(channel, textJson);
- }
-
- /**
- * 单位转换
- */
- bytesChange (limit) {
- let size = "";
- if(limit < 0.1 * 1024){
- size = limit.toFixed(2) + "B";
- }else if(limit < 0.1 * 1024 * 1024){
- size = (limit/1024).toFixed(2) + "KB";
- }else if(limit < 0.1 * 1024 * 1024 * 1024){
- size = (limit/(1024 * 1024)).toFixed(2) + "MB";
- }else{
- size = (limit/(1024 * 1024 * 1024)).toFixed(2) + "GB";
- }
-
- let sizeStr = size + "";
- let index = sizeStr.indexOf(".");
- let dou = sizeStr.substring(index + 1 , index + 3);
- if(dou == "00"){
- return sizeStr.substring(0, index) + sizeStr.substring(index + 3, index + 5);
- }
-
- return size;
- }
}
-AutoUpdaterAddon.toString = () => '[class AutoUpdaterAddon]';
-module.exports = AutoUpdaterAddon;
\ No newline at end of file
+TrayAddon.toString = () => '[class TrayAddon]';
+module.exports = TrayAddon;
\ No newline at end of file
diff --git a/electron/config/bin.js b/electron/config/bin.js
index eac4fa78..d377caa4 100644
--- a/electron/config/bin.js
+++ b/electron/config/bin.js
@@ -21,6 +21,7 @@ module.exports = {
directory: './',
cmd: 'electron',
args: ['.', '--env=local'],
+ loadingPage: '/public/html/loading.html',
}
},
diff --git a/electron/config/config.default.js b/electron/config/config.default.js
index 833dd6dd..f69287f4 100644
--- a/electron/config/config.default.js
+++ b/electron/config/config.default.js
@@ -114,15 +114,13 @@ module.exports = (appInfo) => {
config.mainServer = {
protocol: 'file://',
indexPath: '/public/dist/index.html',
- host: '127.0.0.1',
- port: 7072,
};
/**
* 硬件加速
*/
config.hardGpu = {
- enable: false
+ enable: true
};
/**
diff --git a/electron/preload/index.js b/electron/preload/index.js
index 63ea9945..36d8349c 100644
--- a/electron/preload/index.js
+++ b/electron/preload/index.js
@@ -11,6 +11,4 @@ module.exports = async () => {
// 示例功能模块,可选择性使用和修改
Addon.get('tray').create();
Addon.get('security').create();
- Addon.get('awaken').create();
- Addon.get('autoUpdater').create();
}
\ No newline at end of file
diff --git a/package.json b/package.json
index 934043bc..d9614ad7 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "ee",
- "version": "3.10.0",
+ "version": "3.11.0",
"description": "A fast, desktop software development framework",
"main": "main.js",
"scripts": {
@@ -46,7 +46,7 @@
"devDependencies": {
"@electron/rebuild": "^3.2.13",
"debug": "^4.3.3",
- "ee-bin": "^1.4.0",
+ "ee-bin": "^1.5.0",
"electron": "^21.4.4",
"electron-builder": "^23.6.0",
"eslint": "^5.13.0",
@@ -55,7 +55,7 @@
},
"dependencies": {
"dayjs": "^1.10.7",
- "ee-core": "^2.8.1",
+ "ee-core": "^2.9.2",
"electron-updater": "^5.3.0",
"lodash": "^4.17.21"
}