The main problem with your code is that you are registering the maximum event in the window object after a reboot using window.location, so your javascript code will be deleted and garbage collected.
js- ,
inject_js_start inject_js_end config.json, , script
home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Tray Demo</title>
<script type="text/javascript">
console.log('redirecting the page');
window.location.href = 'http://www.microsoft.com';
</script>
</head>
<body>
<p>redirecting the page...</p>
</body>
</html>
package.json
{
"main": "home.html",
"name": "tray-demo",
"description": "tray demo for windows",
"version": "1.0",
"inject_js_start": "NWInit.js",
"window": {
"title": "Tray Demo",
"resizable": true,
"show_in_taskbar": true
},
"webkit": {
"plugin": true
},
"node-remote": "*://*"
}
NWInit.js
if(typeof nw != 'undefined') {
NWInit = {
initApp: function() {
console.log('init app called');
var win = nw.Window.get();
win.showDevTools();
win.on('minimize', function() {
console.log('minimize called');
if(typeof nw.Tray == 'undefined') {
return;
}
win.hide();
var tray = new nw.Tray({
title: 'Web Music Player',
icon: 'img/music.png'
});
tray.on('click', function() {
console.log('tray clicked');
win.show();
tray.remove();
tray = null;
});
});
}
};
NWInit.initApp();
}