diff --git a/SoundSwitch/Framework/Updater/Remind/PostponeService.cs b/SoundSwitch/Framework/Updater/Remind/PostponeService.cs
new file mode 100644
index 0000000000..f5867f8a4b
--- /dev/null
+++ b/SoundSwitch/Framework/Updater/Remind/PostponeService.cs
@@ -0,0 +1,65 @@
+using System;
+using Serilog;
+using SoundSwitch.Framework.Configuration;
+
+namespace SoundSwitch.Framework.Updater.Remind
+{
+ public class PostponeService
+ {
+ ///
+ /// Set the release as postponed
+ ///
+ ///
+ public void PostponeRelease(Release release)
+ {
+ var postponed = AppConfigs.Configuration.Postponed;
+ try
+ {
+ if (postponed == null || postponed.Version < release.ReleaseVersion)
+ {
+ AppConfigs.Configuration.Postponed = new ReleasePostponed(release.ReleaseVersion, DateTime.UtcNow + 3 * TimeSpan.FromSeconds(AppConfigs.Configuration.UpdateCheckInterval), 1);
+ return;
+ }
+
+ if (postponed.Version == release.ReleaseVersion)
+ {
+ var postponedCount = postponed.Count + 1;
+ if (postponedCount > 5)
+ {
+ postponedCount = 5;
+ }
+ AppConfigs.Configuration.Postponed = postponed with
+ {
+ Count = postponedCount, Until = DateTime.UtcNow + (3 + (postponedCount ^ 2)) * TimeSpan.FromSeconds(AppConfigs.Configuration.UpdateCheckInterval)
+ };
+ }
+ }
+ finally
+ {
+ Log.Information($"Release {release} set as {AppConfigs.Configuration.Postponed}");
+ AppConfigs.Configuration.Save();
+ }
+ }
+
+ ///
+ /// Return true if the release should be postponed, false if it can be done now.
+ ///
+ ///
+ ///
+ public bool ShouldPostpone(Release release)
+ {
+ var postponed = AppConfigs.Configuration.Postponed;
+ if (postponed == null)
+ {
+ return false;
+ }
+
+ if (release.ReleaseVersion > postponed.Version)
+ {
+ return false;
+ }
+
+ return postponed.Until > DateTime.UtcNow;
+ }
+ }
+}
\ No newline at end of file
diff --git a/SoundSwitch/Framework/Updater/Remind/ReleasePostponed.cs b/SoundSwitch/Framework/Updater/Remind/ReleasePostponed.cs
index 1405f3d312..d49af551e1 100644
--- a/SoundSwitch/Framework/Updater/Remind/ReleasePostponed.cs
+++ b/SoundSwitch/Framework/Updater/Remind/ReleasePostponed.cs
@@ -2,21 +2,5 @@
namespace SoundSwitch.Framework.Updater.Remind
{
- public record ReleasePostponed(Version Version, DateTime Until)
- {
- ///
- /// Return true if the release should be postponed, false if it can be done now.
- ///
- ///
- ///
- public bool ShouldPostpone(Release release)
- {
- if (release.ReleaseVersion > Version)
- {
- return false;
- }
-
- return Until > DateTime.UtcNow;
- }
- }
+ public record ReleasePostponed(Version Version, DateTime Until, uint Count);
}
\ No newline at end of file
diff --git a/SoundSwitch/Model/AppModel.cs b/SoundSwitch/Model/AppModel.cs
index d78260a185..475ae70efc 100644
--- a/SoundSwitch/Model/AppModel.cs
+++ b/SoundSwitch/Model/AppModel.cs
@@ -34,7 +34,6 @@
using SoundSwitch.Framework.Profile.Trigger;
using SoundSwitch.Framework.Updater;
using SoundSwitch.Framework.Updater.Job;
-using SoundSwitch.Framework.Updater.Remind;
using SoundSwitch.Framework.WinApi;
using SoundSwitch.Framework.WinApi.Keyboard;
using SoundSwitch.Localization;
@@ -161,16 +160,6 @@ public UpdateMode UpdateMode
}
}
- public ReleasePostponed ReleasePostponed
- {
- get => AppConfigs.Configuration.Postponed;
- set
- {
- AppConfigs.Configuration.Postponed = value;
- AppConfigs.Configuration.Save();
- }
- }
-
public Language Language
{
get => AppConfigs.Configuration.Language;
diff --git a/SoundSwitch/Model/IAppModel.cs b/SoundSwitch/Model/IAppModel.cs
index 1203b67c34..ac23ac2c04 100644
--- a/SoundSwitch/Model/IAppModel.cs
+++ b/SoundSwitch/Model/IAppModel.cs
@@ -21,7 +21,6 @@
using SoundSwitch.Framework.NotificationManager;
using SoundSwitch.Framework.Profile;
using SoundSwitch.Framework.Updater;
-using SoundSwitch.Framework.Updater.Remind;
using SoundSwitch.Framework.WinApi.Keyboard;
using SoundSwitch.Localization.Factory;
using SoundSwitch.UI.Component;
@@ -115,11 +114,6 @@ public interface IAppModel : IDisposable
///
IAudioDeviceLister ActiveUnpluggedAudioLister { get; set; }
- ///
- /// Do we have a postponement for a specific release
- ///
- ReleasePostponed ReleasePostponed { get; set; }
-
#endregion
#region Events
diff --git a/SoundSwitch/UI/Component/TrayIcon.cs b/SoundSwitch/UI/Component/TrayIcon.cs
index af0ff220b5..eb1b9e1a65 100644
--- a/SoundSwitch/UI/Component/TrayIcon.cs
+++ b/SoundSwitch/UI/Component/TrayIcon.cs
@@ -32,6 +32,7 @@
using SoundSwitch.Framework.TrayIcon.Icon;
using SoundSwitch.Framework.TrayIcon.TooltipInfoManager;
using SoundSwitch.Framework.Updater;
+using SoundSwitch.Framework.Updater.Remind;
using SoundSwitch.Localization;
using SoundSwitch.Model;
using SoundSwitch.Properties;
@@ -58,6 +59,7 @@ public sealed class TrayIcon : IDisposable
private readonly ContextMenuStrip _selectionMenu = new();
private readonly ContextMenuStrip _settingsMenu = new();
+ private readonly PostponeService _postponeService = new();
private readonly SynchronizationContext _context =
SynchronizationContext.Current ?? new SynchronizationContext();
@@ -241,15 +243,14 @@ private void SetEventHandlers()
private void NewReleaseAvailable(object sender, UpdateChecker.NewReleaseEvent newReleaseEvent)
{
-
_updateMenuItem.Tag = newReleaseEvent.Release;
_updateMenuItem.Text = string.Format(TrayIconStrings.updateAvailable, newReleaseEvent.Release.ReleaseVersion);
- var configurationPostponed = AppConfigs.Configuration.Postponed;
- if (configurationPostponed?.ShouldPostpone(newReleaseEvent.Release) ?? false)
+ if (_postponeService.ShouldPostpone(newReleaseEvent.Release))
{
- Log.Information("Release {release} has been postponed to {date:yyyy-MM-dd hh:mm}", newReleaseEvent.Release, configurationPostponed.Until);
+ Log.Information("Release {release} has been postponed", newReleaseEvent.Release);
return;
}
+
StartAnimationIconUpdate();
NotifyIcon.BalloonTipClicked += OnUpdateClick;
NotifyIcon.ShowBalloonTip(3000, string.Format(TrayIconStrings.versionAvailable, newReleaseEvent.Release.ReleaseVersion), newReleaseEvent.Release.Name + '\n' + TrayIconStrings.clickToUpdate, ToolTipIcon.Info);
diff --git a/SoundSwitch/UI/Forms/UpdateDownloadForm.cs b/SoundSwitch/UI/Forms/UpdateDownloadForm.cs
index 3d3a73d1d7..74c150df4c 100644
--- a/SoundSwitch/UI/Forms/UpdateDownloadForm.cs
+++ b/SoundSwitch/UI/Forms/UpdateDownloadForm.cs
@@ -15,12 +15,10 @@
using System;
using System.Windows.Forms;
using Serilog;
-using SoundSwitch.Framework.Configuration;
using SoundSwitch.Framework.Updater;
using SoundSwitch.Framework.Updater.Installer;
using SoundSwitch.Framework.Updater.Remind;
using SoundSwitch.Localization;
-using SoundSwitch.Model;
using SoundSwitch.Properties;
using SoundSwitch.UI.Component;
@@ -30,6 +28,7 @@ public sealed partial class UpdateDownloadForm : Form
{
private WebFile _releaseFile;
private Release _releaseInfo;
+ private readonly PostponeService _postponeService = new();
public UpdateDownloadForm()
{
@@ -116,7 +115,7 @@ private void cancelButton_Click(object sender, EventArgs e)
}
else
{
- AppModel.Instance.ReleasePostponed = new ReleasePostponed(_releaseInfo.ReleaseVersion, DateTime.UtcNow + 3 * TimeSpan.FromSeconds(AppConfigs.Configuration.UpdateCheckInterval));
+ _postponeService.PostponeRelease(_releaseInfo);
}
Close();
}