Making IPC port kwarg configurable; improving kwarhs filter out

This commit is contained in:
itdominator 2025-07-14 23:00:36 -05:00
parent c5fdab59f6
commit 080cc22841
4 changed files with 46 additions and 33 deletions

View File

@ -2,6 +2,7 @@ const { app } = require('electron');
let startType = "build"; let startType = "build";
let ipcPort = "4563";
let isDebug = false; let isDebug = false;
let args = []; let args = [];
@ -17,6 +18,13 @@ const loadKWArgs = () => {
console.log(startType); 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"); const hasDebug = app.commandLine.hasSwitch("app-debug");
if (hasDebug) { if (hasDebug) {
isDebug = app.commandLine.getSwitchValue("app-debug"); isDebug = app.commandLine.getSwitchValue("app-debug");
@ -25,38 +33,29 @@ const loadKWArgs = () => {
} }
} }
const loadVArgs = () => { const filterOutLaunchAndKWArgs = () => {
console.log("\n\nStart VArgs:");
if ( if (
process.argv[0].endsWith("electron") process.argv[0].endsWith("electron")
) { ) {
process.argv = process.argv.slice(2); process.argv = process.argv.slice(2);
} }
if ( do {
process.argv = process.argv.slice(1);
} while (
process.argv.length > 0 &&
(
process.argv[0].endsWith("/newton") || process.argv[0].endsWith("/newton") ||
process.argv[0].endsWith(".AppImage") process.argv[0].endsWith(".AppImage") ||
) {
process.argv = process.argv.slice(1);
}
if ( process.argv.length > 0 && (
process.argv[0].includes("--trace-warnings") || process.argv[0].includes("--trace-warnings") ||
process.argv[0].includes("--start-as") 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 = process.argv;
args.forEach((val, index, array) => { args.forEach((val, index, array) => {
console.log(index + ': ' + val); console.log(index + ': ' + val);
@ -67,6 +66,7 @@ const loadVArgs = () => {
const loadArgs = () => { const loadArgs = () => {
loadKWArgs(); loadKWArgs();
filterOutLaunchAndKWArgs();
loadVArgs(); loadVArgs();
} }
@ -83,6 +83,10 @@ const getDebugMode = () => {
return isDebug; return isDebug;
} }
const getIpcPort = () => {
return ipcPort;
}
module.exports = { module.exports = {
argsParser: { argsParser: {
@ -90,5 +94,6 @@ module.exports = {
getArgs: getArgs, getArgs: getArgs,
getStartType: getStartType, getStartType: getStartType,
getDebugMode: getDebugMode, getDebugMode: getDebugMode,
getIpcPort: getIpcPort,
} }
}; };

View File

@ -8,14 +8,19 @@ const fetch = require('electron-fetch').default
const IPC_SERVER_IP = "127.0.0.1"; const IPC_SERVER_IP = "127.0.0.1";
let window = null; let window = null;
let ipcServer = null; let ipcServer = null;
let ipcServerPort = "4563"; let ipcServerPort = "";
let ipcServerURL = `http://${IPC_SERVER_IP}:${ipcServerPort}`; let ipcServerURL = "";
const setWindow = (win) => { const setWindow = (win) => {
window = win; window = win;
} }
const configure = (ipcPort) => {
ipcServerPort = ipcPort;
ipcServerURL = `http://${IPC_SERVER_IP}:${ipcServerPort}`;
}
const loadIPCServer = (fpath) => { const loadIPCServer = (fpath) => {
const app = express(); const app = express();
@ -47,7 +52,8 @@ const loadIPCServer = (fpath) => {
} }
const isIPCServerUp = async () => { 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."); console.debug("IPCServer (status) : Not up; okay to start.");
return { return {
text: () => { text: () => {
@ -73,9 +79,10 @@ const sendFilesToIPC = async (files) => {
module.exports = { module.exports = {
newtonIPC: { newtonIPC: {
setWindow: setWindow, configure: configure,
loadIPCServer: loadIPCServer, loadIPCServer: loadIPCServer,
isIPCServerUp: isIPCServerUp, isIPCServerUp: isIPCServerUp,
sendFilesToIPC: sendFilesToIPC, sendFilesToIPC: sendFilesToIPC,
setWindow: setWindow
} }
}; };

View File

@ -80,6 +80,7 @@ app.whenReady().then(async () => {
loadProcessSignalHandlers(); loadProcessSignalHandlers();
newton.args.loadArgs(); newton.args.loadArgs();
newton.ipc.configure( newton.args.getIpcPort() );
if ( !await newton.ipc.isIPCServerUp() ) { if ( !await newton.ipc.isIPCServerUp() ) {
newton.ipc.loadIPCServer(); newton.ipc.loadIPCServer();
} else { } else {

View File

@ -9,8 +9,8 @@
"main": "newton/main.js", "main": "newton/main.js",
"private": true, "private": true,
"scripts": { "scripts": {
"app": "ng build --base-href ./ && 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", "electron-start": "electron . --trace-warnings --start-as=build --ipc-port=4588",
"electron-pack": "ng build --base-href ./ && electron-builder --dir", "electron-pack": "ng build --base-href ./ && electron-builder --dir",
"electron-dist": "ng build --base-href ./ && electron-builder", "electron-dist": "ng build --base-href ./ && electron-builder",
"electron-dist-linux": "ng build --base-href ./ && electron-builder --linux deb zip AppImage", "electron-dist-linux": "ng build --base-href ./ && electron-builder --linux deb zip AppImage",