1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-11 11:34:07 +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.Resources;
using TweetDuck.Updates;
using TweetDuck.Updates.Events;
using TweetLib.Audio;
namespace TweetDuck.Core{
@ -337,7 +336,7 @@ private void plugins_PluginChangedState(object sender, PluginChangedStateEventAr
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(() => {
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(() => {
Config.DismissedUpdate = e.VersionTag;
Config.DismissedUpdate = e.UpdateInfo.VersionTag;
Config.Save();
});
}
@ -454,8 +453,10 @@ public void OpenSettings(Type startTab){
form.FormClosed += (sender, args) => {
if (!prevEnableUpdateCheck && Config.EnableUpdateCheck){
updates.DismissUpdate(string.Empty);
updates.Check(false);
Config.DismissedUpdate = null;
Config.Save();
updates.Check(true);
}
if (!Config.EnableTrayHighlight){

View File

@ -1,7 +1,6 @@
using System;
using TweetDuck.Core.Controls;
using TweetDuck.Updates;
using TweetDuck.Updates.Events;
namespace TweetDuck.Core.Other.Settings{
partial class TabSettingsGeneral : BaseTabSettings{
@ -91,18 +90,19 @@ private void checkUpdateNotifications_CheckedChanged(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);
}
private void updates_CheckFinished(object sender, UpdateCheckEventArgs e){
private void updates_CheckFinished(object sender, UpdateEventArgs e){
this.InvokeAsyncSafe(() => {
if (e.EventId == updateCheckEventId){
btnCheckUpdates.Enabled = true;
if (!e.UpdateAvailable){
if (!e.IsUpdateAvailable){
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\PluginScriptGenerator.cs" />
<Compile Include="Reporter.cs" />
<Compile Include="Updates\Events\UpdateDismissedEventArgs.cs" />
<Compile Include="Updates\FormUpdateDownload.cs">
<SubType>Form</SubType>
</Compile>
@ -259,8 +258,6 @@
<Compile Include="Core\Utils\BrowserCache.cs" />
<Compile Include="Core\Utils\BrowserUtils.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\UpdateHandler.cs" />
<Compile Include="Updates\UpdateInfo.cs" />
@ -272,6 +269,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Resources\ScriptLoader.cs" />
<Compile Include="Updates\UpdateEventArgs.cs" />
<Compile Include="Updates\UpdaterSettings.cs" />
</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.Utils;
using TweetDuck.Resources;
using TweetDuck.Updates.Events;
namespace TweetDuck.Updates{
sealed class UpdateHandler{
private readonly ChromiumWebBrowser browser;
private readonly UpdaterSettings settings;
public event EventHandler<UpdateAcceptedEventArgs> UpdateAccepted;
public event EventHandler<UpdateDismissedEventArgs> UpdateDismissed;
public event EventHandler<UpdateCheckEventArgs> CheckFinished;
public event EventHandler<UpdateEventArgs> UpdateAccepted;
public event EventHandler<UpdateEventArgs> UpdateDismissed;
public event EventHandler<UpdateEventArgs> CheckFinished;
private int lastEventId;
private UpdateInfo lastUpdateInfo;
@ -36,9 +35,11 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
public int Check(bool 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;
}
@ -79,20 +80,16 @@ public void CleanupDownload(){
}
}
public void DismissUpdate(string tag){
TriggerUpdateDismissedEvent(new UpdateDismissedEventArgs(tag));
}
private void TriggerUpdateAcceptedEvent(UpdateAcceptedEventArgs args){
private void TriggerUpdateAcceptedEvent(UpdateEventArgs args){
UpdateAccepted?.Invoke(this, args);
}
private void TriggerUpdateDismissedEvent(UpdateDismissedEventArgs args){
settings.DismissedUpdate = args.VersionTag;
private void TriggerUpdateDismissedEvent(UpdateEventArgs args){
settings.DismissedUpdate = args.UpdateInfo.VersionTag;
UpdateDismissed?.Invoke(this, args);
}
private void TriggerCheckFinishedEvent(UpdateCheckEventArgs args){
private void TriggerCheckFinishedEvent(UpdateEventArgs args){
CheckFinished?.Invoke(this, args);
}
@ -110,22 +107,22 @@ public void TriggerUpdateCheck(){
public void OnUpdateCheckFinished(int eventId, string versionTag, string downloadUrl){
if (versionTag != null && (owner.lastUpdateInfo == null || owner.lastUpdateInfo.VersionTag != versionTag)){
owner.CleanupDownload();
owner.lastUpdateInfo = new UpdateInfo(owner.settings, versionTag, downloadUrl);
owner.lastUpdateInfo = new UpdateInfo(owner.settings, eventId, versionTag, downloadUrl);
owner.lastUpdateInfo.BeginSilentDownload();
}
owner.TriggerCheckFinishedEvent(new UpdateCheckEventArgs(eventId, owner.lastUpdateInfo));
owner.TriggerCheckFinishedEvent(new UpdateEventArgs(eventId, owner.lastUpdateInfo));
}
public void OnUpdateAccepted(){
if (owner.lastUpdateInfo != null){
owner.TriggerUpdateAcceptedEvent(new UpdateAcceptedEventArgs(owner.lastUpdateInfo));
owner.TriggerUpdateAcceptedEvent(new UpdateEventArgs(owner.lastUpdateInfo));
}
}
public void OnUpdateDismissed(){
if (owner.lastUpdateInfo != null){
owner.TriggerUpdateDismissedEvent(new UpdateDismissedEventArgs(owner.lastUpdateInfo.VersionTag));
owner.TriggerUpdateDismissedEvent(new UpdateEventArgs(owner.lastUpdateInfo));
owner.CleanupDownload();
}
}

View File

@ -5,6 +5,7 @@
namespace TweetDuck.Updates{
sealed class UpdateInfo{
public int EventId { get; }
public string VersionTag { get; }
public string InstallerPath { get; }
@ -15,10 +16,11 @@ sealed class UpdateInfo{
private readonly string downloadUrl;
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.downloadUrl = downloadUrl;
this.EventId = eventId;
this.VersionTag = versionTag;
this.InstallerPath = Path.Combine(installerFolder, "TweetDuck."+versionTag+".exe");
}