Reference to a window after reloading is broken
See original GitHub issueIn my test app i open a window on app start
nw.Window.open(nw.App.manifest.onlineURL, windowProperties, function (win) { win.on('close', function (shouldQuit) { if (shouldQuit) { nw.App.quit(); } else { win.hide() }; }); nw.App.on('reopen', function () { win.show(); }); tray.on('click', function () { win.show(); }); win.window.onload = function (){ setTimeout(function(){ win.window.location.href = nw.App.manifest.onlineURL; }, 5000); } });
And i have a Tray click handler.
After reloading the window tray.on('click) does not work. The window is hidden and i do not have any reference to it.
NW 0.14.2 Windows 10 x64. My test app: test_app.zip
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (4 by maintainers)
Top GitHub Comments
@franchuk Have you managed to fix this? I create the window in the init script (main: index.js on package.json) and keep the reference to it. After navigating to another page, the window reference is broken and the close event is cleared. I have tray with menu on the background page. I’m using the latest stable version of nw.js.
@ghostoy and @rogerwang Any recommendations?
Thanks for your help.
Can you please provide more information like when does the file that contains the above code is executed? When do you inject the file that contains your tray’s code? I did face the same issue and the reason is when you reload or navigate, your functions and variables are likely to get GCed. So you are gonna have to write your tray related code in background context, which stays there for your app’s lifetime. See manifest format and use bgscript in your package.json to include your tray file. I hope it helps. Cheers. 😃