added proper status message

This commit is contained in:
Sören Oesterwind 2022-11-13 19:12:33 +01:00
parent 811d96f5fa
commit de22ec5c3a

View File

@ -1,9 +1,11 @@
const { app, BrowserWindow, ipcMain, Tray, Menu, nativeImage, MenuItem, dialog } = require('electron')
const { app, BrowserWindow, ipcMain, Tray, Menu, MenuItem, dialog } = require('electron')
const path = require('path')
const fs = require('fs')
const _ = require("underscore")
const open = require('open');
const childProcess = require('child_process');
const http = require('http');
const packageJson = JSON.parse(fs.readFileSync("package.json"))
@ -20,6 +22,8 @@ const tempJsonText = JSON.parse(fs.readFileSync("config.json", "utf8"));
configObject = _.extend(configObject, tempJsonText);
fs.writeFileSync("config.json", JSON.stringify(configObject));
let serverStatus = "Starting"
const processArgs = process.argv;
// Check if --headless is passed as an argument
if (processArgs.includes("--headless")) {
@ -31,11 +35,29 @@ if (processArgs.includes("--headless")) {
startServer()
createTray()
createWindow()
setInterval(() => {
http.get('http://127.0.0.1:' + configObject.port + "/api/v1/system", (resp) => {
let data = '';
// A chunk of data has been received.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
let parsed = JSON.parse(data)
serverStatus = "Running"
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}, 1000);
})
ipcMain.on('info', function () {
if (win) {
win.webContents.send('info', { "appStatus": "Testing", "appURL": "http://127.0.0.1:" + configObject.port, "appName": "openCountdown " + packageJson.version, "startMinimised": configObject.startMinimised, "port": configObject.port })
win.webContents.send('info', { "appStatus": serverStatus, "appURL": "http://127.0.0.1:" + configObject.port, "appName": "openCountdown " + packageJson.version, "startMinimised": configObject.startMinimised, "port": configObject.port })
}
})
@ -62,7 +84,8 @@ if (processArgs.includes("--headless")) {
fs.writeFileSync("config.json", JSON.stringify(configObject));
dialog.showMessageBoxSync({
message: "Port changed. Restart openCountdown to apply change.",
buttons: ["OK"]})
buttons: ["OK"]
})
})
}