Allow loading and running cfg file from argument

This commit is contained in:
2026-06-13 16:03:28 +02:00
parent a3f810ac71
commit 5f2f76a7d3
2 changed files with 46 additions and 7 deletions
+19 -7
View File
@@ -120,6 +120,19 @@ function fallbackBrowseForFolder() {
picker.click();
}
function loadConfigFile(filename, autoRun = false) {
console.log('Open file ' + filename);
fs.readFile(filename.toString(), function read(err, data) {
if (err) {
throw err;
}
setValues(data);
if (autoRun) {
setTimeout(() => startSim(), 0);
}
});
}
function firstLoad() {
document.getElementById("trimPath").value = process.cwd();
if (typeof syncStatusBar === 'function') {
@@ -140,13 +153,12 @@ function firstLoad() {
// Catch calls for open file
ipcRenderer.on('openFile', function(event, filename) {
console.log('Open file '+filename);
fs.readFile(filename.toString(), function read(err, data) {
if (err) {
throw err;
}
setValues(data);
});
loadConfigFile(filename, false);
});
ipcRenderer.on('openFileAndMaybeRun', function(event, payload) {
if (!payload || !payload.filename) { return; }
loadConfigFile(payload.filename, !!payload.autoRun);
});
// Catch calls for selectfolder
+27
View File
@@ -2,9 +2,27 @@ const path = require('path');
const { app, BrowserWindow, Menu, dialog, ipcMain, fs } = require('electron');
let currentWorkPath = process.cwd();
const startupOptions = parseStartupOptions(process.argv);
app.setName('TrimSP');
function parseStartupOptions(argv) {
const options = {
configPath: null,
autoRun: false,
};
for (const arg of argv.slice(1)) {
if (arg === '--run') {
options.autoRun = true;
} else if (!arg.startsWith('--') && options.configPath == null) {
options.configPath = path.resolve(arg);
}
}
return options;
}
function showAboutDialog(parentWindow) {
const detail = [
'TRIM.SP simulation GUI for low-energy ion implantation studies.',
@@ -67,6 +85,15 @@ function createWindow () {
}
})
win.webContents.on('did-finish-load', () => {
if (startupOptions.configPath) {
win.webContents.send('openFileAndMaybeRun', {
filename: startupOptions.configPath,
autoRun: startupOptions.autoRun,
});
}
});
let template = [
{