Squirrel / Squirrel.Windows

An installation and update framework for Windows desktop apps
MIT License
7.23k stars 1.02k forks source link

Fix app can not restart after an unexpected exit during the apply releases #1862

Closed q837477816 closed 11 months ago

q837477816 commented 11 months ago

Problem Description: During the use of Squirrel's automatic upgrade feature, if the app is quit or unexpectedly exits while installing the new version, it may result in unable to restart the app. Upon reviewing the source code, it was found that the stubExe would find the latest version and create the path to launch it. However, due to missing files in the latest app-xxx directory, the app fails to start.

Solution: To address this issue, during the application of releases, the new version is first extracted to a temp-app-xxxx directory. After the extraction is complete, it is then renamed to the final app-xxxx directory. This approach ensures that even if the app unexpectedly exits during the installation process and leaves the temp directory, it will not affect the next app launch.

anaisbetts commented 11 months ago

Instead of doing this, write a .not-finished file in the app folder, and delete it when the update successfully completes. Then, make the stubs ignore folders with .not-finished and delete any folders on update check that do have .not-finished. This seems more complicated but it avoids moving executables around or renaming folders, which often triggers 3rd party antivirus

Also, don't quit your application while updates are running - instead of exiting, hide the window, await the update, then close once it finishes

q837477816 commented 11 months ago

Instead of doing this, write a .not-finished file in the app folder, and delete it when the update successfully completes. Then, make the stubs ignore folders with .not-finished and delete any folders on update check that do have .not-finished. This seems more complicated but it avoids moving executables around or renaming folders, which often triggers 3rd party antivirus

Agreed, I have submitted another commit, plz help review it, thanks. About delete any folders on update check that do have .not-finished, I don't need to add extra logic to handle this part since it already covers in https://github.com/Squirrel/Squirrel.Windows/blob/0ee9447d0f70744ad3624de953fc0eccf600990a/src/Squirrel/UpdateManager.ApplyReleases.cs#L306 and https://github.com/Squirrel/Squirrel.Windows/blob/0ee9447d0f70744ad3624de953fc0eccf600990a/src/Squirrel/UpdateManager.ApplyReleases.cs#L96

Also, don't quit your application while updates are running - instead of exiting, hide the window, await the update, then close once it finishes

Yes, during the upgrade process, we don't recommend users to exit the app. But we can't guarantee whether the app will be exited due to other reasons, such as crash or system shutdown. So we need this part logic to make sure users won't be able to launch the app due to the uncompleted upgrade.

q837477816 commented 11 months ago

A few small things but this looks good

Hi @anaisbetts , plz review it again, thx

caesay commented 8 months ago

Not sure if I missed something here, but I don't think this covers the Update.exe --processStart case, which will seemingly still launch the broken directory.

damonyu666 commented 6 months ago

@caesay In fact, when launching the app through "Update.exe --processStart," it initiates the latest version recorded in the local RELEASES file. However, if the last upgrade attempt failed, the RELEASES file remains unchanged, and as a result, it won't launch the broken directory.