Skip to content

fix(settings): re-poll reminder permission on foreground return - #929

Merged
wei18 merged 2 commits into
mainfrom
fix/reminder-foreground-refresh
Jul 21, 2026
Merged

wei18 merged 2 commits into
mainfrom
fix/reminder-foreground-refresh

Conversation

@wei18

@wei18 wei18 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Found by a navigation-contract audit of all 22 screen contracts. The reminder row in Settings never refreshes after the user returns from the system Settings deep-link, so it keeps showing a stale denied state.

Why it happens

ReminderPermissionModel.openSettings() calls UIApplication.shared.open(openNotificationSettingsURLString), which backgrounds the app into Settings.app — this view never leaves the hierarchy. On return, SwiftUI does not re-fire .task (it only re-fires on identity change), so the existing .task { await model.onAppear() } — the only refresh path — never runs again. A grep across SettingsUI found zero scenePhase / willEnterForeground / didBecomeActive hooks.

The intent was already documented: ReminderPermissionModel.swift:37 says the status is "refreshed via refreshStatus() (call on foreground / before presenting the primer)". The foreground half was never wired.

Symptom: grant permission in system Settings → return to the app → the reminder row still reads as denied until the user leaves Settings and re-enters. No data loss; the UI simply lies.

Fix

Add a scenePhase re-poll alongside the existing .task, reusing model.onAppear() rather than duplicating the refresh call. This mirrors the pattern already used by BoardView, MinesweeperBoardView and BannerSlotView (guard newPhase == .active), and is naturally cross-platform — unlike a UIKit-only NotificationCenter observer. macOS has no openNotificationSettingsURLString (the denial explainer shows textual guidance instead), so macOS never had the bug, but the hook is harmless there.

Repeat calls are safe: refreshStatus() is a plain re-read, and the #817 one-shot migration inside onAppear() is guarded by getIsScheduled() == nil plus a post-await TOCTOU re-check. A new test pins this.

Verification

  • swift test --package-path Packages/SettingsKit — 51 tests / 9 suites pass (including 2 new).
  • swift test --package-path Packages/SudokuKit --no-parallel --filter Settings — 50 tests / 12 suites pass.
  • swift test --package-path Packages/MinesweeperKit --no-parallel — 370 tests / 63 suites pass.
  • swiftlint --strict on the changed files — 0 violations. No snapshot baselines changed.

New tests: one drives denied → authorized-in-system-Settings → foreground return and asserts the status is re-read; one asserts a repeated onAppear() neither re-runs the #817 migration nor clobbers a user's explicit disable().

Shared SettingsKit, so both apps get the fix — both suites verified.

🤖 Generated with Claude Code

…ings.app

`openSystemSettings()` backgrounds the app into Settings.app without the
Settings screen ever leaving the view hierarchy, so the reminder section's
`.task { await model.onAppear() }` never re-fired on return — the row stayed
on the stale `denied` status until the user left and re-entered Settings.

Add a `scenePhase == .active` `.onChange` hook that re-calls the existing
`model.onAppear()` refresh path (reused, not duplicated). `onAppear()`'s
#817 one-shot migration is already TOCTOU-guarded, so repeat calls are safe.

Co-Authored-By: Claude Fable 5 <[email protected]>
CR round 1: the comment claimed BoardView / MinesweeperBoardView as
precedent for this pattern, but their scenePhase handlers switch on
.background/.inactive to pause and flush — the opposite edge. Only
BannerSlotView (#341) is the same `guard newPhase == .active` re-poll.
Comment-only; no behavior change.

Co-Authored-By: Claude Fable 5 <[email protected]>
@wei18
wei18 enabled auto-merge (squash) July 21, 2026 09:32
@wei18
wei18 merged commit 96f6245 into main Jul 21, 2026
5 checks passed
@wei18
wei18 deleted the fix/reminder-foreground-refresh branch July 21, 2026 09:32
wei18 added a commit that referenced this pull request Jul 21, 2026
…nd re-poll (#932)

Closes the two contract gaps left open by the navigation audit:

- SUD-BOARD-LOAD-FAILED listed three LoadState cases; there are four.
  .completedRedirect (#842) is a race guard that renders Completion inline
  when the open-time precheck finds the SavedGame already completed, rather
  than building a playable GameViewModel. MS reaches the same outcome via a
  different structure (its tier-2 guard view), so the apps mirror
  behaviorally but not structurally — worth knowing before unifying them.

- REMINDER-DENIED said the user "returns manually" from the Settings.app
  deep-link, which was accurate only because no foreground hook existed.
  #929 added a scenePhase re-poll, so the row now re-reads permission state
  on every foreground return; noted along with why repeat calls are safe.

Co-authored-by: Claude Fable 5 <[email protected]>
wei18 added a commit that referenced this pull request Jul 23, 2026
…ives its status re-poll (#948)

* fix(settings): host reminder sheets at screen root so the primer survives its status re-poll

The daily-reminder primer sheet self-dismissed ~1s after presenting: both
it and the denied-explainer were `.sheet` modifiers on ReminderSettingsSection's
`Section`, a presentation host nested inside the Settings List. The tap-time
async permission-status write swaps that Section's `switch model.status` row
content mid-presentation; List row diffing duplicates the host, UIKit rejects
the second present ("already presenting") and tears the primer down.
Reproduced 4/4 on device + sim; distinct from #909's model-caching bug (intact).

Both sheets now attach at the SettingsScreen root — a stable host outside any
List row — still driven by the same ReminderSettingsModel via
SettingsScreenReminderConfig. Adds a locale-independent `reminders.primer.sheet`
anchor and an E2E regression guard (open primer, wait 3s past the old teardown
window, assert still present). scenePhase re-poll (#929) and detents preserved.

Closes #940

Co-Authored-By: Claude Fable 5 <[email protected]>

* docs(settings): reword #940 binding comment and primer-anchor inventory line

Round-1 review cosmetics: the comment overstated the AudioSettingsSection
precedent (that wraps a non-optional model); reworded to describe the actual
optional-nil behavior. Also detached the reminders.primer.sheet anchor from
the "icon tile" phrase in the element inventory.

Part of #940.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant