My project is developed based on NW.JS. When a certain condition is met, I need to restart the client, but I really don’t know enough about NODE. I need help from experts to solve it. Thank you! !
Whether it is the nw.js method or the node method, as long as the program can be restarted~
我想大声告诉你2017-05-16 13:41:20
var nwRestart = function () {
var child, child_process = require('child_process');
if (process.platform == "darwin") {
child = child_process.spawn("open", ["-n", "-a", process.execPath.match(/^([^rrreee]+?\.app)\//)[1]], { detached: true });
} else {
child = child_process.spawn(process.execPath, [], { detached: true });
}
child.unref();
require("nw.gui").Window.get().hide();
process._nw_app.quit();
};
nwRestart();
This is suitable for older nw clients. If the nw version you are using is relatively new, you need to modify it accordingly, mainly to get nw_app to exit at the end