Skip to content

fix: restore Nextcloud favorites when Apple Files reopens - #4506

Closed
zxxwyt wants to merge 1 commit into
nextcloud:masterfrom
zxxwyt:nc-ios/4410-files-favorites
Closed

zxxwyt wants to merge 1 commit into
nextcloud:masterfrom
zxxwyt:nc-ios/4410-files-favorites

Conversation

@zxxwyt

@zxxwyt zxxwyt commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Closes #4410

Nextcloud folders could disappear from Favorites after Apple Files restarted. Files can request its working set before anyone opens a folder. At that point the provider could lack an account session, and the favorite ranks it held in memory were lost on restart.

The provider now opens the session for the requested domain and reads its favorite folders from Realm. It persists the order Files assigns per account and includes server favorites that Files has yet to rank. When the provider restarts, it expires the previous working-set anchor so Files can reload the list.

Verification

I also tested Favorites in Apple Files against a live Nextcloud instance and confirmed that the favorites remained available after reopening Files.

  • Apple Files. On an iPhone 17 simulator (iOS 26.0.1) connected to Nextcloud Server 32.0.15, Codex favorited First/Nested and Second and dragged Nested to the top. After terminating and relaunching Files, both folders opened from Favorites in the saved order. After removing Second and relaunching again, only Nested remained. WebDAV confirmed favorite values of 1 and 0 respectively.
  • Regression tests. Codex ran FileProviderFavoriteRanksTests and FileProviderWorkingSetChangesTests on an iPad Pro 13-inch (M5) simulator with iPadOS 26.0.1 and Xcode 27.2. All five tests passed with zero skips.

On a further relaunch, Files opened in On My iPhone. Before browsing the Nextcloud location, Codex returned to Browse and opened the existing Nested favorite directly. The removed Second entry was absent.

The local build resolved GoogleAppMeasurement 13.2.0 and GoogleAdsOnDeviceConversion 3.8.0 to satisfy Firebase 13.2.0.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (Codex:gpt-6.2-astra).

Codex helped implement the working-set and favorite-rank changes, wrote regression tests, ran the checks above and drafted this description.

Files can request its working set before browsing a folder. Establish the domain session on that path, persist the order assigned by Files, and let an expired working-set anchor reload favorites from Realm after the provider restarts.

Assisted-by: Codex:gpt-6.2-astra
Signed-off-by: zouxianxian <187847046+zxxwyt@users.noreply.github.com>
@marinofaggiana

Copy link
Copy Markdown
Member

Thanks for looking into #4410 and for the thorough testing. I'm closing this PR because it changes much more than the bug needs. Several of those changes affect sensitive parts of the File Provider extension:

  • item(for:) now calls prepareSession, which runs the version check, several keychain reads (passcode, requestPasscodeAtStart, disableFilesApp) and getAllTableAccount() on every call. That is a hot path: urlForItem, providePlaceholder and reparentItem all go through it.
  • The working set now runs the authentication checks. It used to skip them on purpose. With a passcode enabled, Favorites and Recents in Files would now show an authentication error.
  • setupAccount is rewritten (signature, logger setup, side effects on session and domain), and the auth flow is restructured. None of this is needed to fix the bug.

The actual fix is much smaller. We'd welcome a new PR limited to:

  1. Open the account session for the working set by calling setupAccount(domain:) when .workingSet is requested, without adding the authentication checks. Today enumerateItems returns early because session is nil.
  2. Persist the favorite order across restarts. Your FileProviderFavoriteRanks is fine as is. Please also remove the stored ranks when an account is removed.
  3. Use a new working-set sync anchor on each extension launch, so Files re-enumerates after a restart. The core of FileProviderWorkingSetChanges and its tests can be reused for this.

Please leave item(for:), the authentication flow and setupAccount as they are. If you think they need refactoring, open a separate issue so we can discuss it first.

Thanks again, and looking forward to the smaller PR!

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.

Nextcloud folders disappear from Apple Files Favorites after restarting the app

2 participants