1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-11 11:34:07 +02:00

Fix a race condition crash in update checker events

This commit is contained in:
chylex 2017-06-24 12:10:25 +02:00
parent 1087b5e1d1
commit 4800faa783
3 changed files with 29 additions and 33 deletions

View File

@ -104,7 +104,7 @@ public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings)
Config.MuteToggled += Config_MuteToggled;
Config.ZoomLevelChanged += Config_ZoomLevelChanged;
this.updates = new UpdateHandler(browser, this, updaterSettings);
this.updates = new UpdateHandler(browser, updaterSettings);
this.updates.UpdateAccepted += updates_UpdateAccepted;
this.updates.UpdateDismissed += updates_UpdateDismissed;
@ -287,24 +287,28 @@ private void plugins_PluginChangedState(object sender, PluginChangedStateEventAr
}
private void updates_UpdateAccepted(object sender, UpdateAcceptedEventArgs e){
foreach(Form form in Application.OpenForms.Cast<Form>().Reverse()){
if (form is FormSettings || form is FormPlugins || form is FormAbout){
form.Close();
this.InvokeAsyncSafe(() => {
foreach(Form form in Application.OpenForms.Cast<Form>().Reverse()){
if (form is FormSettings || form is FormPlugins || form is FormAbout){
form.Close();
}
}
}
updates.BeginUpdateDownload(this, e.UpdateInfo, update => {
if (update.DownloadStatus == UpdateDownloadStatus.Done){
UpdateInstallerPath = update.InstallerPath;
}
updates.BeginUpdateDownload(this, e.UpdateInfo, update => {
if (update.DownloadStatus == UpdateDownloadStatus.Done){
UpdateInstallerPath = update.InstallerPath;
}
ForceClose();
ForceClose();
});
});
}
private void updates_UpdateDismissed(object sender, UpdateDismissedEventArgs e){
Config.DismissedUpdate = e.VersionTag;
Config.Save();
this.InvokeAsyncSafe(() => {
Config.DismissedUpdate = e.VersionTag;
Config.Save();
});
}
private void soundNotification_PlaybackError(object sender, PlaybackErrorEventArgs e){

View File

@ -98,13 +98,15 @@ private void btnCheckUpdates_Click(object sender, EventArgs e){
}
private void updates_CheckFinished(object sender, UpdateCheckEventArgs e){
if (e.EventId == updateCheckEventId){
btnCheckUpdates.Enabled = true;
this.InvokeAsyncSafe(() => {
if (e.EventId == updateCheckEventId){
btnCheckUpdates.Enabled = true;
if (!e.UpdateAvailable){
MessageBox.Show("Your version of "+Program.BrandName+" is up to date.", "No Updates Available", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (!e.UpdateAvailable){
MessageBox.Show("Your version of "+Program.BrandName+" is up to date.", "No Updates Available", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
});
}
private void zoomUpdateTimer_Tick(object sender, EventArgs e){

View File

@ -2,7 +2,6 @@
using CefSharp.WinForms;
using System;
using System.Windows.Forms;
using TweetDuck.Core;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils;
using TweetDuck.Resources;
@ -13,7 +12,6 @@ sealed class UpdateHandler{
private static bool IsSystemSupported => true; // Environment.OSVersion.Version >= new Version("6.1"); // 6.1 NT version = Windows 7
private readonly ChromiumWebBrowser browser;
private readonly FormBrowser form;
private readonly UpdaterSettings settings;
public event EventHandler<UpdateAcceptedEventArgs> UpdateAccepted;
@ -23,9 +21,8 @@ sealed class UpdateHandler{
private int lastEventId;
private UpdateInfo lastUpdateInfo;
public UpdateHandler(ChromiumWebBrowser browser, FormBrowser form, UpdaterSettings settings){
public UpdateHandler(ChromiumWebBrowser browser, UpdaterSettings settings){
this.browser = browser;
this.form = form;
this.settings = settings;
browser.FrameLoadEnd += browser_FrameLoadEnd;
@ -92,27 +89,20 @@ public void CleanupDownload(){
}
public void DismissUpdate(string tag){
settings.DismissedUpdate = tag;
UpdateDismissed?.Invoke(this, new UpdateDismissedEventArgs(tag));
TriggerUpdateDismissedEvent(new UpdateDismissedEventArgs(tag));
}
private void TriggerUpdateAcceptedEvent(UpdateAcceptedEventArgs args){
if (UpdateAccepted != null){
form.InvokeAsyncSafe(() => UpdateAccepted(this, args));
}
UpdateAccepted?.Invoke(this, args);
}
private void TriggerUpdateDismissedEvent(UpdateDismissedEventArgs args){
form.InvokeAsyncSafe(() => {
settings.DismissedUpdate = args.VersionTag;
UpdateDismissed?.Invoke(this, args);
});
settings.DismissedUpdate = args.VersionTag;
UpdateDismissed?.Invoke(this, args);
}
private void TriggerCheckFinishedEvent(UpdateCheckEventArgs args){
if (CheckFinished != null){
form.InvokeAsyncSafe(() => CheckFinished(this, args));
}
CheckFinished?.Invoke(this, args);
}
public class Bridge{