Add proper Electron launcher and building process #6

Merged
grey merged 6 commits from electron into master 2022-11-15 18:28:59 +01:00
Showing only changes of commit 94c81ee76d - Show all commits

View File

@ -22,13 +22,13 @@ const tempJsonText = JSON.parse(fs.readFileSync("config.json", "utf8"));
configObject = _.extend(configObject, tempJsonText);
fs.writeFileSync("config.json", JSON.stringify(configObject));
// Set a serverStatus
let serverStatus = "Starting"
const processArgs = process.argv;
// Check if --headless is passed as an argument
const processArgs = process.argv;
if (processArgs.includes("--headless")) {
startServer()
} else {
// Start electron
app.whenReady().then(() => {
@ -36,6 +36,7 @@ if (processArgs.includes("--headless")) {
createTray()
createWindow()
setInterval(() => {
// Check if the server is running
http.get('http://127.0.0.1:' + configObject.port + "/api/v1/system", (resp) => {
let data = '';
@ -46,16 +47,23 @@ if (processArgs.includes("--headless")) {
// The whole response has been received. Print out the result.
resp.on('end', () => {
// If we have a valid response, set the serverStatus to "Running"
let parsed = JSON.parse(data)
console.log(parsed)
serverStatus = "Running"
// Send the serverStatus to the window
if (win) {
win.webContents.send('info', { "appStatus": serverStatus, "appURL": "http://127.0.0.1:" + configObject.port, "appName": "openCountdown " + packageJson.version, "startMinimised": configObject.startMinimised, "port": configObject.port })
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}, 1000);
}, 2000);
})
ipcMain.on('info', function () {
// Send inital data to the window
if (win) {
win.webContents.send('info', { "appStatus": serverStatus, "appURL": "http://127.0.0.1:" + configObject.port, "appName": "openCountdown " + packageJson.version, "startMinimised": configObject.startMinimised, "port": configObject.port })
}
@ -169,6 +177,10 @@ function trayQuit() {
}
let response = dialog.showMessageBoxSync(options)
if (response == 0) {
serverStatus = "Stopping"
if (win) {
win.webContents.send('info', { "appStatus": serverStatus, "appURL": "http://127.0.0.1:" + configObject.port, "appName": "openCountdown " + packageJson.version, "startMinimised": configObject.startMinimised, "port": configObject.port })
}
srvProc.kill("SIGINT")
setTimeout(app.quit, 1000)
}