I'm making an electron project with multiple windows. One of these is a popup window that appears whenever errors/etc happen with the main window. I'm trying to write my code so that this popup window can change its text depending on what causes it to appear.
As it worked previously, I defined the main BrowserWindow object in the main.js file, and all other BrowserWindow objects in the index.js file. This all functioned as it should have. I tried using IPC renderers to communicate to the popup window, only I needed to have a reference to its BrowserWindow in the same file as the ipcMain. That meant I had to move the code that initializes that BrowserWindow from index.js to main.js. The issue is that as soon as I did so, the popup window would only render completely blank. Why is that? If it helps, here is the code for the BrowserWindow I want to be able to reference in the main file...
const modalPath = path.join('file://', __dirname, 'popup.html');
let win2 = new BrowserWindow({
frame: false,
alwaysOnTop: true,
width: 400,
height: 200 });
win2.on('close', function () { win = null });
win2.loadURL(modalPath);
win2.show();
Note that the above code works exactly as intended if it's placed within my index.js file. It only doesn't work when I use it in the main.js file, which is where (I think) I need it to be to reference it for the ipcMain object to send a message to the window.