Title is pretty much the question
I'd like to know how would I be able to offer the user to download the update
"Update Available" or something then if user clicks OK will install. then once complete will restart
If you're after a quick'n'dirty, MessageBox based, copy-paste-done solution then have a look at this. It's inelegant but it does the thing. Feel free to use this as you will.
using (var mgr = new UpdateManager(SourceUri))
{
this.logger.Info("Checking for updates");
try
{
var updateInfo = await mgr.CheckForUpdate();
if (updateInfo.ReleasesToApply.Any())
{
var versionCount = updateInfo.ReleasesToApply.Count;
this.logger.Info($"{versionCount} update(s) found.");
var versionWord = versionCount > 1 ? "versions" : "version";
var message = new StringBuilder().AppendLine($"App is {versionCount} {versionWord} behind.").
AppendLine("If you choose to update, changes wont take affect until App is restarted.").
AppendLine("Would you like to download and install them?").
ToString();
var result = MessageBox.Show(message, "App Update", MessageBoxButton.YesNo);
if (result != MessageBoxResult.Yes)
{
this.logger.Info("update declined by user.");
return;
}
this.logger.Info("Downloading updates");
var updateResult = await mgr.UpdateApp();
this.logger.Info(
$"Download complete. Version {updateResult.Version} will take effect when App is restarted.");
}
else
{
this.logger.Info("No updates detected.");
}
}
catch (Exception ex)
{
this.logger.Warn($"There was an issue during the update process! {ex.Message}");
}
}
@JKSnd
That works great but It keeps the previous installations (more than 2)
My localappdata has 1.0.1, 1.0.2,1.0.3,1.0.4
any idea how to solve that?
Good question, @JonZso. I was under the impression that cleaning up previous versions was default behaviour, but now that you mention it I definitely have three versions of this particular app in my AppData. I'm going to troll the documentation one more time.
When you go through auto-update process, old versions are left behind. When you install from the *.exe, that will force uninstall all old instances.
In case this is helpful for anyone who wants to know how to handle this for electron auto-updater:
Our team uses the electron auto-updater which doesn't have an APIs to separately 1) check to see if there is an update and then 2) install upon request. They only provide one which does the check and immediately starts downloading/install.
We had to manually query the endpoint to see if there was an update before showing a dialog to the user to see if they wanted to update. If they confirmed, we would then call auto-updater.checkForUpdates()
@shiftkey original question answered, this can be closed.
Most helpful comment
If you're after a quick'n'dirty, MessageBox based, copy-paste-done solution then have a look at this. It's inelegant but it does the thing. Feel free to use this as you will.