Inform user when checking update fail or update fail, and wrap all code in one try catch instead of catch each exception seperately since they are all same kind of exception.

Use using instead of manually dispose.
This commit is contained in:
弘韬 张 2020-12-20 17:44:46 +08:00
parent f61a7271c5
commit cbfa3f354d

View file

@ -31,33 +31,18 @@ namespace Flow.Launcher.Core
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true) public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
{ {
UpdateManager updateManager; try
{
UpdateInfo newUpdateInfo; UpdateInfo newUpdateInfo;
if (!silentUpdate) if (!silentUpdate)
api.ShowMsg("Please wait...", "Checking for new update"); api.ShowMsg("Please wait...", "Checking for new update");
try using var updateManager = await GitHubUpdateManager(GitHubRepository);
{
updateManager = await GitHubUpdateManager(GitHubRepository);
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Log.Exception($"|Updater.UpdateApp|Please check your connection and proxy settings to api.github.com.", e);
return;
}
try
{
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed // UpdateApp CheckForUpdate will return value only if the app is squirrel installed
newUpdateInfo = await updateManager.CheckForUpdate().NonNull(); newUpdateInfo = await updateManager.CheckForUpdate().NonNull();
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to api.github.com.", e);
updateManager.Dispose();
return;
}
var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString()); var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
var currentVersion = Version.Parse(Constant.Version); var currentVersion = Version.Parse(Constant.Version);
@ -75,16 +60,7 @@ namespace Flow.Launcher.Core
if (!silentUpdate) if (!silentUpdate)
api.ShowMsg("Update found", "Updating..."); api.ShowMsg("Update found", "Updating...");
try
{
await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply); await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply);
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
updateManager.Dispose();
return;
}
await updateManager.ApplyReleases(newUpdateInfo); await updateManager.ApplyReleases(newUpdateInfo);
@ -105,14 +81,18 @@ namespace Flow.Launcher.Core
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}"); Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
// always dispose UpdateManager
updateManager.Dispose();
if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes) if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{ {
UpdateManager.RestartApp(Constant.ApplicationFileName); UpdateManager.RestartApp(Constant.ApplicationFileName);
} }
} }
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
api.ShowMsg("Update Fail!", "Check your connection and proxy settings to github-cloud.s3.amazonaws.com.");
return;
}
}
[UsedImplicitly] [UsedImplicitly]
private class GithubRelease private class GithubRelease