diff --git a/newton/app.js b/newton/app.js index 0ff65c0..76370db 100644 --- a/newton/app.js +++ b/newton/app.js @@ -2,6 +2,7 @@ const { BrowserWindow } = require('electron'); const path = require('node:path'); const { menu } = require('./menu'); +const { argsParser } = require('./args-parser'); const { settingsManager } = require('./settings-manager'); const { newtonFs } = require('./fs'); @@ -72,7 +73,6 @@ const createWindow = (startType = "build", debug = false, args = []) => { // }); return win; - } @@ -80,7 +80,8 @@ const createWindow = (startType = "build", debug = false, args = []) => { module.exports = { newton: { createWindow: createWindow, + args: argsParser, + settings: settingsManager, fs: newtonFs, - settings: settingsManager } }; \ No newline at end of file diff --git a/newton/args-parser.js b/newton/args-parser.js new file mode 100644 index 0000000..87e9d2f --- /dev/null +++ b/newton/args-parser.js @@ -0,0 +1,94 @@ +const { app } = require('electron'); + + +let startType = "build"; +let isDebug = false; +let args = []; + + + +const loadKWArgs = () => { + console.log("\n\nStart KWArgs:"); + + const hasStartAs = app.commandLine.hasSwitch("start-as"); + if (hasStartAs) { + startType = app.commandLine.getSwitchValue("start-as"); + console.log("Has start-as switch..."); + console.log(startType); + } + + const hasDebug = app.commandLine.hasSwitch("app-debug"); + if (hasDebug) { + isDebug = app.commandLine.getSwitchValue("app-debug"); + console.log("Has app-debug switch..."); + console.log(isDebug); + } +} + +const loadVArgs = () => { + console.log("\n\nStart VArgs:"); + + if ( + process.argv[0].endsWith("electron") + ) { + process.argv = process.argv.slice(2); + } + + if ( + process.argv[0].endsWith("/newton") || + 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("--start-as") + ) + ) { + 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); + } + + args = process.argv; + args.forEach((val, index, array) => { + console.log(index + ': ' + val); + }); + + console.log("\n\n"); +} + +const loadArgs = () => { + loadKWArgs(); + loadVArgs(); +} + + +const getArgs = () => { + return args; +} + +const getStartType = () => { + return startType; +} + +const debugMode = () => { + return isDebug; +} + + +module.exports = { + argsParser: { + loadArgs: loadArgs, + getArgs: getArgs, + getStartType: getStartType, + debugMode: debugMode, + } +}; \ No newline at end of file diff --git a/newton/main.js b/newton/main.js index 64e1462..1c99b05 100644 --- a/newton/main.js +++ b/newton/main.js @@ -9,37 +9,6 @@ const { newton } = require('./app'); -let startType = ""; -let isDebug = false; -let args = []; - - - -const loadArgs = () => { - console.log("\n\nStart KArgs:"); - const hasStartAs = app.commandLine.hasSwitch("start-as"); - if (hasStartAs) { - startType = app.commandLine.getSwitchValue("start-as"); - console.log("Has start-as switch..."); - console.log(startType); - } - - const hasDebug = app.commandLine.hasSwitch("app-debug"); - if (hasDebug) { - isDebug = app.commandLine.getSwitchValue("app-debug"); - console.log("Has app-debug switch..."); - console.log(isDebug); - } - - console.log("\n\nStart VArgs:"); - args = process.argv.slice(4); // remove up to --start-as ... - args.forEach((val, index, array) => { - console.log(index + ': ' + val); - }); - - console.log("\n\n"); -} - const loadHandlers = () => { ipcMain.handle('getLspConfigData', (eve) => newton.fs.getLspConfigData()); ipcMain.handle('getFileContents', (eve, file) => newton.fs.getFileContents(file)); @@ -50,17 +19,25 @@ const loadHandlers = () => { app.whenReady().then(() => { - loadArgs(); + newton.args.loadArgs(); loadHandlers(); newton.settings.loadsettings(); - let window = newton.createWindow(startType, isDebug, args); + let window = newton.createWindow( + newton.args.getStartType(), + newton.args.debugMode(), + newton.args.getArgs(), + ); newton.fs.setWindow(window); }); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { - newton.createWindow(startType, isDebug, args); + newton.createWindow( + newton.args.getStartType(), + newton.args.debugMode(), + newton.args.getArgs(), + ); }; });