Skip to content

Commit

Permalink
Fix refreshing of subscription preference pane when switching between…
Browse files Browse the repository at this point in the history
… panes
  • Loading branch information
miasma13 committed Feb 21, 2024
1 parent 15af998 commit e1b3e6f
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,18 @@ public final class PreferencesSubscriptionModel: ObservableObject {
func fetchAndUpdateSubscriptionDetails() {
guard fetchSubscriptionDetailsTask == nil else { return }

fetchSubscriptionDetailsTask = Task {
guard let token = accountManager.accessToken else { return }
fetchSubscriptionDetailsTask = Task { [weak self] in
defer {
self?.fetchSubscriptionDetailsTask = nil
}

guard let token = self?.accountManager.accessToken else { return }

if let cachedDate = SubscriptionService.cachedSubscriptionDetailsResponse?.expiresOrRenewsAt {
updateDescription(for: cachedDate)
self?.updateDescription(for: cachedDate)

if cachedDate.timeIntervalSinceNow > 0 {
self.cachedEntitlements = []
if cachedDate.timeIntervalSinceNow < 0 {
self?.cachedEntitlements = []
}
}

Expand All @@ -190,13 +194,13 @@ public final class PreferencesSubscriptionModel: ObservableObject {
return
}

updateDescription(for: response.expiresOrRenewsAt)
self?.updateDescription(for: response.expiresOrRenewsAt)

subscriptionPlatform = response.platform
self?.subscriptionPlatform = response.platform
}

if case let .success(entitlements) = await AccountManager().fetchEntitlements() {
self.cachedEntitlements = entitlements
self?.cachedEntitlements = entitlements
}
}
}
Expand Down

0 comments on commit e1b3e6f

Please sign in to comment.