From f2813e6dae751b1251af738c27f06b7e8ae3e2cb Mon Sep 17 00:00:00 2001 From: gaoshuaixing <530353222@qq.com> Date: Sun, 22 Dec 2024 21:01:10 +0800 Subject: [PATCH] chore: test config \ lifecycle --- electron/config/config.default.js | 180 ++++++-------------- electron/config/config.local.js | 36 +--- electron/config/config.prod.js | 36 +--- electron/controller/child/friend/school.js | 18 ++ electron/main.js | 3 + electron/{index.js => preload/lifecycle.js} | 9 +- package.json | 3 +- 7 files changed, 90 insertions(+), 195 deletions(-) create mode 100644 electron/controller/child/friend/school.js rename electron/{index.js => preload/lifecycle.js} (85%) diff --git a/electron/config/config.default.js b/electron/config/config.default.js index 7b38f9f..ebbb087 100644 --- a/electron/config/config.default.js +++ b/electron/config/config.default.js @@ -6,135 +6,65 @@ const path = require('path'); * 默认配置 */ module.exports = (appInfo) => { - const config = {}; - - /** - * 开发者工具 - */ - config.openDevTools = false; - - /** - * 主窗口 - */ - config.windowsOption = { - title: 'EE框架', - width: 980, - height: 650, - minWidth: 400, - minHeight: 300, - webPreferences: { - //webSecurity: false, - contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge) - nodeIntegration: true, - //preload: path.join('preload', 'bridge.js'), + return { + openDevTools: false, + windowsOption: { + title: 'electron-egg1', + width: 980, + height: 650, + minWidth: 400, + minHeight: 300, + webPreferences: { + //webSecurity: false, + contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge) + nodeIntegration: true, + //preload: path.join(appInfo.electronDir, 'preload', 'bridge.js'), + }, + frame: true, + show: false, + icon: path.join(appInfo.baseDir, 'public', 'images', 'logo-32.png'), }, - frame: true, - show: false, - icon: path.join('public', 'images', 'logo-32.png'), - }; - - /** - * ee框架日志 - */ - config.logger = { - encoding: 'utf8', - level: 'INFO', - outputJSON: false, - buffer: true, - enablePerformanceTimer: false, - rotator: 'day', - appLogName: 'ee.log', - coreLogName: 'ee-core.log', - errorLogName: 'ee-error.log' - } - - /** - * 远程模式-web地址 - */ - config.remoteUrl = { - enable: false, - url: 'http://electron-egg.kaka996.com/' - }; - - /** - * 内置socket服务 - */ - config.socketServer = { - enable: false, - port: 7070, - path: "/socket.io/", - connectTimeout: 45000, - pingTimeout: 30000, - pingInterval: 25000, - maxHttpBufferSize: 1e8, - transports: ["polling", "websocket"], - cors: { - origin: true, + logger: { + level: 'INFO', + outputJSON: false, + appLogName: 'ee.log', + coreLogName: 'ee-core.log', + errorLogName: 'ee-error.log' }, - channel: 'c1' - }; - - /** - * 内置http服务 - */ - config.httpServer = { - enable: false, - https: { - enable: false, - key: '/public/ssl/localhost+1.key', - cert: '/public/ssl/localhost+1.pem' + remoteUrl: { + enable: false, + url: 'http://electron-egg.kaka996.com/' }, - host: '127.0.0.1', - port: 7071, - cors: { - origin: "*" + socketServer: { + enable: false, + port: 8080, + path: "/socket.io/", + connectTimeout: 45000, + pingTimeout: 30000, + pingInterval: 25000, + maxHttpBufferSize: 1e8, + transports: ["polling", "websocket"], + cors: { + origin: false, + }, + channel: 'c1' }, - body: { - multipart: true, - formidable: { - keepExtensions: true + httpServer: { + enable: false, + https: { + enable: false, + key: '/public/ssl/localhost+1.key', + cert: '/public/ssl/localhost+1.pem' + }, + host: '127.0.0.1', + port: 7071, + cors: { + origin: "*" } }, - filterRequest: { - uris: [ - 'favicon.ico' - ], - returnData: '' - } - }; - - /** - * 主进程 - */ - config.mainServer = { - protocol: 'file://', - indexPath: '/public/dist/index.html', - }; - - /** - * 硬件加速 - */ - config.hardGpu = { - enable: true - }; - - /** - * 异常捕获 - */ - config.exception = { - mainExit: false, - childExit: true, - rendererExit: true, - }; - - /** - * jobs - */ - config.jobs = { - messageLog: true - }; - - return { - ...config - }; + mainServer: { + protocol: 'file://', + indexPath: '/public/dist/index.html', + }, + } } diff --git a/electron/config/config.local.js b/electron/config/config.local.js index bfa73c2..fae1ec7 100644 --- a/electron/config/config.local.js +++ b/electron/config/config.local.js @@ -1,37 +1,15 @@ 'use strict'; /** - * 开发环境配置,覆盖 config.default.js + * Development environment configuration, coverage config.default.js */ module.exports = () => { - const config = {}; - - /** - * 开发者工具 - */ - config.openDevTools = { - mode: 'undocked' - }; - - /** - * 内置socket服务 - */ - config.socketServer = { - enable: false, - port: 7071, - path: "/socket.io/", - connectTimeout: 45000, - pingTimeout: 30000, - pingInterval: 25000, - maxHttpBufferSize: 1e8, - transports: ["polling", "websocket"], - cors: { - origin: false, - }, - channel: 'c1' - }; - return { - ...config + openDevTools: { + mode: 'undocked' + }, + jobs: { + messageLog: false + } }; }; diff --git a/electron/config/config.prod.js b/electron/config/config.prod.js index 975beb6..db1ce01 100644 --- a/electron/config/config.prod.js +++ b/electron/config/config.prod.js @@ -1,42 +1,10 @@ 'use strict'; /** - * 开发环境配置,覆盖 config.default.js + * coverage config.default.js */ module.exports = () => { - const config = {}; - - /** - * 开发者工具 - */ - config.openDevTools = { - mode: 'undocked' - }; - - /** - * 应用程序顶部菜单 - */ - config.openAppMenu = false; - - /** - * 内置socket服务 - */ - config.socketServer = { - enable: false, - port: 7071, - path: "/socket.io/", - connectTimeout: 45000, - pingTimeout: 30000, - pingInterval: 25000, - maxHttpBufferSize: 1e8, - transports: ["polling", "websocket"], - cors: { - origin: false, - }, - channel: 'c1' - }; - return { - ...config + openDevTools: false, }; }; diff --git a/electron/controller/child/friend/school.js b/electron/controller/child/friend/school.js new file mode 100644 index 0000000..d89582b --- /dev/null +++ b/electron/controller/child/friend/school.js @@ -0,0 +1,18 @@ +'use strict'; + +/** + * school + * @class + */ +class SchoolController { + + /** + * test + */ + async test () { + return 'hello electron-egg'; + } +} + +SchoolController.toString = () => '[class SchoolController]'; +module.exports = SchoolController; \ No newline at end of file diff --git a/electron/main.js b/electron/main.js index bac11f9..47da1e1 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,5 +1,8 @@ const { ElectronEgg } = require('ee-core'); +const Lifecycle = require('./preload/lifecycle'); const app = new ElectronEgg(); +const lifecycle = new Lifecycle(); +app.register("ready", lifecycle.ready()); app.run(); \ No newline at end of file diff --git a/electron/index.js b/electron/preload/lifecycle.js similarity index 85% rename from electron/index.js rename to electron/preload/lifecycle.js index ac8bedc..f50e9f3 100644 --- a/electron/index.js +++ b/electron/preload/lifecycle.js @@ -1,10 +1,9 @@ 'use strict'; -class Index { +class Lifecycle { constructor() { - super(); - // this === eeApp; + } /** @@ -46,5 +45,5 @@ class Index { } } -Index.toString = () => '[class Index]'; -module.exports = Index; \ No newline at end of file +Lifecycle.toString = () => '[class Lifecycle]'; +module.exports = Lifecycle; \ No newline at end of file diff --git a/package.json b/package.json index 5b1f154..c82e883 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "license": "Apache", "devDependencies": { "cross-env": "^7.0.3", - "debug": "^4.3.7", + "debug": "^4.4.0", "ee-bin": "file:.yalc/ee-bin", "ee-bin-ts": "file:.yalc/ee-bin-ts", "electron": "^29.4.0", @@ -55,7 +55,6 @@ "dependencies": { "dayjs": "^1.11.13", "ee-core": "file:.yalc/ee-core", - "ee-core-ts": "file:.yalc/ee-core-ts", "electron-updater": "^6.3.8" } }