Skip to content

Logout no longer wipes data#1239

Open
dfsm wants to merge 3 commits intomainfrom
export-settings
Open

Logout no longer wipes data#1239
dfsm wants to merge 3 commits intomainfrom
export-settings

Conversation

@dfsm
Copy link
Copy Markdown
Contributor

@dfsm dfsm commented Apr 17, 2026

  • Logging out now just logs out. Settings and Cache remain. This is largely to avoid users being logged out when their cookie expires, losing all their settings.
  • New options in Settings menu: Clear Cache and Reset Settings.
    (This branch originally had option to export settings, but not really needed so removed)
  • Combined cache total size now shown in Settings before performing clear
  • Clear Cache now clears more caches and core data storage.
  • Reset Settings keeps cache but resets preferences
  • No more crash on logging in after logging out
  • Crash avoided during Clear Cache scenario also (where the reset data store was moved to)

dfsm added 3 commits April 5, 2026 13:45
Logout no longer wipes user preferences (themes, font scale, toggles, etc.) - only session/auth keys (including imgur) are cleared. Settings now survive cookie expiration and manual logout.

New Data Management section in Settings:
- Clear Cache: now clears all caches (URLCache, Nuke disk/memory, WKWebView data, external stylesheet) and shows accurate size before and after clearing
- Reset All Settings: restores preferences to defaults while staying logged in
- Export Settings: saves preferences as a dated JSON file via share sheet
- Import Settings: restores preferences from a previously exported JSON file, with warnings when importing from an older app build
- Preserve UserDefaults preferences on logout; only session/auth keys (userID, username, canSendPrivateMessages, imgur upload mode, last pasteboard URL) are cleared.
- Stop wiping the Core Data store on logout. Cached forums, threads, and posts survive. Fixes a long-standing crash where logging in again after logout hit "persistent store is not reachable" — ForumsClient's background MOC retained objects tied to the deleted store and the next save-notification merge blew up.
- Drop the "Logging out erases..." footer; logout is just logout now.

Clear Cache (Settings):
- New Data Management section with Clear Cache and Reset All Settings.
- Clear Cache now wipes URLCache, Nuke disk/memory, WKWebView data, the external stylesheet cache, AND the Core Data store, and reports accurate size before/after.
- Store-size estimate includes the Core Data store directory.
- Avoids the stale-MOC crash by cycling ForumsClient.shared.managedObjectContext around the store reset.
- DataStoreWillReset / DataStoreDidReset promoted to public Notification.Name extensions on AwfulCore. All FRC owners (ThreadListDataSource, ForumListDataSource, MessageListDataSource, ForumSpecificThemesViewController) now observe .dataStoreDidReset and re-fetch so their caches stop pointing at dangling objectIDs.
- SettingsViewController rebuilds its currentUser header on reset so re-render doesn't fault the invalidated User.
- RootViewControllerStack observes reset too: dismisses any modal (compose sheet, etc.) and pops every tab's nav stack plus the split view's detail nav back to root, so pushed detail VCs (PostsPageViewController, PrivateMessageViewController, profile, etc.) can't crash trying to render stale managed objects.

Reset All Settings:
- Restores preferences to defaults while staying logged in. Keys are removed individually (not via setPersistentDomain) so KVO fires and @AppStorage observers update immediately.

Also:
- Fix: AppDelegate.calculateCacheSize() offloaded to a detached utility Task so file enumeration doesn't stall the main thread when Settings appears; directorySize(at:) marked nonisolated.
- Expose DataStore.storeDirectoryURL publicly so AppDelegate can size it.
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