-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Significantly simplify UpdaterPlugin (#973)
The updater **no longer downloads or installs updates**. It only notifies the user of an update being available. This was done to avoid having to show a changelog[^1]. Other changes: - When the user has explicitly checked for an update, the updater will notify the user whether an update is available or not. - Whenever a release is skipped by the user, this is now saved immediately. Previously, this was only saved when the user closed Whim. - Whim was previously unaware of its current version. This was because it was inspecting the incorrect attribute from the assembly. This has been fixed. [^1]: WinUI 3 does not have native Markdown support in WinUI 3, nor is there a CommunityToolkit control. The prior implementation used a WebView2 to display the changelog. This was removed as the containing window would sometimes hide the non-WebView2 controls.
- Loading branch information
Showing
26 changed files
with
517 additions
and
1,158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Whim.Tests; | ||
|
||
public class SavedStateTransformTests | ||
{ | ||
[Theory, AutoSubstituteData<StoreCustomization>] | ||
internal void Execute(IContext ctx, IInternalContext internalCtx, MutableRootSector rootSector) | ||
{ | ||
// Given | ||
SaveStateTransform sut = new(); | ||
|
||
// When | ||
Result<Unit> result = sut.Execute(ctx, internalCtx, rootSector); | ||
|
||
// Then | ||
Assert.True(result.IsSuccessful); | ||
ctx.PluginManager.Received(1).SaveState(); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using FluentAssertions; | ||
using Microsoft.UI.Dispatching; | ||
using NSubstitute; | ||
using Octokit; | ||
using Whim.TestUtils; | ||
using Xunit; | ||
|
||
namespace Whim.Updater.Tests; | ||
|
||
[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")] | ||
public class ReleaseManagerTests | ||
{ | ||
#region CheckForUpdates | ||
[Theory, AutoSubstituteData<UpdaterPluginCustomization>] | ||
public async Task CheckForUpdates_WhenNoReleases(IContext ctx, IGitHubClient client) | ||
{ | ||
// Given | ||
UpdaterPlugin plugin = new(ctx, new UpdaterConfig()); | ||
ReleaseManager sut = new(ctx, plugin) { GitHubClient = client }; | ||
|
||
// When | ||
await sut.CheckForUpdates(false); | ||
|
||
// Then | ||
ctx.NativeManager.DidNotReceive().TryEnqueue(Arg.Any<DispatcherQueueHandler>()); | ||
ctx.Store.Received(1).Dispatch(Arg.Any<SaveStateTransform>()); | ||
Assert.NotNull(plugin.LastCheckedForUpdates); | ||
} | ||
|
||
[Theory, AutoSubstituteData<UpdaterPluginCustomization>] | ||
public async Task CheckForUpdates_ReleaseIsSkipped(IContext ctx, IGitHubClient client) | ||
{ | ||
// Given | ||
Release release = Data.CreateRelease242(tagName: "v0.1.265-alpha+bc5c56c4"); | ||
client.Repository.Release.GetAll("dalyIsaac", "Whim", Arg.Any<ApiOptions>()).Returns([release]); | ||
|
||
UpdaterPlugin plugin = new(ctx, new UpdaterConfig() { ReleaseChannel = ReleaseChannel.Alpha }); | ||
plugin.SkipRelease(release.TagName); | ||
ctx.Store.ClearReceivedCalls(); | ||
|
||
ReleaseManager sut = new(ctx, plugin) { GitHubClient = client }; | ||
|
||
// When | ||
await sut.CheckForUpdates(false); | ||
|
||
// Then | ||
ctx.NativeManager.DidNotReceive().TryEnqueue(Arg.Any<DispatcherQueueHandler>()); | ||
ctx.Store.Received(1).Dispatch(Arg.Any<SaveStateTransform>()); | ||
Assert.NotNull(plugin.LastCheckedForUpdates); | ||
} | ||
|
||
[Theory, AutoSubstituteData<UpdaterPluginCustomization>] | ||
public async Task CheckForUpdates_NewRelease(IContext ctx, IGitHubClient client) | ||
{ | ||
// Given | ||
Release release = Data.CreateRelease242(tagName: "v0.1.265-alpha+bc5c56c4"); | ||
client.Repository.Release.GetAll("dalyIsaac", "Whim", Arg.Any<ApiOptions>()).Returns([release]); | ||
|
||
UpdaterPlugin plugin = new(ctx, new UpdaterConfig() { ReleaseChannel = ReleaseChannel.Alpha }); | ||
ReleaseManager sut = new(ctx, plugin) { GitHubClient = client }; | ||
|
||
// When | ||
await sut.CheckForUpdates(false); | ||
|
||
// Then | ||
ctx.NativeManager.Received(1).TryEnqueue(Arg.Any<DispatcherQueueHandler>()); | ||
ctx.Store.Received(1).Dispatch(Arg.Any<SaveStateTransform>()); | ||
Assert.NotNull(plugin.LastCheckedForUpdates); | ||
} | ||
#endregion | ||
|
||
#region GetNotInstalledReleases | ||
[Theory, AutoSubstituteData<UpdaterPluginCustomization>] | ||
public async Task GetNotInstalledReleases_WhenNoReleases(IContext ctx, IGitHubClient client) | ||
{ | ||
// Given | ||
UpdaterPlugin plugin = new(ctx, new UpdaterConfig()); | ||
ReleaseManager sut = new(ctx, plugin) { GitHubClient = client }; | ||
|
||
// When | ||
IEnumerable<ReleaseInfo> releases = await sut.GetNotInstalledReleases(); | ||
|
||
// Then | ||
Assert.Empty(releases); | ||
} | ||
|
||
[Theory, AutoSubstituteData<UpdaterPluginCustomization>] | ||
public async Task GetNotInstalledReleases_InvalidVersion(IContext ctx, IGitHubClient client) | ||
{ | ||
// Given | ||
UpdaterPlugin plugin = new(ctx, new UpdaterConfig()); | ||
ReleaseManager sut = new(ctx, plugin) { GitHubClient = client }; | ||
client | ||
.Repository.Release.GetAll("dalyIsaac", "Whim", Arg.Any<ApiOptions>()) | ||
.Returns([Data.CreateRelease242(tagName: "welp")]); | ||
|
||
// When | ||
IEnumerable<ReleaseInfo> releases = await sut.GetNotInstalledReleases(); | ||
|
||
// Then | ||
Assert.Empty(releases); | ||
} | ||
|
||
[Theory, AutoSubstituteData<UpdaterPluginCustomization>] | ||
public async Task GetNotInstalledReleases_DifferentChannel(IContext ctx, IGitHubClient client) | ||
{ | ||
// Given | ||
UpdaterPlugin plugin = new(ctx, new UpdaterConfig()); | ||
ReleaseManager sut = new(ctx, plugin) { GitHubClient = client }; | ||
client | ||
.Repository.Release.GetAll("dalyIsaac", "Whim", Arg.Any<ApiOptions>()) | ||
.Returns([Data.CreateRelease242(tagName: "v0.1.263-beta+bc5c56c4")]); | ||
|
||
// When | ||
IEnumerable<ReleaseInfo> releases = await sut.GetNotInstalledReleases(); | ||
|
||
// Then | ||
Assert.Empty(releases); | ||
} | ||
|
||
[Theory, AutoSubstituteData<UpdaterPluginCustomization>] | ||
public async Task GetNotInstalledReleases_OlderVersion(IContext ctx, IGitHubClient client) | ||
{ | ||
// Given | ||
UpdaterPlugin plugin = new(ctx, new UpdaterConfig()); | ||
ReleaseManager sut = new(ctx, plugin) { GitHubClient = client }; | ||
client | ||
.Repository.Release.GetAll("dalyIsaac", "Whim", Arg.Any<ApiOptions>()) | ||
.Returns([Data.CreateRelease242(tagName: "v0.1.261-alpha+bc5c56c4")]); | ||
|
||
// When | ||
IEnumerable<ReleaseInfo> releases = await sut.GetNotInstalledReleases(); | ||
|
||
// Then | ||
Assert.Empty(releases); | ||
} | ||
|
||
[Theory, AutoSubstituteData<UpdaterPluginCustomization>] | ||
public async Task GetNotInstalledReleases_Ordered(IContext ctx, IGitHubClient client) | ||
{ | ||
// Given | ||
UpdaterPlugin plugin = new(ctx, new UpdaterConfig() { ReleaseChannel = ReleaseChannel.Alpha }); | ||
ReleaseManager sut = new(ctx, plugin) { GitHubClient = client }; | ||
|
||
string[] orderedReleases = | ||
[ | ||
"v0.1.261-alpha+bc5c56c4", | ||
"v0.1.262-beta+bc5c56c4", | ||
"v0.1.263-stable+bc5c56c4", | ||
"v0.1.264-alpha+bc5c56c4", | ||
"v0.2.265-alpha+bc5c56c4", | ||
"v1.1.266-alpha+bc5c56c4" | ||
]; | ||
string[] expectedReleases = ["v0.1.264-alpha+bc5c56c4", "v0.2.265-alpha+bc5c56c4", "v1.1.266-alpha+bc5c56c4"]; | ||
|
||
client | ||
.Repository.Release.GetAll("dalyIsaac", "Whim", Arg.Any<ApiOptions>()) | ||
.Returns(orderedReleases.Select(t => Data.CreateRelease242(tagName: t)).ToArray()); | ||
|
||
// When | ||
IEnumerable<ReleaseInfo> releases = await sut.GetNotInstalledReleases(); | ||
|
||
// Then | ||
releases.Select(r => r.Release.TagName).Should().BeEquivalentTo(expectedReleases); | ||
} | ||
#endregion | ||
} |
Oops, something went wrong.