diff --git a/electron/config/config.local.js b/electron/config/config.local.js index 2d89902..20ecc4b 100644 --- a/electron/config/config.local.js +++ b/electron/config/config.local.js @@ -6,7 +6,7 @@ module.exports = () => { return { openDevTools: { - mode: 'undocked' + mode: 'bottom' }, jobs: { messageLog: true diff --git a/electron/controller/cross.js b/electron/controller/cross.js index 63fbc92..a289912 100644 --- a/electron/controller/cross.js +++ b/electron/controller/cross.js @@ -1,5 +1,7 @@ 'use strict'; +const { crossService } = require('../service/cross'); + /** * Cross * @class @@ -10,17 +12,7 @@ class CrossController { * View process service information */ info() { - const pids = Cross.getPids(); - Log.info('cross pids:', pids); - - let num = 1; - pids.forEach(pid => { - let entity = Cross.getProc(pid); - Log.info(`server-${num} name:${entity.name}`); - Log.info(`server-${num} config:`, entity.config); - num++; - }) - + crossService.info(); return 'hello electron-egg'; } @@ -29,7 +21,7 @@ class CrossController { */ async getUrl(args) { const { name } = args; - const serverUrl = Cross.getUrl(name); + const serverUrl = crossService.getUrl(name); return serverUrl; } @@ -39,12 +31,7 @@ class CrossController { */ async killServer(args) { const { type, name } = args; - if (type == 'all') { - Cross.killAll(); - } else { - Cross.killByName(name); - } - + crossService.killServer(type, name); return; } @@ -54,11 +41,11 @@ class CrossController { async createServer(args) { const { program } = args; if (program == 'go') { - Services.get('cross').createGoServer(); + crossService.createGoServer(); } else if (program == 'java') { - Services.get('cross').createJavaServer(); + crossService.createJavaServer(); } else if (program == 'python') { - Services.get('cross').createPythonServer(); + crossService.createPythonServer(); } return; @@ -69,20 +56,8 @@ class CrossController { */ async requestApi(args) { const { name, urlPath, params} = args; - const hc = new HttpClient(); - const serverUrl = Cross.getUrl(name); - console.log('Server Url:', serverUrl); - - const apiHello = serverUrl + urlPath; - const options = { - method: 'GET', - data: params || {}, - dataType: 'json', - timeout: 1000, - }; - const result = await hc.request(apiHello, options); - - return result.data; + const data = await crossService.requestApi(name, urlPath, params); + return data; } } diff --git a/electron/main.js b/electron/main.js index cb16894..b005896 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,6 +1,6 @@ const { ElectronEgg } = require('ee-core'); -const Lifecycle = require('./preload/lifecycle'); -const preload = require('./preload/index'); +const { Lifecycle } = require('./preload/lifecycle'); +const { preload } = require('./preload'); // new app const app = new ElectronEgg(); @@ -10,8 +10,10 @@ const life = new Lifecycle(); app.register("ready", life.ready); app.register("electron-app-ready", life.electronAppReady); app.register("window-ready", life.windowReady); -app.register("preload", preload); app.register("before-close", life.beforeClose); +// register preload +app.register("preload", preload); + // run app.run(); \ No newline at end of file diff --git a/electron/preload/index.js b/electron/preload/index.js index 9c883cb..d2c53a7 100644 --- a/electron/preload/index.js +++ b/electron/preload/index.js @@ -2,12 +2,14 @@ ** preload为预加载模块,该文件将会在程序启动时加载 ** *************************************************/ +function preload() { + // 示例功能模块,可选择性使用和修改 + console.log('preload/index.js'); +} /** * 预加载模块入口 */ -module.exports = async () => { - - // 示例功能模块,可选择性使用和修改 - console.log('preload/index.js'); +module.exports = { + preload } \ No newline at end of file diff --git a/electron/preload/lifecycle.js b/electron/preload/lifecycle.js index 52ed108..396be77 100644 --- a/electron/preload/lifecycle.js +++ b/electron/preload/lifecycle.js @@ -5,16 +5,12 @@ const { getMainWindow } = require('ee-core/electron'); class Lifecycle { - constructor() { - - } - /** * core app have been loaded */ async ready() { // do some things - console.log('------------lifecycle ready'); + console.log('[lifecycle] ready'); } /** @@ -22,14 +18,14 @@ class Lifecycle { */ async electronAppReady() { // do some things - console.log('-----------lifecycle electron-app-ready'); + console.log('[lifecycle] electron-app-ready'); } /** * main window have been loaded */ async windowReady() { - console.log('-------------lifecycle window-ready'); + console.log('[lifecycle] window-ready'); // 延迟加载,无白屏 const { windowsOption } = getConfig(); if (windowsOption.show == false) { @@ -45,9 +41,11 @@ class Lifecycle { * before app close */ async beforeClose() { - console.log('-----------lifecycle before-close'); + console.log('[lifecycle] before-close'); } } Lifecycle.toString = () => '[class Lifecycle]'; -module.exports = Lifecycle; \ No newline at end of file +module.exports = { + Lifecycle +}; \ No newline at end of file diff --git a/electron/service/cross.js b/electron/service/cross.js index 64ff240..c850d06 100644 --- a/electron/service/cross.js +++ b/electron/service/cross.js @@ -3,7 +3,9 @@ const { logger } = require('ee-core/log'); const { getExtraResourcesDir } = require('ee-core/ps'); const path = require("path"); -const Is = require('ee-core/utils/is'); +const axios = require('axios'); +const { is } = require('ee-core/utils'); +const { cross } = require('ee-core/cross'); /** * cross @@ -11,6 +13,34 @@ const Is = require('ee-core/utils/is'); */ class CrossService { + info() { + const pids = cross.getPids(); + logger.info('cross pids:', pids); + + let num = 1; + pids.forEach(pid => { + let entity = cross.getProc(pid); + logger.info(`server-${num} name:${entity.name}`); + logger.info(`server-${num} config:`, entity.config); + num++; + }) + + return 'hello electron-egg'; + } + + getUrl(name) { + const serverUrl = cross.getUrl(name); + return serverUrl; + } + + killServer(type, name) { + if (type == 'all') { + cross.killAll(); + } else { + cross.killByName(name); + } + } + /** * create go service * In the default configuration, services can be started with applications. @@ -18,7 +48,7 @@ class CrossService { */ async createGoServer() { // method 1: Use the default Settings - //const entity = await Cross.run(serviceName); + //const entity = await cross.run(serviceName); // method 2: Use custom configuration const serviceName = "go"; @@ -29,7 +59,7 @@ class CrossService { args: ['--port=7073'], appExit: true, } - const entity = await Cross.run(serviceName, opt); + const entity = await cross.run(serviceName, opt); logger.info('server name:', entity.name); logger.info('server config:', entity.config); logger.info('server url:', entity.getUrl()); @@ -50,18 +80,18 @@ class CrossService { args: ['-jar', '-server', '-Xms512M', '-Xmx512M', '-Xss512k', '-Dspring.profiles.active=prod', `-Dserver.port=18080`, `-Dlogging.file.path=${Ps.getLogDir()}`, `${jarPath}`], appExit: false, } - if (Is.macOS()) { + if (is.macOS()) { // Setup Java program - opt.cmd = path.join(Ps.getExtraResourcesDir(), 'jre1.8.0_201.jre/Contents/Home/bin/java'); + opt.cmd = path.join(getExtraResourcesDir(), 'jre1.8.0_201.jre/Contents/Home/bin/java'); } - if (Is.linux()) { + if (is.linux()) { // Setup Java program } - const entity = await Cross.run(serviceName, opt); + const entity = await cross.run(serviceName, opt); logger.info('server name:', entity.name); logger.info('server config:', entity.config); - logger.info('server url:', Cross.getUrl(entity.name)); + logger.info('server url:', cross.getUrl(entity.name)); return; } @@ -73,7 +103,7 @@ class CrossService { */ async createPythonServer() { // method 1: Use the default Settings - //const entity = await Cross.run(serviceName); + //const entity = await cross.run(serviceName); // method 2: Use custom configuration const serviceName = "python"; @@ -85,13 +115,33 @@ class CrossService { windowsExtname: true, appExit: true, } - const entity = await Cross.run(serviceName, opt); + const entity = await cross.run(serviceName, opt); logger.info('server name:', entity.name); logger.info('server config:', entity.config); logger.info('server url:', entity.getUrl()); return; } + + async requestApi(name, urlPath, params) { + const serverUrl = cross.getUrl(name); + const apiHello = serverUrl + urlPath; + console.log('Server Url:', serverUrl); + + const response = await axios({ + method: 'get', + url: apiHello, + timeout: 1000, + params, + proxy: false, + }); + if (response.status == 200) { + const { data } = response; + return data; + } + + return null; + } } CrossService.toString = () => '[class CrossService]'; diff --git a/electron/service/database/basedb.js b/electron/service/database/basedb.js index b0b2126..0d5d05a 100644 --- a/electron/service/database/basedb.js +++ b/electron/service/database/basedb.js @@ -1,7 +1,7 @@ 'use strict'; const { SqliteStorage } = require('ee-core/storage'); -const { getStorageDir } = require('ee-core/ps'); +const { getDataDir } = require('ee-core/ps'); const path = require('path'); /** @@ -22,7 +22,7 @@ class BasedbService { */ _init() { // 定义数据文件 - const dbFile = path.join(getStorageDir(), "db", this.dbname); + const dbFile = path.join(getDataDir(), "db", this.dbname); const sqliteOptions = { timeout: 6000, verbose: console.log diff --git a/frontend/src/views/cross/go/Index.vue b/frontend/src/views/cross/go/Index.vue index 38445b4..57c0aa3 100644 --- a/frontend/src/views/cross/go/Index.vue +++ b/frontend/src/views/cross/go/Index.vue @@ -1,117 +1,104 @@ - - - \ No newline at end of file + if (type == 1) { + const testApi = serverUrl.value + '/api/hello'; + const cfg = { + method: 'get', + url: testApi, + params: { id: '111'}, + timeout: 1000, + } + axios(cfg).then(res => { + console.log('res:', res); + const data = res.data.data || null; + message.info(`服务返回: ${data}`); + }) + } else { + ipc.invoke(ipcApiRoute.cross.requestApi, {name: 'goapp', urlPath: '/api/hello'}).then(res => { + console.log('res:', res); + if (res) { + const { data} = res; + message.info(`服务返回: ${data}`); + } else { + message.info(`服务无返回`); + } + }) + } +} + + diff --git a/go/config/.air.toml b/go/config/.air.toml index 66a8c75..f0e1444 100644 --- a/go/config/.air.toml +++ b/go/config/.air.toml @@ -3,10 +3,10 @@ tmp_dir = "tmp" [build] # 编译使用的shell命令 -cmd = "go build -tags=fts5 -o ./tmp/goapp ./main.go" +cmd = "go build -o ./tmp/goapp ./main.go" # 由`cmd`命令得到的二进制文件名 -bin = "./tmp/goapp --basedir=../ --env=dev --port=7003" +bin = "./tmp/goapp --basedir=../ --env=dev --port=7073" # 在运行二进制文件时添加额外的参数 (bin/full_bin)。将运行“./tmp/main hello world” # args_bin = ["hello", "world"] diff --git a/go/config/.air.windows.toml b/go/config/.air.windows.toml index 300e2cd..a8b85d2 100644 --- a/go/config/.air.windows.toml +++ b/go/config/.air.windows.toml @@ -3,10 +3,10 @@ tmp_dir = "tmp" [build] # 编译使用的shell命令 -cmd = "go build -tags=fts5 -o ./tmp/goapp.exe ./main.go" +cmd = "go build -o ./tmp/goapp.exe ./main.go" # 由`cmd`命令得到的二进制文件名 -bin = "./tmp/goapp.exe --basedir=../ --env=dev --port=7003" +bin = "./tmp/goapp.exe --basedir=../ --env=dev --port=7073" # 在运行二进制文件时添加额外的参数 (bin/full_bin)。将运行“./tmp/main hello world” # args_bin = ["hello", "world"] diff --git a/go/public/config/.air.toml b/go/public/config/.air.toml index 66a8c75..f0e1444 100644 --- a/go/public/config/.air.toml +++ b/go/public/config/.air.toml @@ -3,10 +3,10 @@ tmp_dir = "tmp" [build] # 编译使用的shell命令 -cmd = "go build -tags=fts5 -o ./tmp/goapp ./main.go" +cmd = "go build -o ./tmp/goapp ./main.go" # 由`cmd`命令得到的二进制文件名 -bin = "./tmp/goapp --basedir=../ --env=dev --port=7003" +bin = "./tmp/goapp --basedir=../ --env=dev --port=7073" # 在运行二进制文件时添加额外的参数 (bin/full_bin)。将运行“./tmp/main hello world” # args_bin = ["hello", "world"] diff --git a/go/public/config/.air.windows.toml b/go/public/config/.air.windows.toml index 300e2cd..a8b85d2 100644 --- a/go/public/config/.air.windows.toml +++ b/go/public/config/.air.windows.toml @@ -3,10 +3,10 @@ tmp_dir = "tmp" [build] # 编译使用的shell命令 -cmd = "go build -tags=fts5 -o ./tmp/goapp.exe ./main.go" +cmd = "go build -o ./tmp/goapp.exe ./main.go" # 由`cmd`命令得到的二进制文件名 -bin = "./tmp/goapp.exe --basedir=../ --env=dev --port=7003" +bin = "./tmp/goapp.exe --basedir=../ --env=dev --port=7073" # 在运行二进制文件时添加额外的参数 (bin/full_bin)。将运行“./tmp/main hello world” # args_bin = ["hello", "world"]