Skip to content

Commit

Permalink
fix: Make autoupdates work again (#1895)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
KazWolfe authored Jul 5, 2024
1 parent 9d9326f commit c5e90e4
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions Dalamud/Plugin/Internal/AutoUpdate/AutoUpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ internal class AutoUpdateManager : IServiceType
private bool hasStartedInitialUpdateThisSession;

private IActiveNotification? updateNotification;
private bool notificationHasStartedUpdate; // Used to track if the user has started an update from the notification.

private Task? autoUpdateTask;

Expand Down Expand Up @@ -195,6 +194,8 @@ private void OnUpdate(IFramework framework)
if (currentlyUpdatablePlugins.Count == 0)
{
this.IsAutoUpdateComplete = true;
this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecks;

return;
}

Expand All @@ -209,7 +210,6 @@ private void OnUpdate(IFramework framework)
}

Log.Verbose("Running initial auto-update, updating {Num} plugins", currentlyUpdatablePlugins.Count);
this.notificationHasStartedUpdate = true;
this.KickOffAutoUpdates(currentlyUpdatablePlugins);
return;
}
Expand All @@ -221,8 +221,6 @@ private void OnUpdate(IFramework framework)
DateTime.Now > this.nextUpdateCheckTime &&
this.updateNotification == null)
{
this.nextUpdateCheckTime = null;

Log.Verbose("Starting periodic update check");
this.pluginManager.ReloadPluginMastersAsync()
.ContinueWith(
Expand All @@ -245,27 +243,16 @@ private IActiveNotification GetBaseNotification(Notification notification)
if (this.updateNotification != null)
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.Dismiss += _ =>
{
this.updateNotification = null;
// If the user just clicked off the notification, we don't want to bother them again for quite a while.
if (this.notificationHasStartedUpdate)
{
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);
}
// Schedule the next update opportunistically for when this closes.
this.nextUpdateCheckTime = DateTime.Now + TimeBetweenUpdateChecks;
};

return this.updateNotification!;
}

Expand Down Expand Up @@ -360,8 +347,6 @@ private void NotifyUpdatesAreAvailable(ICollection<AvailablePluginUpdate> updata
if (updatablePlugins.Count == 0)
return;

this.notificationHasStartedUpdate = false;

var notification = this.GetBaseNotification(new Notification
{
Title = Locs.NotificationTitleUpdatesAvailable,
Expand All @@ -381,14 +366,23 @@ void DrawNotificationContent(INotificationDrawArgs args)
{
notification.DrawActions -= DrawNotificationContent;
this.KickOffAutoUpdates(updatablePlugins, notification);
this.notificationHasStartedUpdate = true;
}

ImGui.SameLine();
DrawOpenInstallerNotificationButton(false, PluginInstallerOpenKind.UpdateablePlugins, notification);
}

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)
Expand Down

0 comments on commit c5e90e4

Please sign in to comment.