Enable auto cfg loading and running from arguments.

This commit is contained in:
2026-06-13 16:37:16 +02:00
parent 5f2f76a7d3
commit dd7100d1d5
4 changed files with 74 additions and 20 deletions
+15 -13
View File
@@ -1,5 +1,6 @@
const path = require('path');
const { app, BrowserWindow, Menu, dialog, ipcMain, fs } = require('electron');
const fs = require('fs');
const { app, BrowserWindow, Menu, dialog, ipcMain } = require('electron');
let currentWorkPath = process.cwd();
const startupOptions = parseStartupOptions(process.argv);
@@ -12,11 +13,18 @@ function parseStartupOptions(argv) {
autoRun: false,
};
for (const arg of argv.slice(1)) {
for (const arg of argv.slice(2)) {
if (arg === '--run') {
options.autoRun = true;
} else if (!arg.startsWith('--') && options.configPath == null) {
options.configPath = path.resolve(arg);
const candidate = path.resolve(arg);
if (
path.extname(candidate).toLowerCase() === '.cfg' &&
fs.existsSync(candidate) &&
fs.statSync(candidate).isFile()
) {
options.configPath = candidate;
}
}
}
@@ -85,16 +93,6 @@ function createWindow () {
}
})
win.webContents.on('did-finish-load', () => {
if (startupOptions.configPath) {
win.webContents.send('openFileAndMaybeRun', {
filename: startupOptions.configPath,
autoRun: startupOptions.autoRun,
});
}
});
let template = [
{
label: 'File',
@@ -344,6 +342,10 @@ ipcMain.on('updateWorkPath', (event, folder) => {
}
});
ipcMain.handle('getStartupOptions', async () => {
return startupOptions;
});
//ipcMain.on('browseFolder-send', (event, args) => {
// dialog.showOpenDialog(null, args).then(filePaths => {
// event.sender.dend('browseFolder', filePaths);