Skip to content

Commit ad2711e

Browse files
authored
Merge pull request #601 from cch1rag/issue-323-notification-fix
Fix newly outdated package notifications
2 parents 9064c39 + 1524b2b commit ad2711e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Cork/CorkApp.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,14 @@ struct CorkApp: App
665665

666666
// MARK: - Background updating
667667

668+
nonisolated static func backgroundNewlyOutdatedPackages(
669+
refreshed refreshedOutdatedPackages: Set<OutdatedPackage>,
670+
previous previousOutdatedPackages: Set<OutdatedPackage>
671+
) -> Set<OutdatedPackage>
672+
{
673+
refreshedOutdatedPackages.subtracting(previousOutdatedPackages)
674+
}
675+
668676
func handleBackgroundUpdating()
669677
{
670678
// Start the background update scheduler when the app starts
@@ -696,14 +704,19 @@ struct CorkApp: App
696704
newOutdatedPackages = .init()
697705
}
698706

699-
if await newOutdatedPackages.count > outdatedPackagesTracker.outdatedPackages.count
707+
let previousOutdatedPackages: Set<OutdatedPackage> = await outdatedPackagesTracker.outdatedPackages
708+
709+
if await newOutdatedPackages.count > previousOutdatedPackages.count
700710
{
701711
AppConstants.shared.logger.log("New updates found")
702712

703713
/// Set this to `true` so the normal notification doesn't get sent
704714
await setWhetherToSendStandardUpdatesAvailableNotification(to: false)
705715

706-
let differentPackages: Set<OutdatedPackage> = await newOutdatedPackages.subtracting(outdatedPackagesTracker.allDisplayableOutdatedPackages)
716+
let differentPackages: Set<OutdatedPackage> = Self.backgroundNewlyOutdatedPackages(
717+
refreshed: newOutdatedPackages,
718+
previous: previousOutdatedPackages
719+
)
707720
AppConstants.shared.logger.debug("Changed packages: \(differentPackages, privacy: .auto)")
708721

709722
sendNotification(title: String(localized: "notification.new-outdated-packages-found.title"), subtitle: differentPackages.map{$0.package.name(withPrecision: .precise)}.formatted(.list(type: .and)))
@@ -774,4 +787,3 @@ struct CorkApp: App
774787
}
775788
}
776789
}
777-

0 commit comments

Comments
 (0)