Windows 7 x64, nwjs 0.19.4
Minimize to tray works fine without setting window.location.href, but when set nwjs will not minimize to tray.
Revised Code Per Request:
index.html
<html>
<body>
<div></div>
<script>
// Load library
var gui = require('nw.gui');
// Reference to window and tray
var win = gui.Window.get();
var tray;
onload = function () {
window.location.href = "http://iheartradio.com"
};
// Get the minimize event
win.on('minimize', function () {
// Hide window
win.hide();
var tray = new nw.Tray({
title: 'Web Music Player',
icon: 'img/music.png'
});
// Show window and remove tray when clicked
tray.on('click', function () {
win.show();
this.remove();
tray = null;
});
});
</script>
</body>
</html>
package.json
{
"name": "webmusicplayer",
"version": "0.1.0",
"main": "index.html",
"single-instance": true,
"window": {
"title": "webmusicplayer",
"min_width": 1200,
"min_height": 600
},
"webkit": {
"plugin": true
},
"chromium-args": "--load-plugin=ffmpegsumo.dll --child-clean-exit --disable-direct-composition --allow-running-insecure-content --no-proxy-server --enable-video-player-chromecast-support"
}
Main issue with your code is that you are registering maximize event on window object after that you are reloading using window.location, so your javascript code will be removed and garbage collected.
You need to inject your js code after every reload, you can use inject_js_start or inject_js_end config of package.json to make sure you script is preserved on every reload
Below is the full working code as per your requirement
home.html
package.json
NWInit.js