Skip to content

Commit a2b507e

Browse files
committed
feat(Update::Postpone): User can now decide to postpone the update and be reminded about it at a later date.
1 parent 2029a9b commit a2b507e

14 files changed

+103
-4
lines changed

SoundSwitch/Framework/Configuration/ISoundSwitchConfiguration.cs

+5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using JetBrains.Annotations;
1718
using SoundSwitch.Common.Framework.Audio.Device;
1819
using SoundSwitch.Framework.DeviceCyclerManager;
1920
using SoundSwitch.Framework.NotificationManager;
2021
using SoundSwitch.Framework.Profile;
2122
using SoundSwitch.Framework.TrayIcon.Icon;
2223
using SoundSwitch.Framework.TrayIcon.TooltipInfoManager.TootipInfo;
2324
using SoundSwitch.Framework.Updater;
25+
using SoundSwitch.Framework.Updater.Remind;
2426
using SoundSwitch.Framework.WinApi.Keyboard;
2527
using SoundSwitch.Localization.Factory;
2628

@@ -69,6 +71,9 @@ public interface ISoundSwitchConfiguration : IConfiguration
6971
/// Unique ID assigned at installation
7072
/// </summary>
7173
Guid UniqueInstallationId { get; set; }
74+
75+
[CanBeNull]
76+
ReleasePostponed Postponed { get; set; }
7277

7378
/// <summary>
7479
/// Fields of the config that got migrated

SoundSwitch/Framework/Configuration/SoundSwitchConfiguration.cs

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using SoundSwitch.Framework.TrayIcon.Icon;
2828
using SoundSwitch.Framework.TrayIcon.TooltipInfoManager.TootipInfo;
2929
using SoundSwitch.Framework.Updater;
30+
using SoundSwitch.Framework.Updater.Remind;
3031
using SoundSwitch.Framework.WinApi.Keyboard;
3132
using SoundSwitch.Localization.Factory;
3233

@@ -101,6 +102,8 @@ public SoundSwitchConfiguration()
101102

102103
public HashSet<Profile.Profile> Profiles { get; set; } = new();
103104

105+
public ReleasePostponed Postponed { get; set; }
106+
104107
/// <summary>
105108
/// Fields of the config that got migrated
106109
/// </summary>

SoundSwitch/Framework/Updater/Installer/WebFile.cs

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public WebFile(Uri fileUri, string filePath)
4545

4646
public Uri FileUri { get; }
4747
public string FilePath { get; }
48+
public bool DownloadStarted { get; private set; }
4849

