clowd / Clowd.Squirrel

Quick and easy installer and automatic updates for cross-platform dotnet applications
426 stars 39 forks source link

UpdateApp is opening another instance of app before RestartApp is called #150

Closed will-scc closed 1 year ago

will-scc commented 1 year ago

When my application updates, a new instance of the application is opened when UpdateApp() is called.

If I close this second instance it will cause the first to get stuck (maybe some silent exception?) and trying to close it gets the "Please wait until application has finished updating message" and can only be killed via Task Manager. Note: I'm actually not clear whether it's closing the first or second instance that causes the problem, it's a bit hard to tell the difference, but I close the one which isn't currently doing the update (which is shown in the app before UpdateApp is called).

There is no log file created in the SquirrelClowdTemp folder.

The Squirrel-ProcessStart.log file looks like this:

2023-03-08 12:23:25.9239 [INFO] - Program: Starting Squirrel Updater: --processStartAndWait Application.exe
2023-03-08 12:23:26.1198 [INFO] - Program: Want to launch '<redacted>\app-0.8.1-alpha284\Application.exe'
2023-03-08 12:23:26.1339 [INFO] - Program: About to wait for parent PID 24744
2023-03-08 12:23:26.3956 [INFO] - Program: About to launch: '<redacted>\app-0.8.1-alpha284\Application.exe': 
2023-03-08 12:23:26.4256 [INFO] - Program: Finished Squirrel Updater

My update logic, looks like this (some UI-related logic removed for brevity):

bool updateAvailable = false;

using (var mgr = new UpdateManager(updateLocation))
{
    UpdateInfo updateInfo = await mgr.CheckForUpdate();

    updateAvailable = updateInfo.ReleasesToApply.Any();

    if (updateAvailable)
    {
        await mgr.UpdateApp();
    }
}

if (updateAvailable)
{
    if (shouldRestart)
    {
        UpdateManager.RestartApp();
    }
    else
    {
        //some ui logic to say an update is pending app restart
    }
}
caesay commented 1 year ago

UpdateApp will call the standard Squirrel hooks (which execute your app with the "updated" or "obsoleted" command line arguments. Make sure you are calling SquirrelAwareApp.HandleEvents() at the start of your application (per the documentation in the readme)

will-scc commented 1 year ago

I was migrating from Squirrel.Windows and thought those steps were optional if you wanted to do something different than the default behaviour - I see that isn't the case now.

Thanks for the nudge. :)

caesay commented 1 year ago

If you are using v2, this is optional and functions the same way as Squirrel.WIndows. If you mark your exe as squirrel aware the hooks run, otherwise no. In v3 this is no longer optional.