Skip to content

Commit

Permalink
Add UpdateDetectedAsync
Browse files Browse the repository at this point in the history
See #571
  • Loading branch information
Deadpikle committed Aug 16, 2024
1 parent 4c5bde7 commit 5558735
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
* `AppCast? SparkleUpdater.AppCastCache` holds the most recently deserialized app cast information.
* `AppCastItem` has a new `Channel` property. Use it along with `ChannelAppCastFilter` if you want to use channels that way instead of via your `<Version>` property. In the app cast generator, use the `--channel` option to set this (note that using this will set ALL items added to the app cast to that specific channel; to add only new items to your app cast instead of rewriting the whole thing, use the `--reparse-existing` option).
* App cast generator has a new `--use-ed25519-signature-attribute` to use `edSignature` in its XML output instead of `signature` (json output unaffected) to match the original Sparkle library
* Added `UpdateDetectedAsync` -- prioritized over `UpdateDetected` if both `UpdateDetectedAsync` and `UpdateDetected` are implemented.

## Updating from 0.X or 1.X to 2.X

Expand Down
11 changes: 10 additions & 1 deletion src/NetSparkle/NetSparkleDelegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ namespace NetSparkleUpdater
public delegate void LoopFinishedOperation(object sender, bool updateRequired);

/// <summary>
/// An update was detected for the user's currently running software
/// An update was detected for the user's currently running software.
/// If both this and UpdateDetectedAsync are implemented, UpdateDetectedAsync is prioritized.
/// </summary>
/// <param name="sender">the object that initiated the call</param>
/// <param name="e">Information about the update that was detected</param>
public delegate void UpdateDetected(object sender, UpdateDetectedEventArgs e);

/// <summary>
/// An update was detected for the user's currently running software.
/// If both this and UpdateDetected are implemented, UpdateDetectedAsync is prioritized.
/// </summary>
/// <param name="sender">the object that initiated the call</param>
/// <param name="e">Information about the update that was detected</param>
public delegate Task UpdateDetectedAsync(object sender, UpdateDetectedEventArgs e);

/// <summary>
/// <see cref="SparkleUpdater"/> has started checking for updates
/// </summary>
Expand Down
24 changes: 19 additions & 5 deletions src/NetSparkle/SparkleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1801,9 +1801,16 @@ private async Task<UpdateInfo> CheckForUpdates(bool isUserManuallyCheckingForUpd
// UpdateDetected allows for catching and overriding the update handling,
// so if the user has implemented it, tell them there is an update and stop
// handling everything.
if (UpdateDetected != null)
if (UpdateDetected != null || UpdateDetectedAsync != null)
{
UpdateDetected(this, ev); // event's next action can change, here
if (UpdateDetectedAsync != null)
{
await UpdateDetectedAsync(this, ev); // event's next action can change, here
}
else if (UpdateDetected != null)
{
UpdateDetected(this, ev); // event's next action can change, here
}
switch (ev.NextAction)
{
case NextUpdateAction.PerformUpdateUnattended:
Expand Down Expand Up @@ -1977,12 +1984,19 @@ private async void OnWorkerDoWork()
updates[0],
updates
);
if (UpdateDetected != null)
if (UpdateDetected != null || UpdateDetectedAsync != null)
{
var re = new AutoResetEvent(false);
_syncContextForWorkerLoop.Post((state) =>
_syncContextForWorkerLoop.Post(async (state) =>
{
UpdateDetected?.Invoke(this, ev);
if (UpdateDetectedAsync != null)
{
await UpdateDetectedAsync(this, ev);
}
else if (UpdateDetected != null)
{
UpdateDetected.Invoke(this, ev);
}
re.Set();
}, null);
re.WaitOne(); // wait for UpdateDetected to finish even though we called back to UI thread
Expand Down
16 changes: 15 additions & 1 deletion src/NetSparkle/SparkleUpdaterEvents.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using NetSparkleUpdater.Events;

namespace NetSparkleUpdater
{
Expand All @@ -21,10 +22,23 @@ public partial class SparkleUpdater : IDisposable
public event UpdateCheckStarted? UpdateCheckStarted;
/// <summary>
/// This event can be used to override the standard user interface
/// process when an update is detected
/// process when an update is detected. To modify the next action,
/// change the value of the <seealso cref="UpdateDetectedEventArgs.NextAction"/>
/// property.
/// If both this and UpdateDetectedAsync are implemented, UpdateDetectedAsync is
/// used, and UpdateDetected is not called.
/// </summary>
public event UpdateDetected? UpdateDetected;
/// <summary>
/// This event can be used to override the standard user interface
/// process when an update is detected. To modify the next action,
/// change the value of the <seealso cref="UpdateDetectedEventArgs.NextAction"/>
/// property.
/// If both this and UpdateDetected are implemented, UpdateDetectedAsync is
/// used, and UpdateDetected is not called.
/// </summary>
public event UpdateDetectedAsync? UpdateDetectedAsync;
/// <summary>
/// Called when update check is all done. <see cref="UpdateDetected"/> may have been
/// called between the start and end of the update check.
/// </summary>
Expand Down

0 comments on commit 5558735

Please sign in to comment.