4950
private static string DefaultFilePath(Uri fileUri)
5051
{
@@ -88,6 +89,7 @@ public void DownloadFile()
8889
{
8990
await using (var stream = File.OpenWrite(FilePath))
9091
{
92+
DownloadStarted = true;
9193
await FileDownloader.DownloadFileAsync(
9294
FileUri,
9395
stream,

SoundSwitch/Framework/Updater/Release.cs

+5
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@ public Release(Version releaseVersion, GitHubRelease.Asset asset, string name)
3030
public GitHubRelease.Asset Asset { get; private set; }
3131
public List<string> Changelog { get; } = new List<string>();
3232
public string Name { get; private set; }
33+
34+
public override string ToString()
35+
{
36+
return $"{nameof(ReleaseVersion)}: {ReleaseVersion}, {nameof(Name)}: {Name}";
37+
}
3338
}
3439
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace SoundSwitch.Framework.Updater.Remind
4+
{
5+
public record ReleasePostponed(Version Version, DateTime Until)
6+
{
7+
/// <summary>
8+
/// Return true if the release should be postponed, false if it can be done now.
9+
/// </summary>
10+
/// <param name="release"></param>
11+
/// <returns></returns>
12+
public bool ShouldPostpone(Release release)
13+
{
14+
if (release.ReleaseVersion > Version)
15+
{
16+
return false;
17+
}
18+
19+
return Until > DateTime.UtcNow;
20+
}
21+
}
22+
}

SoundSwitch/Framework/Updater/UpdateChecker.cs

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ private bool ProcessRelease(GitHubRelease serverRelease)
6666
return false;
6767
}
6868

69+
70+
6971
var changelog = Regex.Split(serverRelease.body, "\r\n|\r|\n");
7072
var release = new Release(version, installer, serverRelease.name);
7173
release.Changelog.AddRange(changelog);

SoundSwitch/Localization/UpdateDownloadStrings.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SoundSwitch/Localization/UpdateDownloadStrings.fr.resx

+3
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,7 @@
115115
<data name="notSigned" xml:space="preserve">
116116
<value>La mise à jour téléchargée ne comporte pas de signature valide. Nous vous conseillons de supprimer le fichier et de contacter le développeur !</value>
117117
</data>
118+
<data name="remindMe" xml:space="preserve">
119+
<value>Plus tard</value>
120+
</data>
118121
</root>

SoundSwitch/Localization/UpdateDownloadStrings.resx

+3
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,7 @@
115115
<data name="notSignedTitle" xml:space="preserve">
116116
<value>Invalid Digital Signature</value>
117117
</data>
118+
<data name="remindMe" xml:space="preserve">
119+
<value>Later</value>
120+
</data>
118121
</root>

SoundSwitch/Model/AppModel.cs

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
using SoundSwitch.Framework.Profile.Trigger;
3535
using SoundSwitch.Framework.Updater;
3636
using SoundSwitch.Framework.Updater.Job;
37+
using SoundSwitch.Framework.Updater.Remind;
3738
using SoundSwitch.Framework.WinApi;
3839
using SoundSwitch.Framework.WinApi.Keyboard;
3940
using SoundSwitch.Localization;
@@ -160,6 +161,16 @@ public UpdateMode UpdateMode
160161
}
161162
}
162163

