Skip to content

Fix critical app extension link handling bugs#73

Open
mattrighetti wants to merge 2 commits into
masterfrom
fix/extension-link-handling
Open

Fix critical app extension link handling bugs#73
mattrighetti wants to merge 2 commits into
masterfrom
fix/extension-link-handling

Conversation

@mattrighetti
Copy link
Copy Markdown
Owner

Summary

Fixes multiple critical bugs in the app extension link saving flow that were causing links to be silently lost or dropped after first use.

Issues Fixed

  1. Stale cache causing permanent link lossexternalCache lazy var was frozen in memory after first load, causing subsequent links saved via extension to be silently dropped when the app processed them
  2. Cold launch miss — Links saved while the app was closed would not be processed until the app went to background and returned to foreground
  3. Plist encoding mismatchpersistCache was encoding as dictionary but getCache/add were decoding as array, risking data corruption
  4. Action extension crashes — Force unwraps on missing extension inputs would crash the action
  5. URL path construction bug — Incorrect method for appending directory components

Key Changes

  • SceneDelegate.processExternalLinks() now reads fresh from disk on each call instead of using the stale lazy externalCache
  • Added direct call to processExternalLinks() during scene initialization to handle cold launches
  • Simplified cache clearing logic: explicitly calls dropCache() + persistCache() instead of relying on notification matching
  • AddToUlryActionViewController now gracefully handles missing extension inputs
  • Fixed +URL.swift to use correct path component method

- Fix stale externalCache causing links to be lost after first extension use
  - processExternalLinks now reads fresh from disk via getCache() on each call
  - No longer relies on unreliable notification-based cache clearing
  - Explicitly calls dropCache() + persistCache() after batch insert

- Process external links on cold launch
  - Added direct call to processExternalLinks() in scene(_:willConnectTo:)
  - Previously only processed on background-to-foreground transitions
  - Links saved while app was closed would be lost until next background/foreground cycle

- Fix persistCache/getCache encoding mismatch
  - persistCache now encodes Array(externalCache.values) instead of dictionary
  - Consistent with how getCache() and add() decode the file as an array

- Prevent crashes in AddToUlryActionViewController
  - Replaced force unwraps on extensionContext and attachments with guard let
  - Gracefully completes request if extension input is missing

- Fix appendingPathExtension → appendingPathComponent in +URL.swift
  - Correct method for appending path components (subdirectories)
  - Previously would have added .folder to filenames instead of creating directories
…sion queue

- ExtensionsAddLinkRequestsManager now uses UserDefaults(suiteName:) instead
  of a manually coordinated plist file
- Removed: externalCache lazy var, getCache, dropCache, persistCache,
  NSFileCoordinator, PropertyListEncoder/Decoder, NSObject inheritance,
  and the notification-based remove mechanism
- Added: pendingLinks computed property (reads fresh each time), clearAll()
- SceneDelegate.processExternalLinks updated to use new API
- Deleted Shared/Utils/+URL.swift — storeURL helper is now unused
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