// Copyright (C) 2026 Zaher Salman // SPDX-License-Identifier: GPL-3.0-or-later // The hardened build runs with nodeIntegration:false, so ipc comes from the // preload bridge (window.electronAPI). require() is a last-resort fallback. const ipcRenderer = (window.electronAPI && window.electronAPI.ipc) || require("electron").ipcRenderer; if (!window.MusrfitParameterPlotPlatform) window.MusrfitParameterPlotPlatform = {}; // In Electron the operating-system BrowserWindow is the plot window. The // shared renderer therefore receives only a content host and never creates or // manages a second in-page window shell. window.MusrfitParameterPlotPlatform.createPlotWindow = function() { document.body.textContent = ""; const content = document.createElement("div"); content.className = "parameter-plot-content"; document.body.appendChild(content); const closeHandlers = []; let closed = false; window.addEventListener("beforeunload", function() { if (closed) return; closed = true; for (const handler of closeHandlers) handler(); }, { once: true }); return { root: document.body, content: content, keyTarget: document, close: function() { window.close(); }, onClose: function(handler) { if (typeof handler === "function") closeHandlers.push(handler); }, show: function() {} }; }; // The bridge delivers only the payload (no event wrapper); legacy ipcRenderer // passes the event first. Normalize so both call shapes hand options to the // shared renderer unchanged. ipcRenderer.on("parameterPlotData", function() { let options = (arguments.length > 0 && arguments[0] && arguments[0].sender) ? arguments[1] : arguments[0]; options = options || {}; document.title = options.jobName ? "Parameters: " + options.jobName : "Parameter plot"; showMusrfitParameterPlotWindow( options.parameterPath || "", options.jobName || "", Array.isArray(options.preferredParameters) ? options.preferredParameters : [], options.preferredXColumn || "", options.preferredTemplate || "", options.preferredLayoutMode || "", options.savedState || null ); });