164+
public ReleasePostponed ReleasePostponed
165+
{
166+
get => AppConfigs.Configuration.Postponed;
167+
set
168+
{
169+
AppConfigs.Configuration.Postponed = value;
170+
AppConfigs.Configuration.Save();
171+
}
172+
}
173+
163174
public Language Language
164175
{
165176
get => AppConfigs.Configuration.Language;

SoundSwitch/Model/IAppModel.cs

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using SoundSwitch.Framework.NotificationManager;
2222
using SoundSwitch.Framework.Profile;
2323
using SoundSwitch.Framework.Updater;
24+
using SoundSwitch.Framework.Updater.Remind;
2425
using SoundSwitch.Framework.WinApi.Keyboard;
2526
using SoundSwitch.Localization.Factory;
2627
using SoundSwitch.UI.Component;
@@ -114,6 +115,11 @@ public interface IAppModel : IDisposable
114115
/// </summary>
115116
IAudioDeviceLister ActiveUnpluggedAudioLister { get; set; }
116117

118+
/// <summary>
119+
/// Do we have a postponement for a specific release
120+
/// </summary>
121+
ReleasePostponed ReleasePostponed { get; set; }
122+
117123
#endregion
118124

119125
#region Events

SoundSwitch/SoundSwitch.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<ItemGroup>
3636
<PackageReference Include="AuthenticodeExaminer" Version="0.3.0" />
3737
<PackageReference Include="ContribSentry" Version="4.0.0" />
38+
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" />
3839
<PackageReference Include="Job.Scheduler" Version="2.2.0" />
3940
<PackageReference Include="Markdig" Version="0.24.0" />
4041
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />

SoundSwitch/UI/Component/TrayIcon.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,16 @@ private void SetEventHandlers()
241241

242242
private void NewReleaseAvailable(object sender, UpdateChecker.NewReleaseEvent newReleaseEvent)
243243
{
244-
StartAnimationIconUpdate();
244+
245245
_updateMenuItem.Tag = newReleaseEvent.Release;
246246
_updateMenuItem.Text = string.Format(TrayIconStrings.updateAvailable, newReleaseEvent.Release.ReleaseVersion);
247+
var configurationPostponed = AppConfigs.Configuration.Postponed;
248+
if (configurationPostponed?.ShouldPostpone(newReleaseEvent.Release) ?? false)
249+
{
250+
Log.Information("Release {release} has been postponed to {date:yyyy-MM-dd hh:mm}", newReleaseEvent.Release, configurationPostponed.Until);
251+
return;
252+
}
253+
StartAnimationIconUpdate();
247254
NotifyIcon.BalloonTipClicked += OnUpdateClick;
248255
NotifyIcon.ShowBalloonTip(3000, string.Format(TrayIconStrings.versionAvailable, newReleaseEvent.Release.ReleaseVersion), newReleaseEvent.Release.Name + '\n' + TrayIconStrings.clickToUpdate, ToolTipIcon.Info);
249256
}

SoundSwitch/UI/Forms/UpdateDownloadForm.cs

+23-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
using System;
1616
using System.Windows.Forms;
1717
using Serilog;
18+
using SoundSwitch.Framework.Configuration;
1819
using SoundSwitch.Framework.Updater;
1920
using SoundSwitch.Framework.Updater.Installer;
21+
using SoundSwitch.Framework.Updater.Remind;
2022
using SoundSwitch.Localization;
23+
using SoundSwitch.Model;
2124
using SoundSwitch.Properties;
2225
using SoundSwitch.UI.Component;
2326

@@ -26,6 +29,7 @@ namespace SoundSwitch.UI.Forms
2629
public sealed partial class UpdateDownloadForm : Form
2730
{
2831
private WebFile _releaseFile;
32+
private Release _releaseInfo;
2933

3034
public UpdateDownloadForm()
3135
{
@@ -40,6 +44,7 @@ public UpdateDownloadForm()
4044

4145
public void DownloadRelease(Release release)
4246
{
47+
_releaseInfo = release;
4348
installButton.Enabled = true;
4449
changeLog.SetChangelog(release.Changelog);
4550
Name = release.Name;
@@ -83,7 +88,14 @@ public void DownloadRelease(Release release)
8388
}
8489

8590
new UpdateRunner().RunUpdate(_releaseFile, "/SILENT");
86-
BeginInvoke((Action) Close);
91+
if (InvokeRequired)
92+
{
93+
BeginInvoke((Action) Close);
94+
}
95+
else
96+
{
97+
Close();
98+
}
8799
};
88100
ShowDialog();
89101
}
@@ -92,13 +104,20 @@ private void LocalizeForm()
92104
{
93105
// Misc
94106
changeLogGroup.Text = UpdateDownloadStrings.changelog;
95-
cancelButton.Text = UpdateDownloadStrings.cancel;
107+
cancelButton.Text = UpdateDownloadStrings.remindMe;
96108
installButton.Text = UpdateDownloadStrings.install;
97109
}
98110

99111
private void cancelButton_Click(object sender, EventArgs e)
100112
{
101-
_releaseFile.CancelDownload();
113+
if (_releaseFile.DownloadStarted)
114+
{
115+
_releaseFile.CancelDownload();
116+
}
117+
else
118+
{
119+
AppModel.Instance.ReleasePostponed = new ReleasePostponed(_releaseInfo.ReleaseVersion, DateTime.UtcNow + 3 * TimeSpan.FromSeconds(AppConfigs.Configuration.UpdateCheckInterval));
120+
}
102121
Close();
103122
}
104123

@@ -108,6 +127,7 @@ private void installButton_Click(object sender, EventArgs e)
108127
downloadProgress.Visible = true;
109128
_releaseFile.DownloadFile();
110129
installButton.Enabled = false;
130+
cancelButton.Text = UpdateDownloadStrings.cancel;
111131
}
112132

113133
private void UpdateDownloadForm_FormClosing(object sender, FormClosingEventArgs e)

0 commit comments

Comments
 (0)