mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Split client into frontend website and server
This commit is contained in:
57
frontend/server/client.js
Normal file
57
frontend/server/client.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const { app, BrowserWindow } = require('electron/main')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const { spawn } = require('child_process');
|
||||
const yargs = require('yargs');
|
||||
|
||||
yargs.alias('c', 'config').describe('c', 'olympus.json config location').string('rp');
|
||||
args = yargs.argv;
|
||||
|
||||
console.log(`Config location: ${args["config"]}`)
|
||||
var clientPort = 3000;
|
||||
if (fs.existsSync(args["config"])) {
|
||||
var json = JSON.parse(fs.readFileSync(args["config"], 'utf-8'));
|
||||
clientPort = json["client"]["port"];
|
||||
} else {
|
||||
console.log("Failed to read config, trying default port");
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
const win = new BrowserWindow({
|
||||
icon: "./../img/olympus.ico"
|
||||
})
|
||||
|
||||
win.loadURL(`http://localhost:${clientPort}`);
|
||||
win.setMenuBarVisibility(false);
|
||||
win.maximize();
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
const server = spawn('node', [path.join('.', 'bin', 'www'), "--config", args["config"]]);
|
||||
|
||||
server.stdout.on('data', (data) => {
|
||||
console.log(`${data}`);
|
||||
});
|
||||
|
||||
server.stderr.on('data', (data) => {
|
||||
console.error(`stderr: ${data}`);
|
||||
});
|
||||
|
||||
server.on('close', (code) => {
|
||||
console.log(`Child process exited with code ${code}`);
|
||||
});
|
||||
|
||||
createWindow()
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user