Allow loading and running cfg file from argument
This commit is contained in:
+19
-7
@@ -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
|
||||
|
||||
@@ -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 = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user