Add proper Electron launcher and building process #6
@ -22,13 +22,13 @@ const tempJsonText = JSON.parse(fs.readFileSync("config.json", "utf8"));
|
|||||||
configObject = _.extend(configObject, tempJsonText);
|
configObject = _.extend(configObject, tempJsonText);
|
||||||
fs.writeFileSync("config.json", JSON.stringify(configObject));
|
fs.writeFileSync("config.json", JSON.stringify(configObject));
|
||||||
|
|
||||||
|
// Set a serverStatus
|
||||||
let serverStatus = "Starting"
|
let serverStatus = "Starting"
|
||||||
|
|
||||||
const processArgs = process.argv;
|
|
||||||
// Check if --headless is passed as an argument
|
// Check if --headless is passed as an argument
|
||||||
|
const processArgs = process.argv;
|
||||||
if (processArgs.includes("--headless")) {
|
if (processArgs.includes("--headless")) {
|
||||||
startServer()
|
startServer()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Start electron
|
// Start electron
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
@ -36,6 +36,7 @@ if (processArgs.includes("--headless")) {
|
|||||||
createTray()
|
createTray()
|
||||||
createWindow()
|
createWindow()
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
// Check if the server is running
|
||||||
http.get('http://127.0.0.1:' + configObject.port + "/api/v1/system", (resp) => {
|
http.get('http://127.0.0.1:' + configObject.port + "/api/v1/system", (resp) => {
|
||||||
let data = '';
|
let data = '';
|
||||||
|
|
||||||
@ -46,16 +47,23 @@ if (processArgs.includes("--headless")) {
|
|||||||
|
|
||||||
// The whole response has been received. Print out the result.
|
// The whole response has been received. Print out the result.
|
||||||
resp.on('end', () => {
|
resp.on('end', () => {
|
||||||
|
// If we have a valid response, set the serverStatus to "Running"
|
||||||
let parsed = JSON.parse(data)
|
let parsed = JSON.parse(data)
|
||||||
|
console.log(parsed)
|
||||||
serverStatus = "Running"
|
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) => {
|
}).on("error", (err) => {
|
||||||
console.log("Error: " + err.message);
|
console.log("Error: " + err.message);
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 2000);
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('info', function () {
|
ipcMain.on('info', function () {
|
||||||
|
// Send inital data to the window
|
||||||
if (win) {
|
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 })
|
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)
|
let response = dialog.showMessageBoxSync(options)
|
||||||
if (response == 0) {
|
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")
|
srvProc.kill("SIGINT")
|
||||||
setTimeout(app.quit, 1000)
|
setTimeout(app.quit, 1000)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user