-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Api suggestion: API.App.restart #149
Comments
Can't you just refresh the page? document.location.reload(true) |
Sure, you could do that. But what if the application holds an exclusive lock on a file you are going to update? What if you want to replace the chromium binary blob itself? |
+1 |
I'll implement |
+1 |
Any thoughts / priority on this restart API? Would be great. |
+1 for a clean restart function |
Any updates on this feature? |
+1 for this! |
+1 It would be nice to auto update applications. |
This feature would be helpful when doing updates, as you can provide the user with a button to restart the application instead of asking them to close and reopen. |
It is a real nuisance to do this with shell scripts. Since after you've spawned the script you'll have to wait until the app process terminates. @echo off
rem usage: relaunch_app.bat <seconds to wait> <executable to launch> <arguments>
rem i.e. $>relaunch_app.bat 5 "C:\Program Files\Jujusoft\JujuEdit\JujuEdit.exe" "C:\Windows\system.ini"
echo Restarting in %1 seconds...
title Waiting
rem Windows 7
@timeout /t %1 /nobreak >nul 2>&1
rem Windows XP
if errorlevel 1 ping 192.0.2.2 -n 1 -w %1000 > nul
rem # launch the executable via start command
start /B "" %2 %3 %4 And on Mac: echo "Please wait for ${1} seconds.."
sleep $1
open -n -a "${2}" --args $3 In your node-webkit app: child_process.spawn(path.join(process.cwd(), "relaunch_app.bat")
, [waitSecs.toString()
, (process.platform == "darwin") ? process.execPath.match(/^([^\0]+?\.app)\//)[1]
: process.execPath
]
, {detached: true}
); |
现在只能在工具条上点击, 如何在程序中调用 restart 呢 用 document.location.reload(true) 代替是不是不能刷新node的模块? |
What about: |
@f0rmiga No, unfortunately that doesn't work. If your app consists of more than one window, only the window from which that command is run is reloaded. Ideally, App.restart or its equivalent would restart the entire app by shutting down all windows associated with the app. |
+1 |
@james: you could send a notification to that window so it can reload micha 2014-02-27 1:11 GMT+01:00 Paul Mandel notifications@github.com:
|
+1 |
3 similar comments
+1 |
+1 |
+1 |
@f0rmiga - You wrote:
I had no idea the method accepted arguments. It's not in the wiki. It helped me out. One or two of the 'Window.reload' family methods aren't documented either. Like this one:
Which, funnily enough, resolves to a nested call to reload(3)... |
@dynamite-ready I'm sorry, but I don't remember where I found it and what exactly it controls, but it worked to me pretty well. I made a app that uses just one window and it connects to a server, and all other solutions that I tried did not reloaded the connection to the server for example, but that method did it... maybe in other scenarios, like @jamesmortensen said, it won't work. More specifically when you have more than 1 window. |
Actually this works perfect for me, a simple respawn of itself: //Restart node-webkit app
var child_process = require("child_process");
//Start new app
var child = child_process.spawn(process.execPath, [], {detached: true});
//Don't wait for it
child.unref();
//Quit current
GUI.window.hide(); // hide window to prevent black display
GUI.app.quit(); // quit node-webkit app |
@gpetrov I can't get this to work on OS X. I did alter the If I use it as-is (not altering the exePath to point to the actual Any ideas? In the meantime, I think I'm going to try @semmel 's method. |
i tested the spawn method the problem (0.10) seems that the .unref on the child is not working i tried it with say and delay. app does not quit until the delay on the spawned process and say command happens this is my bash test script content sleep 5 but if you run the same thing on plain node works. |
add my +1 to App.restart, too |
in my index.html <script src="./code/app.js"></script> in my app.js require('nw.gui').App.restart = function() {
var child
var child_process = require("./code/app.js")
var gui = require('nw.gui')
var win = gui.Window.get()
if (process.platform == "darwin") {
child = child_process.spawn("open", ["-n", "-a", process.execPath.match(/^([^\0]+?\.app)\//)[1]], {detached:true})
} else {
child = child_process.spawn(process.execPath, [], {detached: true})
}
child.unref()
win.hide()
gui.App.quit()
}
setTimeout(function () {
require('nw.gui').App.restart()
}, 2*1000) Application launches fine and crashes after 2 seconds (on App.restart) with output [11948:1028/112029:ERROR:nw_shell.cc(336)] Error: Cannot find module 'nw.gui'
at Function.Module._resolveFilename (module.js:327:15)
at Function.Module._load (module.js:264:25)
at Module.require (module.js:356:17)
at require (module.js:375:17)
at Object.<anonymous> (/Users/michelek/Documents/github/Screenwerk/code/app.js:6:23)
at Module._compile (module.js:451:26)
at Object.Module._extensions..js (module.js:469:10)
at Module.load (module.js:346:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:356:17)
[11948:1028/112029:INFO:CONSOLE(327)] "Uncaught Error: Cannot find module 'nw.gui'", source: module.js (327) There is a context problem as I'm not reloading my index.html |
+1 |
@mitselek i have the same error on fedora 22 |
A long-awaited feature, indeed. Is there some hope for it to be implemented? |
+1 to this feature from me too! |
+1 |
chrome.runtime.reload(); |
@iteufel, it ends up with "Unchecked runtime.lastError while running runtime.restart: Restart is only supported on ChromeOS". |
@xenohunter Use |
@iteufel Thank you very much! It works like a charm. |
@iteufel, oops. Though now it takes no effect at all. No warning, no error, just nothing. |
+1 |
1 similar comment
+1 |
if anyone is interested, i've solved it like this restart() {
const {execPath, platform} = nw.process;
const {resolve} = nw.require('path');
let exePath = '';
let restartFile = '';
let command = '';
let content = '';
const {tmpdir} = nw.require('os');
const TEMP_DIR = resolve(tmpdir(), 'YOUR APP NAME');
if (platform === 'darwin') {
exePath = resolve(execPath, '../../../../../../../');
restartFile = resolve(TEMP_DIR, 'restart.sh');
content = "#!/bin/sh\nAPP=$1\nsleep 1\nopen $APP";
command = 'sh ';
} else {
exePath = execPath;
restartFile = resolve(TEMP_DIR, 'restart.bat');
content = "timeout 2\ncall $1";
command = '';
}
const fs = nw.require('fs');
fs.writeFile(restartFile, content, function (err) {
child_process.exec(command + restartFile + ' ' + exePath);
nw.App.quit();
});
} |
@blaremc did you test it on windows? Doesn't work for me, seems like |
@GendelfLugansk this code is working restart() {
let exePath = '';
const {resolve} = nw.require('path');
const {execPath, platform} = nw.process;
if (platform === 'darwin') {
exePath = resolve(execPath, '../../../../../../../');
} else {
exePath = execPath;
}
this.createRestartFile(exePath, () => {
setTimeout(() => {
nw.App.quit();
}, 300);
});
}
createRestartFile(exePath, callback) {
const {platform} = nw.process;
const {resolve} = nw.require('path');
let restartFile = '';
let command = '';
let content = '';
const TEMP_DIR = this.getTempDir();
if (platform === 'darwin') {
restartFile = resolve(TEMP_DIR, 'restart.sh');
content = "#!/bin/sh\nAPP=$1\nsleep 3\nopen $APP";
command = 'sh ';
} else {
restartFile = resolve(TEMP_DIR, 'restart.bat');
content = "timeout 3\nstart %1\nexit\n";
command = 'start /b ';
}
const fs = nw.require('fs');
fs.writeFile(restartFile, content, function (err) {
child_process.exec(command + restartFile + ' ' + exePath);
callback();
});
} |
try |
As mentioned by surinder: |
@mscreenie As was mentioned before by few users, |
Works
|
@loadbalance-sudachi-kun funded this issue with $256. Visit this issue on Issuehunt |
chrome.runtime.reload() does not work at this time. seems like localStorage doesn't get loaded the same way afterwards |
any new?, if(event.keyCode === 116){ // F5 refresh
document.location.reload(true);
}; "version": "0.1.0",
"configurations": [
{
"type": "nwjs",
"request": "launch",
"name": "NWJS DEBUG",
"runtimeExecutable": "${workspaceRoot}\\_NW\\sdk\\nw.exe",
"runtimeArgs": [
"--remote-debugging-port=9222",
"--enable-gpu-rasterization",
"--enable-gpu-memory-buffer-video-frames",
"--enable-native-gpu-memory-buffers",
],
"webRoot": "${workspaceRoot}",
"port": 9222,
"sourceMaps": false,
"reloadAfterAttached": true,
},
{
"type": "nwjs",
"request": "attach",
"name": "Attach to NWjs",
"port": 9222,
"webRoot": "${workspaceFolder}",
"reloadAfterAttached": true,
}
] |
+1 It seems there are enough uses cases to just expose either the old |
Support for restarting the application. It should restart with the same invocation flags it was started with in the first place. This would be great when it comes to auto-updating.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: