Making IPC port kwarg configurable; improving kwarhs filter out
This commit is contained in:
parent
c5fdab59f6
commit
080cc22841
@ -1,9 +1,10 @@
|
||||
const { app } = require('electron');
|
||||
|
||||
|
||||
let startType = "build";
|
||||
let isDebug = false;
|
||||
let args = [];
|
||||
let startType = "build";
|
||||
let ipcPort = "4563";
|
||||
let isDebug = false;
|
||||
let args = [];
|
||||
|
||||
|
||||
|
||||
@ -17,6 +18,13 @@ const loadKWArgs = () => {
|
||||
console.log(startType);
|
||||
}
|
||||
|
||||
const hasIpcPort = app.commandLine.hasSwitch("ipc-port");
|
||||
if (hasIpcPort) {
|
||||
ipcPort = app.commandLine.getSwitchValue("ipc-port");
|
||||
console.log("Has ipc-port switch...");
|
||||
console.log(ipcPort);
|
||||
}
|
||||
|
||||
const hasDebug = app.commandLine.hasSwitch("app-debug");
|
||||
if (hasDebug) {
|
||||
isDebug = app.commandLine.getSwitchValue("app-debug");
|
||||
@ -25,38 +33,29 @@ const loadKWArgs = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadVArgs = () => {
|
||||
console.log("\n\nStart VArgs:");
|
||||
|
||||
const filterOutLaunchAndKWArgs = () => {
|
||||
if (
|
||||
process.argv[0].endsWith("electron")
|
||||
) {
|
||||
process.argv = process.argv.slice(2);
|
||||
}
|
||||
|
||||
if (
|
||||
process.argv[0].endsWith("/newton") ||
|
||||
process.argv[0].endsWith(".AppImage")
|
||||
) {
|
||||
do {
|
||||
process.argv = process.argv.slice(1);
|
||||
}
|
||||
|
||||
if ( process.argv.length > 0 && (
|
||||
process.argv[0].includes("--trace-warnings") ||
|
||||
process.argv[0].includes("--start-as")
|
||||
} while (
|
||||
process.argv.length > 0 &&
|
||||
(
|
||||
process.argv[0].endsWith("/newton") ||
|
||||
process.argv[0].endsWith(".AppImage") ||
|
||||
process.argv[0].includes("--trace-warnings") ||
|
||||
process.argv[0].includes("--start-as") ||
|
||||
process.argv[0].includes("--ipc-port")
|
||||
)
|
||||
) {
|
||||
process.argv = process.argv.slice(1);
|
||||
}
|
||||
|
||||
if ( process.argv.length > 0 && (
|
||||
process.argv[0].includes("--trace-warnings") ||
|
||||
process.argv[0].includes("--start-as")
|
||||
)
|
||||
) {
|
||||
process.argv = process.argv.slice(1);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const loadVArgs = () => {
|
||||
console.log("\n\nStart VArgs:");
|
||||
args = process.argv;
|
||||
args.forEach((val, index, array) => {
|
||||
console.log(index + ': ' + val);
|
||||
@ -67,6 +66,7 @@ const loadVArgs = () => {
|
||||
|
||||
const loadArgs = () => {
|
||||
loadKWArgs();
|
||||
filterOutLaunchAndKWArgs();
|
||||
loadVArgs();
|
||||
}
|
||||
|
||||
@ -83,6 +83,10 @@ const getDebugMode = () => {
|
||||
return isDebug;
|
||||
}
|
||||
|
||||
const getIpcPort = () => {
|
||||
return ipcPort;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
argsParser: {
|
||||
@ -90,5 +94,6 @@ module.exports = {
|
||||
getArgs: getArgs,
|
||||
getStartType: getStartType,
|
||||
getDebugMode: getDebugMode,
|
||||
getIpcPort: getIpcPort,
|
||||
}
|
||||
};
|
@ -8,12 +8,17 @@ const fetch = require('electron-fetch').default
|
||||
const IPC_SERVER_IP = "127.0.0.1";
|
||||
let window = null;
|
||||
let ipcServer = null;
|
||||
let ipcServerPort = "4563";
|
||||
let ipcServerURL = `http://${IPC_SERVER_IP}:${ipcServerPort}`;
|
||||
let ipcServerPort = "";
|
||||
let ipcServerURL = "";
|
||||
|
||||
|
||||
const setWindow = (win) => {
|
||||
window = win;
|
||||
window = win;
|
||||
}
|
||||
|
||||
const configure = (ipcPort) => {
|
||||
ipcServerPort = ipcPort;
|
||||
ipcServerURL = `http://${IPC_SERVER_IP}:${ipcServerPort}`;
|
||||
}
|
||||
|
||||
const loadIPCServer = (fpath) => {
|
||||
@ -47,7 +52,8 @@ const loadIPCServer = (fpath) => {
|
||||
}
|
||||
|
||||
const isIPCServerUp = async () => {
|
||||
const response = await fetch(`${ipcServerURL}/is-up`).catch((err) => {
|
||||
const response = await fetch(`${ipcServerURL}/is-up`)
|
||||
.catch((err) => {
|
||||
console.debug("IPCServer (status) : Not up; okay to start.");
|
||||
return {
|
||||
text: () => {
|
||||
@ -73,9 +79,10 @@ const sendFilesToIPC = async (files) => {
|
||||
|
||||
module.exports = {
|
||||
newtonIPC: {
|
||||
setWindow: setWindow,
|
||||
configure: configure,
|
||||
loadIPCServer: loadIPCServer,
|
||||
isIPCServerUp: isIPCServerUp,
|
||||
sendFilesToIPC: sendFilesToIPC,
|
||||
setWindow: setWindow
|
||||
}
|
||||
};
|
@ -80,6 +80,7 @@ app.whenReady().then(async () => {
|
||||
loadProcessSignalHandlers();
|
||||
newton.args.loadArgs();
|
||||
|
||||
newton.ipc.configure( newton.args.getIpcPort() );
|
||||
if ( !await newton.ipc.isIPCServerUp() ) {
|
||||
newton.ipc.loadIPCServer();
|
||||
} else {
|
||||
|
@ -9,8 +9,8 @@
|
||||
"main": "newton/main.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"app": "ng build --base-href ./ && electron . --trace-warnings --start-as=build",
|
||||
"electron-start": "electron . --trace-warnings --start-as=build",
|
||||
"app": "ng build --base-href ./ && electron . --trace-warnings --start-as=build --ipc-port=4588",
|
||||
"electron-start": "electron . --trace-warnings --start-as=build --ipc-port=4588",
|
||||
"electron-pack": "ng build --base-href ./ && electron-builder --dir",
|
||||
"electron-dist": "ng build --base-href ./ && electron-builder",
|
||||
"electron-dist-linux": "ng build --base-href ./ && electron-builder --linux deb zip AppImage",
|
||||
|
Loading…
Reference in New Issue
Block a user