cross service

This commit is contained in:
gaoshuaixing
2024-01-29 18:23:44 +08:00
6 changed files with 86 additions and 60 deletions

View File

@@ -134,7 +134,7 @@ module.exports = (appInfo) => {
* 硬件加速
*/
config.hardGpu = {
enable: false
enable: true
};
/**
@@ -184,13 +184,6 @@ module.exports = (appInfo) => {
},
force: false,
},
javaServer: {
enable: false,
port: 18080,
jreVersion: 'jre1.8.0_201',
opt: '-server -Xms512M -Xmx512M -Xss512k -Dspring.profiles.active=prod -Dserver.port=${port} -Dlogging.file.path="${path}" ',
name: 'java-app.jar'
}
};
return {

View File

@@ -4,9 +4,7 @@ const { Controller } = require('ee-core');
const Cross = require('ee-core/cross');
const Log = require('ee-core/log');
const HttpClient = require('ee-core/httpclient');
const Ps = require('ee-core/ps');
const path = require("path");
const Is = require('ee-core/utils/is');
const Services = require('ee-core/services');
/**
* Cross
@@ -62,52 +60,14 @@ class CrossController extends Controller {
/**
* create service
* In the default configuration, services can be started with applications.
* Developers can turn off the configuration and create it manually.
*/
async createServer() {
// method 1: Use the default Settings
//const entity = await Cross.run(serviceName);
// method 2: Use custom configuration
const serviceName = "go";
const opt = {
name: 'goapp',
appExit: false,
async createServer(args) {
const { program } = args;
if (program == 'go') {
Services.get('cross').createGoServer();
} else if (program == 'java') {
Services.get('cross').createJavaServer();
}
const entity = await Cross.run(serviceName, opt);
Log.info('server name:', entity.name);
Log.info('server config:', entity.config);
Log.info('server url:', Cross.getUrl(entity.name));
return;
}
/**
* create java server
*/
async createJavaServer() {
const serviceName = "java";
const jarPath = path.join(Ps.getExtraResourcesDir(), 'java-app.jar');
const opt = {
name: 'javaapp',
cmd: path.join(Ps.getExtraResourcesDir(), 'jre1.8.0_201/bin/javaw.exe'),
directory: Ps.getExtraResourcesDir(),
args: ['-jar', '-server', '-Xms512M', '-Xmx512M', '-Xss512k', '-Dspring.profiles.active=prod', `-Dserver.port=18080`, `-Dlogging.file.path=${Ps.getLogDir()}`, `${jarPath}`],
appExit: false,
}
if (Is.macOS()) {
// Setup Java program
opt.cmd = path.join(Ps.getExtraResourcesDir(), 'jre1.8.0_201/Contents/Home/bin/java');
}
if (Is.linux()) {
// Setup Java program
}
const entity = await Cross.run(serviceName, opt);
Log.info('server name:', entity.name);
Log.info('server config:', entity.config);
Log.info('server url:', Cross.getUrl(entity.name));
return;
}

74
electron/service/cross.js Normal file
View File

@@ -0,0 +1,74 @@
'use strict';
const { Service } = require('ee-core');
const Cross = require('ee-core/cross');
const Log = require('ee-core/log');
const Ps = require('ee-core/ps');
const path = require("path");
const Is = require('ee-core/utils/is');
/**
* crossservice层为单例
* @class
*/
class CrossService extends Service {
constructor(ctx) {
super(ctx);
}
/**
* create go service
* In the default configuration, services can be started with applications.
* Developers can turn off the configuration and create it manually.
*/
async createGoServer() {
// method 1: Use the default Settings
//const entity = await Cross.run(serviceName);
// method 2: Use custom configuration
const serviceName = "go";
const opt = {
name: 'goapp',
appExit: false,
}
const entity = await Cross.run(serviceName, opt);
Log.info('server name:', entity.name);
Log.info('server config:', entity.config);
Log.info('server url:', Cross.getUrl(entity.name));
return;
}
/**
* create java server
*/
async createJavaServer() {
const serviceName = "java";
const jarPath = path.join(Ps.getExtraResourcesDir(), 'java-app.jar');
const opt = {
name: 'javaapp',
cmd: path.join(Ps.getExtraResourcesDir(), 'jre1.8.0_201/bin/javaw.exe'),
directory: Ps.getExtraResourcesDir(),
args: ['-jar', '-server', '-Xms512M', '-Xmx512M', '-Xss512k', '-Dspring.profiles.active=prod', `-Dserver.port=18080`, `-Dlogging.file.path=${Ps.getLogDir()}`, `${jarPath}`],
appExit: false,
}
if (Is.macOS()) {
// Setup Java program
opt.cmd = path.join(Ps.getExtraResourcesDir(), 'jre1.8.0_201/Contents/Home/bin/java');
}
if (Is.linux()) {
// Setup Java program
}
const entity = await Cross.run(serviceName, opt);
Log.info('server name:', entity.name);
Log.info('server config:', entity.config);
Log.info('server url:', Cross.getUrl(entity.name));
return;
}
}
CrossService.toString = () => '[class CrossService]';
module.exports = CrossService;

View File

@@ -59,7 +59,6 @@ const ipcApiRoute = {
getCrossUrl: 'controller.cross.getUrl',
killCrossServer: 'controller.cross.killServer',
createCrossServer: 'controller.cross.createServer',
createJavaServer: 'controller.cross.createJavaServer',
requestApi: 'controller.cross.requestApi',
}

View File

@@ -7,9 +7,9 @@
</div>
<div class="one-block-2">
<a-space>
<a-button @click="create()"> 启动 </a-button>
<a-button @click="getUrl()"> 获取地址 </a-button>
<a-button @click="kill()"> kill </a-button>
<a-button @click="create()"> 启动 </a-button>
<a-button @click="info()"> test </a-button>
</a-space>
</div>
@@ -69,7 +69,7 @@
ipc.invoke(ipcApiRoute.killCrossServer, {type: 'all', name: 'goapp'})
},
create() {
ipc.invoke(ipcApiRoute.createCrossServer)
ipc.invoke(ipcApiRoute.createCrossServer, { program: 'go' })
},
request(type) {
if (type == 1 && this.serverUrl == "") {

View File

@@ -7,9 +7,9 @@
</div>
<div class="one-block-2">
<a-space>
<a-button @click="create()"> 启动 </a-button>
<a-button @click="getUrl()"> 获取地址 </a-button>
<a-button @click="kill()"> kill </a-button>
<a-button @click="create()"> 启动 </a-button>
<a-button @click="info()"> 查看 </a-button>
</a-space>
</div>
@@ -69,7 +69,7 @@
ipc.invoke(ipcApiRoute.killCrossServer, {type: 'all', name: 'javaapp'})
},
create() {
ipc.invoke(ipcApiRoute.createJavaServer)
ipc.invoke(ipcApiRoute.createCrossServer, { program: 'java' })
},
request(type) {
if (type == 1 && this.serverUrl == "") {