-
Notifications
You must be signed in to change notification settings - Fork 0
/
nwmain.js
32 lines (29 loc) · 906 Bytes
/
nwmain.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var fs=require('fs');
var sep=require('path').sep;
var file=process.cwd()+sep+'bundle.js';
var watchFiles=function() {
fs.watchFile(file, function (f1, f2) {
if (f1.mtime.toString()!=f2.mtime.toString()) reload();
});
}
var unwatchFiles=function() {
fs.unwatchFile(file);
}
var reload=function(){
var gui = global.window.nwDispatcher.requireNwGui();
var win = gui.Window.get();
gui.App.clearCache();
win.reload();
}
// nodemain.js // this java script must be load by inject-script-start in package.json*/
if (typeof process !="undefined") { // checking if node.js is running
nodeRequire=require; // browser side package will overwrite require
if (process.versions["node-webkit"]) { // checking if nw is running
var gui = global.window.nwDispatcher.requireNwGui();
gui.Window.get().on('close', function(){
unwatchFiles();
gui.App.quit();
});
watchFiles();
}
}