diff --git a/electron/addon/autoUpdater/index.js b/electron/addon/autoUpdater/index.js index 005e2ad..4f9a59e 100644 --- a/electron/addon/autoUpdater/index.js +++ b/electron/addon/autoUpdater/index.js @@ -3,7 +3,7 @@ const { autoUpdater } = require("electron-updater"); const is = require('ee-core/utils/is'); 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'); /** * 自动升级插件 @@ -11,8 +11,7 @@ const Electron = require('ee-core/electron'); */ class AutoUpdaterAddon { - constructor(app) { - this.app = app; + constructor() { } /** @@ -20,8 +19,6 @@ class AutoUpdaterAddon { */ create () { Log.info('[addon:autoUpdater] load'); - - // const app = this.app; const cfg = Conf.getValue('addons.autoUpdater'); if ((is.windows() && cfg.windows) || (is.macOS() && cfg.macOS) @@ -131,7 +128,8 @@ class AutoUpdaterAddon { sendStatusToWindow(content = {}) { const textJson = JSON.stringify(content); const channel = 'app.updater'; - Electron.mainWindow.webContents.send(channel, textJson); + const win = CoreWindow.getMainWindow(); + win.webContents.send(channel, textJson); } /** diff --git a/electron/addon/awaken/index.js b/electron/addon/awaken/index.js index 3a05f5b..e4c8a35 100644 --- a/electron/addon/awaken/index.js +++ b/electron/addon/awaken/index.js @@ -8,8 +8,7 @@ const Conf = require('ee-core/config'); */ class AwakenAddon { - constructor(app) { - this.app = app; + constructor() { this.protocol = ''; } @@ -24,17 +23,16 @@ class AwakenAddon { electronApp.setAsDefaultProtocolClient(this.protocol); - const self = this; this.handleArgv(process.argv); electronApp.on('second-instance', (event, argv) => { if (process.platform === 'win32') { - self.handleArgv(argv) + this.handleArgv(argv) } }) // 仅用于macOS electronApp.on('open-url', (event, urlStr) => { - self.handleUrl(urlStr) + this.handleUrl(urlStr) }) } diff --git a/electron/addon/chromeExtension/index.js b/electron/addon/chromeExtension/index.js index 3f88dc6..28ec636 100644 --- a/electron/addon/chromeExtension/index.js +++ b/electron/addon/chromeExtension/index.js @@ -5,13 +5,12 @@ const path = require('path'); const Log = require('ee-core/log'); /** - * 安全插件 + * 扩展插件 (electron自身对该功能并不完全支持,官方也不建议使用) * @class */ class ChromeExtensionAddon { - constructor(app) { - this.app = app; + constructor() { } /** diff --git a/electron/addon/javaServer/index.js b/electron/addon/javaServer/index.js index b60545f..eca6063 100644 --- a/electron/addon/javaServer/index.js +++ b/electron/addon/javaServer/index.js @@ -10,8 +10,7 @@ const GetPort = require('ee-core/utils/get-port'); */ class JavaServerAddon { - constructor(app) { - this.app = app; + constructor() { this.cfg; this.javaServer; } diff --git a/electron/addon/security/index.js b/electron/addon/security/index.js index d19e670..4d87e94 100644 --- a/electron/addon/security/index.js +++ b/electron/addon/security/index.js @@ -1,4 +1,5 @@ const Log = require('ee-core/log'); +const EE = require('ee-core/ee'); /** * 安全插件 @@ -6,8 +7,7 @@ const Log = require('ee-core/log'); */ class SecurityAddon { - constructor(app) { - this.app = app; + constructor() { } /** @@ -15,6 +15,7 @@ class SecurityAddon { */ create () { Log.info('[addon:security] load'); + const { CoreApp } = EE; const runWithDebug = process.argv.find(function(e){ let isHasDebug = e.includes("--inspect") || e.includes("--inspect-brk") || e.includes("--remote-debugging-port"); return isHasDebug; @@ -23,7 +24,7 @@ class SecurityAddon { // 不允许远程调试 if (runWithDebug) { Log.error('[error] Remote debugging is not allowed, runWithDebug:', runWithDebug); - this.app.appQuit(); + CoreApp.appQuit(); } } } diff --git a/electron/addon/tray/index.js b/electron/addon/tray/index.js index 4c723f5..57dbdf8 100644 --- a/electron/addon/tray/index.js +++ b/electron/addon/tray/index.js @@ -1,9 +1,11 @@ -const { Tray, Menu, shell } = require('electron'); +const { Tray, Menu } = require('electron'); const path = require('path'); const Ps = require('ee-core/ps'); const Log = require('ee-core/log'); 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'); /** * 托盘插件 @@ -11,8 +13,7 @@ const Conf = require('ee-core/config'); */ class TrayAddon { - constructor(app) { - this.app = app; + constructor() { this.tray = null; } @@ -24,10 +25,9 @@ class TrayAddon { if (Ps.isDev() && Ps.isHotReload()) return; Log.info('[addon:tray] load'); - - const app = this.app; + const { CoreApp } = EE; const cfg = Conf.getValue('addons.tray'); - const { mainWindow } = Electron; + const mainWindow = CoreWindow.getMainWindow(); // 托盘图标 let iconPath = path.join(Ps.getHomeDir(), cfg.icon); @@ -43,15 +43,14 @@ class TrayAddon { { label: '退出', click: function () { - app.appQuit(); + CoreApp.appQuit(); } } ] // 点击关闭,最小化到托盘 mainWindow.on('close', (event) => { - const extraObj = Electron.extra; - if (extraObj.closeWindow == true) { + if (Electron.extra.closeWindow == true) { return; } mainWindow.hide(); @@ -63,12 +62,6 @@ class TrayAddon { this.tray.setToolTip(cfg.title); const contextMenu = Menu.buildFromTemplate(trayMenuTemplate); this.tray.setContextMenu(contextMenu); - - // 使用默认浏览器打开链接 - mainWindow.webContents.setWindowOpenHandler(({ url }) => { - shell.openExternal(url); - return { action: 'deny' } - }) } } diff --git a/electron/controller/example.js b/electron/controller/example.js index cb0c0f8..52baff0 100644 --- a/electron/controller/example.js +++ b/electron/controller/example.js @@ -2,6 +2,7 @@ const { Controller } = require('ee-core'); const Log = require('ee-core/log'); +const Services = require('ee-core/services'); /** * example @@ -24,12 +25,10 @@ class ExampleController extends Controller { * test */ async test () { - const result = await this.service.example.test('electron'); + const result = await Services.get('example').test('electron'); + Log.info('service result:', result); - let tmpDir = Ps.getLogDir(); - Log.info('tmpDir:', tmpDir); - - return result; + return 'hello electron-egg'; } } diff --git a/electron/index.js b/electron/index.js new file mode 100644 index 0000000..7491e37 --- /dev/null +++ b/electron/index.js @@ -0,0 +1,49 @@ +const { Application } = require('ee-core'); + +class Index extends Application { + + constructor() { + super(); + // this === eeApp; + } + + /** + * core app have been loaded + */ + async ready () { + // do some things + } + + /** + * electron app ready + */ + async electronAppReady () { + // do some things + } + + /** + * main window have been loaded + */ + async windowReady () { + // do some things + // 延迟加载,无白屏 + const winOpt = this.config.windowsOption; + if (winOpt.show == false) { + const win = this.electron.mainWindow; + win.once('ready-to-show', () => { + win.show(); + }) + } + } + + /** + * before app close + */ + async beforeClose () { + // do some things + + } +} + +Index.toString = () => '[class Index]'; +module.exports = Index; \ No newline at end of file diff --git a/electron/preload/index.js b/electron/preload/index.js index a4af709..9de09ba 100644 --- a/electron/preload/index.js +++ b/electron/preload/index.js @@ -1,20 +1,16 @@ /************************************************* ** preload为预加载模块,该文件将会在程序启动时加载 ** *************************************************/ + const Addon = require('ee-core/addon'); -/** - * 预加载模块入口 - */ -module.exports = async (app) => { - - //已实现的功能模块,可选择性使用和修改 - const trayAddon = app.addon.tray; - const securityAddon = app.addon.security; - const awakenAddon = app.addon.awaken; - const autoUpdaterAddon = app.addon.autoUpdater; - - trayAddon.create(); - securityAddon.create(); - awakenAddon.create(); - autoUpdaterAddon.create(); -} \ No newline at end of file + /** + * 预加载模块入口 + */ + 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/main.js b/main.js index cb675c8..98527c4 100644 --- a/main.js +++ b/main.js @@ -1,50 +1,2 @@ -const { Application } = require('ee-core'); -const EE = require('ee-core/ee'); - -class Main extends Application { - - constructor() { - super(); - // this === eeApp; - } - - /** - * core app have been loaded - */ - async ready () { - // do some things - } - - /** - * electron app ready - */ - async electronAppReady () { - // do some things - } - - /** - * main window have been loaded - */ - async windowReady () { - // do some things - // 延迟加载,无白屏 - const winOpt = this.config.windowsOption; - if (winOpt.show == false) { - const win = this.electron.mainWindow; - win.once('ready-to-show', () => { - win.show(); - }) - } - } - - /** - * before app close - */ - async beforeClose () { - // do some things - - } -} - -// Instantiate an app object -EE.app = new Main(); \ No newline at end of file +const { ElectronEgg } = require('ee-core'); +new ElectronEgg(); \ No newline at end of file diff --git a/package.json b/package.json index 024192d..341d0c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ee", - "version": "3.2.0", + "version": "3.3.0", "description": "A fast, desktop software development framework", "main": "main.js", "scripts": { @@ -107,10 +107,14 @@ "electron": "^13.6.9", "electron-builder": "^23.6.0", "electron-rebuild": "^3.2.8", + "eslint": "^5.13.0", + "eslint-plugin-prettier": "^3.0.1", "nodemon": "^2.0.16" }, "dependencies": { - "ee-core": "^2.1.1", + "better-sqlite3": "^7.6.2", + "dayjs": "^1.10.7", + "ee-core": "^2.2.1", "electron-updater": "^5.3.0", "lodash": "^4.17.21" }