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

Rewrite update event args and update dismissal handling

This commit is contained in:
chylex 2017-08-22 03:22:44 +02:00
parent 3d4cec3b22
commit c6190db918
9 changed files with 51 additions and 70 deletions

View File

@ -19,7 +19,6 @@
using TweetDuck.Plugins.Events; using TweetDuck.Plugins.Events;
using TweetDuck.Resources; using TweetDuck.Resources;
using TweetDuck.Updates; using TweetDuck.Updates;
using TweetDuck.Updates.Events;
using TweetLib.Audio; using TweetLib.Audio;
namespace TweetDuck.Core{ namespace TweetDuck.Core{
@ -337,7 +336,7 @@ private void plugins_PluginChangedState(object sender, PluginChangedStateEventAr
browser.ExecuteScriptAsync("window.TDPF_setPluginState", e.Plugin, e.IsEnabled); browser.ExecuteScriptAsync("window.TDPF_setPluginState", e.Plugin, e.IsEnabled);
} }
private void updates_UpdateAccepted(object sender, UpdateAcceptedEventArgs e){ private void updates_UpdateAccepted(object sender, UpdateEventArgs e){
this.InvokeAsyncSafe(() => { this.InvokeAsyncSafe(() => {
FormManager.CloseAllDialogs(); FormManager.CloseAllDialogs();
@ -351,9 +350,9 @@ private void updates_UpdateAccepted(object sender, UpdateAcceptedEventArgs e){
}); });
} }
private void updates_UpdateDismissed(object sender, UpdateDismissedEventArgs e){ private void updates_UpdateDismissed(object sender, UpdateEventArgs e){
this.InvokeAsyncSafe(() => { this.InvokeAsyncSafe(() => {
Config.DismissedUpdate = e.VersionTag; Config.DismissedUpdate = e.UpdateInfo.VersionTag;
Config.Save(); Config.Save();
}); });
} }
@ -454,8 +453,10 @@ public void OpenSettings(Type startTab){
form.FormClosed += (sender, args) => { form.FormClosed += (sender, args) => {
if (!prevEnableUpdateCheck && Config.EnableUpdateCheck){ if (!prevEnableUpdateCheck && Config.EnableUpdateCheck){
updates.DismissUpdate(string.Empty); Config.DismissedUpdate = null;
updates.Check(false); Config.Save();
updates.Check(true);
} }
if (!Config.EnableTrayHighlight){ if (!Config.EnableTrayHighlight){

View File

@ -1,7 +1,6 @@
using System; using System;
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Updates; using TweetDuck.Updates;
using TweetDuck.Updates.Events;
namespace TweetDuck.Core.Other.Settings{ namespace TweetDuck.Core.Other.Settings{
partial class TabSettingsGeneral : BaseTabSettings{ partial class TabSettingsGeneral : BaseTabSettings{
@ -91,18 +90,19 @@ private void checkUpdateNotifications_CheckedChanged(object sender, EventArgs e)
} }
private void btnCheckUpdates_Click(object sender, EventArgs e){ private void btnCheckUpdates_Click(object sender, EventArgs e){
btnCheckUpdates.Enabled = false; Config.DismissedUpdate = null;
Config.Save();
updates.DismissUpdate(string.Empty); btnCheckUpdates.Enabled = false;
updateCheckEventId = updates.Check(true); updateCheckEventId = updates.Check(true);
} }
private void updates_CheckFinished(object sender, UpdateCheckEventArgs e){ private void updates_CheckFinished(object sender, UpdateEventArgs e){
this.InvokeAsyncSafe(() => { this.InvokeAsyncSafe(() => {
if (e.EventId == updateCheckEventId){ if (e.EventId == updateCheckEventId){
btnCheckUpdates.Enabled = true; btnCheckUpdates.Enabled = true;
if (!e.UpdateAvailable){ if (!e.IsUpdateAvailable){
FormMessage.Information("No Updates Available", "Your version of TweetDuck is up to date.", FormMessage.OK); FormMessage.Information("No Updates Available", "Your version of TweetDuck is up to date.", FormMessage.OK);
} }
} }

View File

@ -243,7 +243,6 @@
<Compile Include="Plugins\PluginManager.cs" /> <Compile Include="Plugins\PluginManager.cs" />
<Compile Include="Plugins\PluginScriptGenerator.cs" /> <Compile Include="Plugins\PluginScriptGenerator.cs" />
<Compile Include="Reporter.cs" /> <Compile Include="Reporter.cs" />
<Compile Include="Updates\Events\UpdateDismissedEventArgs.cs" />
<Compile Include="Updates\FormUpdateDownload.cs"> <Compile Include="Updates\FormUpdateDownload.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -259,8 +258,6 @@
<Compile Include="Core\Utils\BrowserCache.cs" /> <Compile Include="Core\Utils\BrowserCache.cs" />
<Compile Include="Core\Utils\BrowserUtils.cs" /> <Compile Include="Core\Utils\BrowserUtils.cs" />
<Compile Include="Core\Utils\NativeMethods.cs" /> <Compile Include="Core\Utils\NativeMethods.cs" />
<Compile Include="Updates\Events\UpdateAcceptedEventArgs.cs" />
<Compile Include="Updates\Events\UpdateCheckEventArgs.cs" />
<Compile Include="Updates\UpdateDownloadStatus.cs" /> <Compile Include="Updates\UpdateDownloadStatus.cs" />
<Compile Include="Updates\UpdateHandler.cs" /> <Compile Include="Updates\UpdateHandler.cs" />
<Compile Include="Updates\UpdateInfo.cs" /> <Compile Include="Updates\UpdateInfo.cs" />
@ -272,6 +269,7 @@
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Resources\ScriptLoader.cs" /> <Compile Include="Resources\ScriptLoader.cs" />
<Compile Include="Updates\UpdateEventArgs.cs" />
<Compile Include="Updates\UpdaterSettings.cs" /> <Compile Include="Updates\UpdaterSettings.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,11 +0,0 @@
using System;
namespace TweetDuck.Updates.Events{
class UpdateAcceptedEventArgs : EventArgs{
public readonly UpdateInfo UpdateInfo;
public UpdateAcceptedEventArgs(UpdateInfo info){
this.UpdateInfo = info;
}
}
}

View File

@ -1,15 +0,0 @@
using System;
namespace TweetDuck.Updates.Events{
class UpdateCheckEventArgs : EventArgs{
public int EventId { get; }
public UpdateInfo UpdateInfo { get; }
public bool UpdateAvailable => UpdateInfo != null;
public UpdateCheckEventArgs(int eventId, UpdateInfo updateInfo){
EventId = eventId;
UpdateInfo = updateInfo;
}
}
}

View File

@ -1,11 +0,0 @@
using System;
namespace TweetDuck.Updates.Events{
class UpdateDismissedEventArgs : EventArgs{
public readonly string VersionTag;
public UpdateDismissedEventArgs(string versionTag){
this.VersionTag = versionTag;
}
}
}

View File

@ -0,0 +1,20 @@
using System;
namespace TweetDuck.Updates{
sealed class UpdateEventArgs : EventArgs{
public int EventId { get; }
public UpdateInfo UpdateInfo { get; }
public bool IsUpdateAvailable => UpdateInfo != null;
public UpdateEventArgs(int eventId, UpdateInfo updateInfo){
this.EventId = eventId;
this.UpdateInfo = updateInfo;
}
public UpdateEventArgs(UpdateInfo updateInfo){
this.EventId = updateInfo.EventId;
this.UpdateInfo = updateInfo;
}
}
}

View File

@ -5,16 +5,15 @@
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils; using TweetDuck.Core.Utils;
using TweetDuck.Resources; using TweetDuck.Resources;
using TweetDuck.Updates.Events;
namespace TweetDuck.Updates{ namespace TweetDuck.Updates{
sealed class UpdateHandler{ sealed class UpdateHandler{
private readonly ChromiumWebBrowser browser; private readonly ChromiumWebBrowser browser;
private readonly UpdaterSettings settings; private readonly UpdaterSettings settings;
public event EventHandler<UpdateAcceptedEventArgs> UpdateAccepted; public event EventHandler<UpdateEventArgs> UpdateAccepted;
public event EventHandler<UpdateDismissedEventArgs> UpdateDismissed; public event EventHandler<UpdateEventArgs> UpdateDismissed;
public event EventHandler<UpdateCheckEventArgs> CheckFinished; public event EventHandler<UpdateEventArgs> CheckFinished;
private int lastEventId; private int lastEventId;
private UpdateInfo lastUpdateInfo; private UpdateInfo lastUpdateInfo;
@ -36,9 +35,11 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
public int Check(bool force){ public int Check(bool force){
if (Program.UserConfig.EnableUpdateCheck || force){ if (Program.UserConfig.EnableUpdateCheck || force){
string dismissedUpdate = force || settings.DismissedUpdate == null ? string.Empty : settings.DismissedUpdate; if (force){
settings.DismissedUpdate = null;
}
browser.ExecuteScriptAsync("TDUF_runUpdateCheck", ++lastEventId, Program.VersionTag, dismissedUpdate, settings.AllowPreReleases); browser.ExecuteScriptAsync("TDUF_runUpdateCheck", ++lastEventId, Program.VersionTag, settings.DismissedUpdate ?? string.Empty, settings.AllowPreReleases);
return lastEventId; return lastEventId;
} }
@ -79,20 +80,16 @@ public void CleanupDownload(){
} }
} }
public void DismissUpdate(string tag){ private void TriggerUpdateAcceptedEvent(UpdateEventArgs args){
TriggerUpdateDismissedEvent(new UpdateDismissedEventArgs(tag));
}
private void TriggerUpdateAcceptedEvent(UpdateAcceptedEventArgs args){
UpdateAccepted?.Invoke(this, args); UpdateAccepted?.Invoke(this, args);
} }
private void TriggerUpdateDismissedEvent(UpdateDismissedEventArgs args){ private void TriggerUpdateDismissedEvent(UpdateEventArgs args){
settings.DismissedUpdate = args.VersionTag; settings.DismissedUpdate = args.UpdateInfo.VersionTag;
UpdateDismissed?.Invoke(this, args); UpdateDismissed?.Invoke(this, args);
} }
private void TriggerCheckFinishedEvent(UpdateCheckEventArgs args){ private void TriggerCheckFinishedEvent(UpdateEventArgs args){
CheckFinished?.Invoke(this, args); CheckFinished?.Invoke(this, args);
} }
@ -110,22 +107,22 @@ public void TriggerUpdateCheck(){
public void OnUpdateCheckFinished(int eventId, string versionTag, string downloadUrl){ public void OnUpdateCheckFinished(int eventId, string versionTag, string downloadUrl){
if (versionTag != null && (owner.lastUpdateInfo == null || owner.lastUpdateInfo.VersionTag != versionTag)){ if (versionTag != null && (owner.lastUpdateInfo == null || owner.lastUpdateInfo.VersionTag != versionTag)){
owner.CleanupDownload(); owner.CleanupDownload();
owner.lastUpdateInfo = new UpdateInfo(owner.settings, versionTag, downloadUrl); owner.lastUpdateInfo = new UpdateInfo(owner.settings, eventId, versionTag, downloadUrl);
owner.lastUpdateInfo.BeginSilentDownload(); owner.lastUpdateInfo.BeginSilentDownload();
} }
owner.TriggerCheckFinishedEvent(new UpdateCheckEventArgs(eventId, owner.lastUpdateInfo)); owner.TriggerCheckFinishedEvent(new UpdateEventArgs(eventId, owner.lastUpdateInfo));
} }
public void OnUpdateAccepted(){ public void OnUpdateAccepted(){
if (owner.lastUpdateInfo != null){ if (owner.lastUpdateInfo != null){
owner.TriggerUpdateAcceptedEvent(new UpdateAcceptedEventArgs(owner.lastUpdateInfo)); owner.TriggerUpdateAcceptedEvent(new UpdateEventArgs(owner.lastUpdateInfo));
} }
} }
public void OnUpdateDismissed(){ public void OnUpdateDismissed(){
if (owner.lastUpdateInfo != null){ if (owner.lastUpdateInfo != null){
owner.TriggerUpdateDismissedEvent(new UpdateDismissedEventArgs(owner.lastUpdateInfo.VersionTag)); owner.TriggerUpdateDismissedEvent(new UpdateEventArgs(owner.lastUpdateInfo));
owner.CleanupDownload(); owner.CleanupDownload();
} }
} }

View File

@ -5,6 +5,7 @@
namespace TweetDuck.Updates{ namespace TweetDuck.Updates{
sealed class UpdateInfo{ sealed class UpdateInfo{
public int EventId { get; }
public string VersionTag { get; } public string VersionTag { get; }
public string InstallerPath { get; } public string InstallerPath { get; }
@ -15,10 +16,11 @@ sealed class UpdateInfo{
private readonly string downloadUrl; private readonly string downloadUrl;
private WebClient currentDownload; private WebClient currentDownload;
public UpdateInfo(UpdaterSettings settings, string versionTag, string downloadUrl){ public UpdateInfo(UpdaterSettings settings, int eventId, string versionTag, string downloadUrl){
this.installerFolder = settings.InstallerDownloadFolder; this.installerFolder = settings.InstallerDownloadFolder;
this.downloadUrl = downloadUrl; this.downloadUrl = downloadUrl;
this.EventId = eventId;
this.VersionTag = versionTag; this.VersionTag = versionTag;
this.InstallerPath = Path.Combine(installerFolder, "TweetDuck."+versionTag+".exe"); this.InstallerPath = Path.Combine(installerFolder, "TweetDuck."+versionTag+".exe");
} }