Commit 12f61d2f authored by Kourser's avatar Kourser
Browse files

fix: the launch catch-up waits for the library

At a cold launch the scene turns active before AppServices.start() has
read the library. returnedToForeground() then ran the catch-up over an
empty podcasts list: no feed was refreshed, and its timestamp turned the
launch's own catch-up away for half an hour. The sync it runs first
compares the server with that same library, and could have taken every
subscription for removed.

returnedToForeground() now waits for start(). On the simulator, five
cold launches with the timestamp cleared fetched the feed none of the
times before, every time after.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent adcfeaa1
Loading
Loading
Loading
Loading
+5
Changes for CHANGELOG.md: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -39,6 +39,11 @@ adopte le [versionnage sémantique](https://semver.org/lang/fr/).
- Les réglages d'un podcast pouvaient s'ouvrir avec les valeurs par défaut,
  puis les enregistrer sur OK, si leur lecture était interrompue à
  l'ouverture de la fenêtre.
- Au lancement, l'actualisation automatique des abonnements ne rafraîchissait
  souvent rien, et n'était plus retentée pendant une demi-heure : elle partait
  avant le chargement de la bibliothèque. Elle l'attend désormais, comme la
  synchronisation qui la précède, qui aurait pu sinon comparer le serveur à
  une bibliothèque vide.

## [1.5.0] - 2026-10-31

+20
Changes for Skingomz/AppModel.swift: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ final class AppModel {
    @ObservationIgnored private var progressExchangeFromStart = false
    @ObservationIgnored private var scheduledProgressSync: Task<Void, Never>?
    @ObservationIgnored private var lastForegroundProgressSync: Date?
    /// Set once `start()` has read the library. Until then `podcasts` is empty
    /// for want of reading, not because nothing is followed.
    @ObservationIgnored private var started = false
    @ObservationIgnored private var waitingForStart: [CheckedContinuation<Void, Never>] = []
    // iCloud sync (CloudSync.swift).
    @ObservationIgnored var cloudStore: CloudKeyValueStore?
    @ObservationIgnored let cloudState = CloudSyncState()
@@ -183,6 +187,15 @@ final class AppModel {
        await loadQueue()
        await downloads.loadPersisted()
        scheduleCloudSync(after: .zero)
        started = true
        for waiting in waitingForStart { waiting.resume() }
        waitingForStart = []
    }

    /// Returns once `start()` has read the library.
    private func untilStarted() async {
        guard !started else { return }
        await withCheckedContinuation { waitingForStart.append($0) }
    }

    /// Launch argument `-uiScreen <name>` used by the screenshot harness to open
@@ -1073,7 +1086,14 @@ final class AppModel {

    /// Back in the app: positions first — they are what the user is about to
    /// resume — then the slower catch-up of feeds and subscriptions.
    ///
    /// Not before the library is read. At a cold launch the scene turns active
    /// before `start()` is done: the catch-up then walked no subscription at
    /// all, and its timestamp turned away the launch's own for half an hour —
    /// while a sync comparing against that empty library would have taken
    /// every subscription for removed.
    func returnedToForeground(now: Date = .now) async {
        await untilStarted()
        if lastForegroundProgressSync.map({ now.timeIntervalSince($0) >= 60 }) ?? true {
            lastForegroundProgressSync = now
            if syncSettings.service == .iCloud {