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 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"]
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -131,21 +154,21 @@ function createTray() {
|
||||
});
|
||||
}
|
||||
|
||||
function showScreen(){
|
||||
function showScreen() {
|
||||
win.show()
|
||||
}
|
||||
|
||||
function launchUI(){
|
||||
function launchUI() {
|
||||
open("http://127.0.0.1:" + configObject.port)
|
||||
}
|
||||
|
||||
function trayQuit(){
|
||||
function trayQuit() {
|
||||
let options = {
|
||||
buttons: ["Yes","No"],
|
||||
buttons: ["Yes", "No"],
|
||||
message: "Do you really want to quit openCountdown?"
|
||||
}
|
||||
let response = dialog.showMessageBoxSync(options)
|
||||
if(response == 0){
|
||||
if (response == 0) {
|
||||
srvProc.kill("SIGINT")
|
||||
setTimeout(app.quit, 1000)
|
||||
}
|
||||
@ -180,11 +203,11 @@ function runScript(scriptPath, callback, valueCb) {
|
||||
|
||||
srvProc = null;
|
||||
|
||||
function setServer(process){
|
||||
function setServer(process) {
|
||||
srvProc = process
|
||||
}
|
||||
|
||||
function startServer(){
|
||||
function startServer() {
|
||||
runScript(path.join(__dirname, 'index.js'), function (err) {
|
||||
if (err) throw err;
|
||||
}, setServer)
|
||||
|
Loading…
Reference in New Issue
Block a user