dsheiko/nw-autoupdater

Nwjs prevent start of application copy

cry0m1 opened this issue · 11 comments

MacOS Sierra.
Main application is running, it downloads/unpack new release successfully, but cannot start this new release (another copy of app). Even running downloaded release (copy) from /var/folders/64/..../T/nw-autoupdate manually using different options (-a or/and -n) will not succeeded, application is not started.

Maybe I did a mistake?

The only way to run a copy of nwjs app I found is to remove app caches (leads to fresh app):
rm -rf /Users/%USERNAME%/Library/Caches/%APPNAME% && rm -rf /Users/%USERNAME%/Library/Application\ Support/%APPNAME%

Thanks for the info. I am going to research on it.

I realized I can do it manually only, I am talking about running another nwjs app while previous still opened. Did you test it on MacOS Sierra? Is it working for you? I read documentation of nodejs about 'spawn' - seems it should work, but I am not able to complete update process, because detached child never got up and running.

It runs the second copy of NWjs because restartToSwap() runs it with option:
--user-data-dir=${tpmUserData} where tpmUserData = join( nw.App.dataPath, "swap" )
what shall be ~/Library/Application\ Support/nw-autoupdater-demo/swap. It differs from default one and is not locked by previous instance.

Besides in index.html I use the options:
updater = new AutoUpdater( require( "./package.json" ), {
homeDir: "/Users/sheiko/Sites/test",
backupDir: "/Users/sheiko/Sites/test.bak"
}),

because for Mac app it's pretty hard to figure out the app container folder.

And of course MacOS security gate will block restart until you tell otherwise.

P.S. BTW errors while running detached process on first restart logged in `~/Library/Application\ Support/nw-autoupdater-demo/swap.log

Yep, I see, but I restartToSwap() on my machine did not start child.
So it works fine for you?

I think to do launcher based on your solution: check -> download -> unpack to inner folder every build -> exit -> start launcher -> launcher checks everyhing ok -> remove folder with old build -> switch to new build changing document.location.href

I checked MVP - works for me.

Yeah, it starts. I had to allow launching it in the Security section of the system preferences as one of unidentified dev, but works (macOS Sierra 10.12.3)

I believe it shall look like the app updates itself in its original folder. In ideal world I would use a swap utility (a light-weight native app) instead of NWjs, but could not find one, universal for all 3 platforms.

You mentioned

updater = new AutoUpdater( require( "./package.json" ), {
homeDir: "/Users/sheiko/Sites/test",
backupDir: "/Users/sheiko/Sites/test.bak"
}),

What are these folders? Inside APPNAME.app is? Why it operates by folders not *.app files (imagine *.app file is placed at /Applications folder).
Description is quite a mess of misunderstanding. It is not oblivious how it works under the hood.

Finally it started too work, thank you very much.

On Ubuntu/Windows I use for the home dir dirname( process.execPath ). That is the folder where the self-extracting archive built by nwjs-builder is located (process.cwd() points to temp directory where that archive is unpacked to). The problem here that under MacOS process.execPath points to the executable inside Mac app structure (something like project-dir/nw-autoupdater-demo.app/Contents/MacOS/nwjs - not very useful when we need just project-dir). Backup directory by default is built from home one by concatenating ".bak". So what I suggest is to set the directories explicitly. It can be any writable directories. I just created two in my workspace ~/Sites/

homeDir/backupDir optional parameters to AutoUpdater, which is part of API (https://github.com/dsheiko/nw-autoupdater/blob/master/example/client/index.html)

Hi, will you join my pull request, if yes - I need to prepare it, also we need to update README to make it more descriptive about initial data, I found some bugs:

My nwjs app builds with 'nw-builder':
macos - %APPNAME%.app (compressed *.app file for release);
win/linux - %FOLDER_NAME% with binary and other necessary files inside (compressed all files inside this folder for release);

  1. macos - excessive path spaces quoting with "\ " in args/argv.
  2. unhandled paths for MacOS %APPNAME%.app when nwjs binary is inside package.
  3. differences between backup creation on mac/win_linux, we need create %APPNAME%.app.bak for macos, and %FOLDER_NAME%.bak for win/linux.
  4. fix for MacOS Sierra, did you notice new app is starting in sanbox Apple called AppTranslocation?

I tested on macos sierra / win10 / ubuntu 12 - works fine with my changes.

Can you please create a pull request?

Yep, done. Thank you.