Add proper Electron launcher and building process #6
@ -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 path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const _ = require("underscore")
|
const _ = require("underscore")
|
||||||
const open = require('open');
|
const open = require('open');
|
||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
|
||||||
const packageJson = JSON.parse(fs.readFileSync("package.json"))
|
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);
|
configObject = _.extend(configObject, tempJsonText);
|
||||||
fs.writeFileSync("config.json", JSON.stringify(configObject));
|
fs.writeFileSync("config.json", JSON.stringify(configObject));
|
||||||
|
|
||||||
|
let serverStatus = "Starting"
|
||||||
|
|
||||||
const processArgs = process.argv;
|
const processArgs = process.argv;
|
||||||
// Check if --headless is passed as an argument
|
// Check if --headless is passed as an argument
|
||||||
if (processArgs.includes("--headless")) {
|
if (processArgs.includes("--headless")) {
|
||||||
@ -31,11 +35,29 @@ if (processArgs.includes("--headless")) {
|
|||||||
startServer()
|
startServer()
|
||||||
createTray()
|
createTray()
|
||||||
createWindow()
|
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 () {
|
ipcMain.on('info', function () {
|
||||||
if (win) {
|
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));
|
fs.writeFileSync("config.json", JSON.stringify(configObject));
|
||||||
dialog.showMessageBoxSync({
|
dialog.showMessageBoxSync({
|
||||||
message: "Port changed. Restart openCountdown to apply change.",
|
message: "Port changed. Restart openCountdown to apply change.",
|
||||||
buttons: ["OK"]})
|
buttons: ["OK"]
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user