fix: Make autoupdates work again (#1895)

* fix: Make autoupdates work again

- Always opportunistically schedule a future (fast) auto-update after a check/attempt has been made.
- Track the update notification dismiss to extend this time out.

This change relies on the fact that a second auto-update won't run so long as a notification is open.

* fix: Start update check time from notification dismiss
This commit is contained in:
KazWolfe 2024-07-05 01:29:08 -07:00 committed by GitHub
parent 9d9326fd6d
commit c5e90e4df2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -75,7 +75,6 @@ internal class AutoUpdateManager : IServiceType
private bool hasStartedInitialUpdateThisSession; private bool hasStartedInitialUpdateThisSession;
private IActiveNotification? updateNotification; private IActiveNotification? updateNotification;
private bool notificationHasStartedUpdate; // Used to track if the user has started an update from the notification.
private Task? autoUpdateTask; private Task? autoUpdateTask;
@ -195,6 +194,8 @@ internal class AutoUpdateManager : IServiceType
if (currentlyUpdatablePlugins.Count == 0) if (currentlyUpdatablePlugins.Count == 0)
{ {
this.IsAutoUpdateComplete = true; this.IsAutoUpdateComplete = true;
this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecks;
return; return;
} }
@ -209,7 +210,6 @@ internal class AutoUpdateManager : IServiceType
} }
Log.Verbose("Running initial auto-update, updating {Num} plugins", currentlyUpdatablePlugins.Count); Log.Verbose("Running initial auto-update, updating {Num} plugins", currentlyUpdatablePlugins.Count);
this.notificationHasStartedUpdate = true;
this.KickOffAutoUpdates(currentlyUpdatablePlugins); this.KickOffAutoUpdates(currentlyUpdatablePlugins);
return; return;
} }
@ -221,8 +221,6 @@ internal class AutoUpdateManager : IServiceType
DateTime.Now > this.nextUpdateCheckTime && DateTime.Now > this.nextUpdateCheckTime &&
this.updateNotification == null) this.updateNotification == null)
{ {
this.nextUpdateCheckTime = null;
Log.Verbose("Starting periodic update check"); Log.Verbose("Starting periodic update check");
this.pluginManager.ReloadPluginMastersAsync() this.pluginManager.ReloadPluginMastersAsync()
.ContinueWith( .ContinueWith(
@ -245,27 +243,16 @@ internal class AutoUpdateManager : IServiceType
if (this.updateNotification != null) if (this.updateNotification != null)
throw new InvalidOperationException("Already showing a notification"); throw new InvalidOperationException("Already showing a notification");
if (this.notificationHasStartedUpdate)
throw new InvalidOperationException("Lost track of notification state");
this.updateNotification = this.notificationManager.AddNotification(notification); this.updateNotification = this.notificationManager.AddNotification(notification);
this.updateNotification.Dismiss += _ => this.updateNotification.Dismiss += _ =>
{ {
this.updateNotification = null; this.updateNotification = null;
// If the user just clicked off the notification, we don't want to bother them again for quite a while. // Schedule the next update opportunistically for when this closes.
if (this.notificationHasStartedUpdate) this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecks;
{
this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecks;
Log.Verbose("User started update, next check at {Time}", this.nextUpdateCheckTime);
}
else
{
this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecksIfDismissed;
Log.Verbose("User dismissed update notification, next check at {Time}", this.nextUpdateCheckTime);
}
}; };
return this.updateNotification!; return this.updateNotification!;
} }
@ -360,8 +347,6 @@ internal class AutoUpdateManager : IServiceType
if (updatablePlugins.Count == 0) if (updatablePlugins.Count == 0)
return; return;
this.notificationHasStartedUpdate = false;
var notification = this.GetBaseNotification(new Notification var notification = this.GetBaseNotification(new Notification
{ {
Title = Locs.NotificationTitleUpdatesAvailable, Title = Locs.NotificationTitleUpdatesAvailable,
@ -381,7 +366,6 @@ internal class AutoUpdateManager : IServiceType
{ {
notification.DrawActions -= DrawNotificationContent; notification.DrawActions -= DrawNotificationContent;
this.KickOffAutoUpdates(updatablePlugins, notification); this.KickOffAutoUpdates(updatablePlugins, notification);
this.notificationHasStartedUpdate = true;
} }
ImGui.SameLine(); ImGui.SameLine();
@ -389,6 +373,16 @@ internal class AutoUpdateManager : IServiceType
} }
notification.DrawActions += DrawNotificationContent; notification.DrawActions += DrawNotificationContent;
// If the user dismisses the notification, we don't want to spam them with notifications. Schedule the next
// auto update further out. Since this is registered after the initial OnDismiss, this should take precedence.
notification.Dismiss += args =>
{
if (args.Reason != NotificationDismissReason.Manual) return;
this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecksIfDismissed;
Log.Verbose("User dismissed update notification, next check at {Time}", this.nextUpdateCheckTime);
};
} }
private List<AvailablePluginUpdate> GetAvailablePluginUpdates(UpdateListingRestriction restriction) private List<AvailablePluginUpdate> GetAvailablePluginUpdates(UpdateListingRestriction restriction)