1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-30 23:34:09 +02:00

Remove UpdaterSettings and fix not restarting the timer after a dismissed update

This commit is contained in:
chylex 2018-04-27 19:21:42 +02:00
parent 87109e5d01
commit b05c8d180f
9 changed files with 57 additions and 84 deletions

View File

@ -56,7 +56,7 @@ public bool IsWaiting{
private VideoPlayer videoPlayer; private VideoPlayer videoPlayer;
private AnalyticsManager analytics; private AnalyticsManager analytics;
public FormBrowser(UpdaterSettings updaterSettings){ public FormBrowser(){
InitializeComponent(); InitializeComponent();
Text = Program.BrandName; Text = Program.BrandName;
@ -97,7 +97,7 @@ public FormBrowser(UpdaterSettings updaterSettings){
UpdateTrayIcon(); UpdateTrayIcon();
this.updates = new UpdateHandler(browser, updaterSettings); this.updates = new UpdateHandler(browser, Program.InstallerPath);
this.updates.CheckFinished += updates_CheckFinished; this.updates.CheckFinished += updates_CheckFinished;
this.updates.UpdateAccepted += updates_UpdateAccepted; this.updates.UpdateAccepted += updates_UpdateAccepted;
this.updates.UpdateDismissed += updates_UpdateDismissed; this.updates.UpdateDismissed += updates_UpdateDismissed;
@ -237,25 +237,24 @@ private static void plugins_Executed(object sender, PluginErrorEventArgs e){
} }
private void updates_CheckFinished(object sender, UpdateCheckEventArgs e){ private void updates_CheckFinished(object sender, UpdateCheckEventArgs e){
this.InvokeAsyncSafe(() => { e.Result.Handle(update => {
e.Result.Handle(update => { string tag = update.VersionTag;
if (!update.IsUpdateDismissed){
if (update.IsUpdateNew){ if (tag != Program.VersionTag && tag != Config.DismissedUpdate){
browser.ShowUpdateNotification(update.VersionTag, update.ReleaseNotes); updates.PrepareUpdate(update);
} browser.ShowUpdateNotification(tag, update.ReleaseNotes);
else{ }
updates.StartTimer(); else{
} updates.StartTimer();
} }
}, ex => { }, ex => {
if (!ignoreUpdateCheckError){ if (!ignoreUpdateCheckError){
Program.Reporter.HandleException("Update Check Error", "An error occurred while checking for updates.", true, ex); Program.Reporter.HandleException("Update Check Error", "An error occurred while checking for updates.", true, ex);
updates.StartTimer(); updates.StartTimer();
} }
});
ignoreUpdateCheckError = true;
}); });
ignoreUpdateCheckError = true;
} }
private void updates_UpdateAccepted(object sender, UpdateEventArgs e){ private void updates_UpdateAccepted(object sender, UpdateEventArgs e){

View File

@ -218,19 +218,17 @@ private void btnCheckUpdates_Click(object sender, EventArgs e){
} }
private void updates_CheckFinished(object sender, UpdateCheckEventArgs e){ private void updates_CheckFinished(object sender, UpdateCheckEventArgs e){
this.InvokeAsyncSafe(() => { if (e.EventId == updateCheckEventId){
if (e.EventId == updateCheckEventId){ btnCheckUpdates.Enabled = true;
btnCheckUpdates.Enabled = true;
e.Result.Handle(update => { e.Result.Handle(update => {
if (!update.IsUpdateNew){ if (update.VersionTag == Program.VersionTag){
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);
} }
}, ex => { }, ex => {
Program.Reporter.HandleException("Update Check Error", "An error occurred while checking for updates.", true, ex); Program.Reporter.HandleException("Update Check Error", "An error occurred while checking for updates.", true, ex);
}); });
} }
});
} }
private void zoomUpdateTimer_Tick(object sender, EventArgs e){ private void zoomUpdateTimer_Tick(object sender, EventArgs e){

View File

@ -31,7 +31,7 @@ static class Program{
public static readonly string PluginPath = Path.Combine(ProgramPath, "plugins"); public static readonly string PluginPath = Path.Combine(ProgramPath, "plugins");
public static readonly string PluginDataPath = Path.Combine(StoragePath, "TD_Plugins"); public static readonly string PluginDataPath = Path.Combine(StoragePath, "TD_Plugins");
private static readonly string InstallerPath = Path.Combine(StoragePath, "TD_Updates"); public static readonly string InstallerPath = Path.Combine(StoragePath, "TD_Updates");
private static readonly string CefDataPath = Path.Combine(StoragePath, "TD_Chromium"); private static readonly string CefDataPath = Path.Combine(StoragePath, "TD_Chromium");
public static string UserConfigFilePath => Path.Combine(StoragePath, "TD_UserConfig.cfg"); public static string UserConfigFilePath => Path.Combine(StoragePath, "TD_UserConfig.cfg");
@ -150,13 +150,8 @@ private static void Main(){
Cef.Initialize(settings, false, new BrowserProcessHandler()); Cef.Initialize(settings, false, new BrowserProcessHandler());
Application.ApplicationExit += (sender, args) => ExitCleanup(); Application.ApplicationExit += (sender, args) => ExitCleanup();
UpdaterSettings updaterSettings = new UpdaterSettings(InstallerPath){ FormBrowser mainForm = new FormBrowser();
AllowPreReleases = Arguments.HasFlag(Arguments.ArgDebugUpdates),
DismissedUpdate = UserConfig.DismissedUpdate
};
FormBrowser mainForm = new FormBrowser(updaterSettings);
Application.Run(mainForm); Application.Run(mainForm);
if (mainForm.UpdateInstallerPath != null){ if (mainForm.UpdateInstallerPath != null){

View File

@ -325,7 +325,6 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\ScriptLoader.cs" /> <Compile Include="Resources\ScriptLoader.cs" />
<Compile Include="Updates\Events\UpdateEventArgs.cs" /> <Compile Include="Updates\Events\UpdateEventArgs.cs" />
<Compile Include="Updates\UpdaterSettings.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client"> <BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

View File

@ -5,7 +5,7 @@ namespace TweetDuck.Updates.Events{
sealed class UpdateCheckEventArgs : EventArgs{ sealed class UpdateCheckEventArgs : EventArgs{
public int EventId { get; } public int EventId { get; }
public Result<UpdateInfo> Result { get; } public Result<UpdateInfo> Result { get; }
public UpdateCheckEventArgs(int eventId, Result<UpdateInfo> result){ public UpdateCheckEventArgs(int eventId, Result<UpdateInfo> result){
this.EventId = eventId; this.EventId = eventId;
this.Result = result; this.Result = result;

View File

@ -11,10 +11,10 @@ sealed class UpdateCheckClient{
private const string ApiLatestRelease = "https://api.github.com/repos/chylex/TweetDuck/releases/latest"; private const string ApiLatestRelease = "https://api.github.com/repos/chylex/TweetDuck/releases/latest";
private const string UpdaterAssetName = "TweetDuck.Update.exe"; private const string UpdaterAssetName = "TweetDuck.Update.exe";
private readonly UpdaterSettings settings; private readonly string installerFolder;
public UpdateCheckClient(UpdaterSettings settings){ public UpdateCheckClient(string installerFolder){
this.settings = settings; this.installerFolder = installerFolder;
} }
public Task<UpdateInfo> Check(){ public Task<UpdateInfo> Check(){
@ -57,7 +57,7 @@ string AssetDownloadUrl(JsonObject obj){
string releaseNotes = (string)root["body"]; string releaseNotes = (string)root["body"];
string downloadUrl = ((Array)root["assets"]).Cast<JsonObject>().Where(IsUpdaterAsset).Select(AssetDownloadUrl).FirstOrDefault(); string downloadUrl = ((Array)root["assets"]).Cast<JsonObject>().Where(IsUpdaterAsset).Select(AssetDownloadUrl).FirstOrDefault();
return new UpdateInfo(settings, versionTag, releaseNotes, downloadUrl); return new UpdateInfo(versionTag, releaseNotes, downloadUrl, installerFolder);
} }
} }
} }

View File

@ -1,18 +1,20 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Core.Other.Interfaces; using TweetDuck.Core.Other.Interfaces;
using TweetDuck.Data; using TweetDuck.Data;
using TweetDuck.Updates.Events; using TweetDuck.Updates.Events;
using Timer = System.Windows.Forms.Timer;
namespace TweetDuck.Updates{ namespace TweetDuck.Updates{
sealed class UpdateHandler : IDisposable{ sealed class UpdateHandler : IDisposable{
public const int CheckCodeUpdatesDisabled = -1; public const int CheckCodeUpdatesDisabled = -1;
public const int CheckCodeNotOnTweetDeck = -2; public const int CheckCodeNotOnTweetDeck = -2;
private readonly UpdaterSettings settings;
private readonly UpdateCheckClient client; private readonly UpdateCheckClient client;
private readonly TaskScheduler scheduler;
private readonly ITweetDeckBrowser browser; private readonly ITweetDeckBrowser browser;
private readonly Timer timer; private readonly Timer timer;
@ -24,9 +26,9 @@ sealed class UpdateHandler : IDisposable{
private ushort lastEventId; private ushort lastEventId;
private UpdateInfo lastUpdateInfo; private UpdateInfo lastUpdateInfo;
public UpdateHandler(ITweetDeckBrowser browser, UpdaterSettings settings){ public UpdateHandler(ITweetDeckBrowser browser, string installerFolder){
this.settings = settings; this.client = new UpdateCheckClient(installerFolder);
this.client = new UpdateCheckClient(settings); this.scheduler = TaskScheduler.FromCurrentSynchronizationContext();
this.browser = browser; this.browser = browser;
this.browser.RegisterBridge("$TDU", new Bridge(this)); this.browser.RegisterBridge("$TDU", new Bridge(this));
@ -66,10 +68,6 @@ public void StartTimer(){
public int Check(bool force){ public int Check(bool force){
if (Program.UserConfig.EnableUpdateCheck || force){ if (Program.UserConfig.EnableUpdateCheck || force){
if (force){
settings.DismissedUpdate = null;
}
if (!browser.IsTweetDeckWebsite){ if (!browser.IsTweetDeckWebsite){
return CheckCodeNotOnTweetDeck; return CheckCodeNotOnTweetDeck;
} }
@ -77,8 +75,8 @@ public int Check(bool force){
int nextEventId = unchecked(++lastEventId); int nextEventId = unchecked(++lastEventId);
Task<UpdateInfo> checkTask = client.Check(); Task<UpdateInfo> checkTask = client.Check();
checkTask.ContinueWith(task => HandleUpdateCheckSuccessful(nextEventId, task.Result), TaskContinuationOptions.OnlyOnRanToCompletion); checkTask.ContinueWith(task => HandleUpdateCheckSuccessful(nextEventId, task.Result), CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, scheduler);
checkTask.ContinueWith(task => HandleUpdateCheckFailed(nextEventId, task.Exception.InnerException), TaskContinuationOptions.OnlyOnFaulted); checkTask.ContinueWith(task => HandleUpdateCheckFailed(nextEventId, task.Exception.InnerException), CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, scheduler);
return nextEventId; return nextEventId;
} }
@ -86,6 +84,12 @@ public int Check(bool force){
return CheckCodeUpdatesDisabled; return CheckCodeUpdatesDisabled;
} }
public void PrepareUpdate(UpdateInfo info){
CleanupDownload();
lastUpdateInfo = info;
lastUpdateInfo.BeginSilentDownload();
}
public void BeginUpdateDownload(Form ownerForm, UpdateInfo updateInfo, Action<UpdateInfo> onFinished){ public void BeginUpdateDownload(Form ownerForm, UpdateInfo updateInfo, Action<UpdateInfo> onFinished){
UpdateDownloadStatus status = updateInfo.DownloadStatus; UpdateDownloadStatus status = updateInfo.DownloadStatus;
@ -121,12 +125,6 @@ public void CleanupDownload(){
} }
private void HandleUpdateCheckSuccessful(int eventId, UpdateInfo info){ private void HandleUpdateCheckSuccessful(int eventId, UpdateInfo info){
if (info.IsUpdateNew && !info.IsUpdateDismissed){
CleanupDownload();
lastUpdateInfo = info;
lastUpdateInfo.BeginSilentDownload();
}
CheckFinished?.Invoke(this, new UpdateCheckEventArgs(eventId, new Result<UpdateInfo>(info))); CheckFinished?.Invoke(this, new UpdateCheckEventArgs(eventId, new Result<UpdateInfo>(info)));
} }
@ -148,9 +146,7 @@ private void TriggerUpdateDelayedEvent(){
private void TriggerUpdateDismissedEvent(){ private void TriggerUpdateDismissedEvent(){
if (lastUpdateInfo != null){ if (lastUpdateInfo != null){
settings.DismissedUpdate = lastUpdateInfo.VersionTag;
UpdateDismissed?.Invoke(this, new UpdateEventArgs(lastUpdateInfo)); UpdateDismissed?.Invoke(this, new UpdateEventArgs(lastUpdateInfo));
CleanupDownload(); CleanupDownload();
} }
} }

View File

@ -8,24 +8,21 @@ sealed class UpdateInfo{
public string VersionTag { get; } public string VersionTag { get; }
public string ReleaseNotes { get; } public string ReleaseNotes { get; }
public string InstallerPath { get; } public string InstallerPath { get; }
public bool IsUpdateNew => VersionTag != Program.VersionTag;
public bool IsUpdateDismissed => VersionTag == settings.DismissedUpdate;
public UpdateDownloadStatus DownloadStatus { get; private set; } public UpdateDownloadStatus DownloadStatus { get; private set; }
public Exception DownloadError { get; private set; } public Exception DownloadError { get; private set; }
private readonly UpdaterSettings settings;
private readonly string downloadUrl; private readonly string downloadUrl;
private readonly string installerFolder;
private WebClient currentDownload; private WebClient currentDownload;
public UpdateInfo(UpdaterSettings settings, string versionTag, string releaseNotes, string downloadUrl){ public UpdateInfo(string versionTag, string releaseNotes, string downloadUrl, string installerFolder){
this.settings = settings;
this.downloadUrl = downloadUrl; this.downloadUrl = downloadUrl;
this.installerFolder = installerFolder;
this.VersionTag = versionTag; this.VersionTag = versionTag;
this.ReleaseNotes = releaseNotes; this.ReleaseNotes = releaseNotes;
this.InstallerPath = Path.Combine(settings.InstallerDownloadFolder, "TweetDuck."+versionTag+".exe"); this.InstallerPath = Path.Combine(installerFolder, $"TweetDuck.{versionTag}.exe");;
} }
public void BeginSilentDownload(){ public void BeginSilentDownload(){
@ -39,7 +36,7 @@ public void BeginSilentDownload(){
} }
try{ try{
Directory.CreateDirectory(settings.InstallerDownloadFolder); Directory.CreateDirectory(installerFolder);
}catch(Exception e){ }catch(Exception e){
DownloadError = e; DownloadError = e;
DownloadStatus = UpdateDownloadStatus.Failed; DownloadStatus = UpdateDownloadStatus.Failed;

View File

@ -1,11 +0,0 @@
namespace TweetDuck.Updates{
sealed class UpdaterSettings{
public string InstallerDownloadFolder { get; }
public string DismissedUpdate { get; set; }
public UpdaterSettings(string installerDownloadFolder){
this.InstallerDownloadFolder = installerDownloadFolder;
}
}
}