I currently have a node-webkit app for Mac and Windows. When you close the window, the app keeps running in the background and can be reopened trough the system tray.
I would like to let my users open the window from the executable (think the shortcut to the .exe on the desktop).
On Mac, I did this to allow users to open the window from the Dock :
var gui = require('nw.gui');
gui.App.on('reopen', function() {
win.show();
});
But, according to the documentation, the 'reopen' event is a Mac only feature.
Is it possible to have the same behaviour on Windows ? How ?
Yes, there is no reopen feature provided for windows yet, but an alternative would be to use window.hide()
and tray features as described in Tray .
In my application I have created custom buttons for minimise, maximise and close and provided following functions for them:
var gui = require('nw.gui');
var window = gui.Window.get();
var isMaximised = false;
//Minimise:
minimise: function(){
window.hide();
var tray = new gui.Tray({title: 'Tray'});
var menuTray = new gui.Menu();
menuTray.append(new gui.MenuItem({ label : 'quit',
click: function(){
window.close();
}
}));
tray.menu = menuTray;
tray.on('click',function(){
tray.remove();
window.show();
tray = null;
});
}
//Maximise
maximise: function(){
if (isMaximized) {
isMaximized = false;
window.unmaximize();
} else {
isMaximized = true;
window.maximize();
}
}
//Close
close: function(){
window.hide();
var tray = new gui.Tray({title: 'Tray'});
var menuTray = new gui.Menu();
menuTray.append(new gui.MenuItem({ label : 'quit',
click: function(){
tray.remove();
window.close();
}
}));
tray.menu = menuTray;
tray.on('click',function(){
tray.remove();
window.show();
tray = null;
});
}
So on close of application by clicking close button, it hides app and creates a menuItem in tray(Dock). On click of icon in dock, it shows application back to user.
Only way application can be closed now is by doing a right-click on dock item and selecting quit button which closes application.
i had the issue and i have fix it using listen to open not reopen, here is simple code for your desktop case simple manifest Json "package.json" :
{
"main": "index.html",
"name": "reopen from Desktop",
"window":
{
"width": 300,
"height": 200
}
}
then a simple index.html file
<html>
<head>
<script>
var gui = require('nw.gui');
var win = gui.Window.get();
</script>
</head>
<body>
<script>
//list to open and make the app show
gui.App.on('open', function() {
win.show();
alert("file re-open");
});
// prevent close and make it hide
win.on('close', function() {
win.hide();
});
</script>
<!-- forse close the app -->
<center><br><br><input type="button" value="exit app" onclick="win.close(true)"></center>
</body>
</html>
then copy and past the node-webkit files for window on the same directory like normal package way then rename nw.exe to reopen.exe for example and then right click and create a desktop shortcut and open the exe file from the folder and click on close which will hide it then click on the desktop shortcut and it will re-show it "re-open" with an alert
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.