I'm creating an app that can go back and forth between Window 1 to Window 2. I keep both windows open but hide the one not currently in use using currentWindow.hide(). I want to increment a counter each time I come into Window 2. I tried to use the code from Using ipc in Electron to set global variable from renderer to set a global variable and increment it each time I come into Window 2:
main.js
ipcMain.on('setMyGlobalVariable', (event, myGlobalVariableValue) => {
global.myGlobalVariable = myGlobalVariableValue;
});
renderer.js
lv = remote.getGlobal("MyGlobalVariable"); // Read
if (lv = null) lv = 0;
lv = lv + 1;
console.log(lv);
ipcRenderer.send("setMyGlobalVariable", lv); // Store New Value
Unfortunately, every time I come back to window 2, lv is null! Can this be done, or am I doing something wrong?