Add debug logging across the Open/Save MSR dialog chain

The bridge readFile fix now logs bytes read in the renderer console, the
renderer open handler logs each step (received path, read result, editor
load, tab switch), and main.js logs the dialog selection/cancel. The
renderer handler also takes the first element when Electron forwards the
filePaths array instead of relying on toString(). These messages make a
packaged-app open failure diagnosable from the renderer console.
This commit is contained in:
salman committed 2026-09-07 18:37:01 +02:00
1 parent 37a54984bd
commit e511c20ab5
3 files changed
+71 -9

No files matched your search

+52 -4
View File
@@ -3,6 +3,7 @@
const { app, BrowserWindow, Menu, dialog, ipcMain, screen, shell } = require('electron');
const path = require('path');
const fs = require('fs');
const childProcess = require('child_process');
// An SSH-forwarded X display belongs to the remote client, but pc13280 also
@@ -39,6 +40,43 @@ if (forwardedX11 && process.env.DBUS_SESSION_BUS_ADDRESS
const parameterPlotWindows = new Set();
let quickStartWindow = null;
// Remember the last folder used by the Open/Save MSR dialogs, so a repeated
// open or save starts where the previous one finished instead of the process
// working directory. The remember is a tiny JSON file under userData; if it is
// missing or the directory no longer exists the dialogs fall back to ".".
function lastMSRDirectoryFile() {
return path.join(app.getPath("userData"), "last-msr-directory.json");
}
let rememberedMSRDirectory = "";
function loadRememberedMSRDirectory() {
try {
const content = fs.readFileSync(lastMSRDirectoryFile(), "utf8");
const saved = JSON.parse(content);
const directory = saved && saved.directory ? String(saved.directory) : "";
if (directory && fs.existsSync(directory) && fs.statSync(directory).isDirectory()) {
rememberedMSRDirectory = directory;
}
} catch (error) {
rememberedMSRDirectory = "";
}
return rememberedMSRDirectory;
}
function rememberMSRDirectory(directory) {
if (!directory) {
return;
}
rememberedMSRDirectory = directory;
try {
fs.mkdirSync(app.getPath("userData"), { recursive: true });
fs.writeFileSync(lastMSRDirectoryFile(), JSON.stringify({ directory: directory }));
} catch (error) {
console.log(error);
}
}
function msrDialogDirectory() {
return rememberedMSRDirectory || ".";
}
function createAuxiliaryWindow(options = {}) {
const auxiliaryWindow = new BrowserWindow({
title: options.title || "muSRFlow",
@@ -146,6 +184,8 @@ function createWindow () {
}
})
loadRememberedMSRDirectory();
const template = [
{
@@ -157,7 +197,7 @@ function createWindow () {
click () {
dialog.showOpenDialog(win, {
title: "Open MSR file",
defaultPath: "./",
defaultPath: msrDialogDirectory(),
filters: [
{name: 'MSR files', extensions: ['msr']},
{name: 'All Files', extensions: ['*']}
@@ -165,10 +205,14 @@ function createWindow () {
properties: ['openFile']
}).then(result => {
if (!result.canceled && result.filePaths.length) {
rememberMSRDirectory(path.dirname(result.filePaths[0]));
console.log("[openMSR] dialog selected " + result.filePaths[0]);
win.webContents.send('openFile', result.filePaths);
} else {
console.log("[openMSR] dialog canceled or empty");
}
}).catch(err => {
console.log(err);
console.log("[openMSR] dialog error: " + err);
});
}
},
@@ -194,7 +238,7 @@ function createWindow () {
click () {
dialog.showSaveDialog(win, {
title: "Save MSR file",
defaultPath: "./",
defaultPath: msrDialogDirectory(),
filters: [
{name: 'MSR files', extensions: ['msr']},
{name: 'All Files', extensions: ['*']}
@@ -202,10 +246,14 @@ function createWindow () {
properties: ['showOverwriteConfirmation']
}).then(result => {
if (!result.canceled && result.filePath) {
rememberMSRDirectory(path.dirname(result.filePath));
console.log("[saveMSR] dialog selected " + result.filePath);
win.webContents.send('saveFile', result.filePath);
} else {
console.log("[saveMSR] dialog canceled");
}
}).catch(err => {
console.log(err);
console.log("[saveMSR] dialog error: " + err);
});
}
},
+12 -2
View File
@@ -1492,11 +1492,14 @@ function firstLoad() {
// Catch calls for open file
electronIpcRenderer.on('openFile', function(filename) {
const filePath = filename.toString();
const filePath = Array.isArray(filename) ? filename[0] : filename.toString();
console.log("[renderer.openFile] received path: " + filePath);
nodeFs.readFile(filePath, "utf8", function read(err, data) {
if (err) {
console.error("[renderer.openFile] read error: " + (err && err.message ? err.message : err));
throw err;
}
console.log("[renderer.openFile] read " + (data ? data.length : 0) + " bytes for " + filePath);
if (typeof loadMSRIntoEditor === "function") {
// A manually opened file is its own editor source. Clear any global-fit
// template tab that may have been left by the previous generated job.
@@ -1518,8 +1521,15 @@ function firstLoad() {
}
window.MSREditor.templateDirty = false;
}
loadMSRIntoEditor(data.toString(), filePath, true, { editorOwned: true });
try {
loadMSRIntoEditor(data.toString(), filePath, true, { editorOwned: true });
console.log("[renderer.openFile] loaded into editor: " + filePath);
} catch (error) {
console.error("[renderer.openFile] loadMSRIntoEditor failed: "
+ (error && error.stack ? error.stack : error));
}
openTab(null, "Editor");
console.log("[renderer.openFile] switched to Editor tab");
}
});
});
+7 -3
View File
@@ -122,9 +122,13 @@ const bridge = {
});
},
readFile: function (p, encoding, callback) {
fs.readFile(p, encoding, function (err, data) {
if (typeof callback === "function") callback(err ? { message: err.message } : null, data);
});
if (typeof callback === "function") {
fs.readFile(p, encoding, function (err, data) {
console.log("[bridge.readFile] " + p
+ (err ? " error: " + err.message : " ok " + (data ? data.length : 0) + " bytes"));
callback(err ? { message: err.message } : null, data);
});
}
},
constants: {
O_WRONLY: fs.constants.O_WRONLY,