Skip to content

Sync instances to App Groups container for Share Extension#628

Open
tillkruss wants to merge 1 commit intofeature/share-extfrom
claude/cloudStorage-app-group-kjqN9
Open

Sync instances to App Groups container for Share Extension#628
tillkruss wants to merge 1 commit intofeature/share-extfrom
claude/cloudStorage-app-group-kjqN9

Conversation

@tillkruss
Copy link
Copy Markdown
Collaborator

Summary

Enable the Share Extension to access the configured instances by syncing them to a shared App Groups container. This allows the Share Extension to read instance data from the main app without requiring direct access to the main app's UserDefaults.

Key Changes

  • AppSettings: Added initialization observer to listen for iCloud KeyValue Store changes and sync instances to App Groups when they change externally
  • AppSettings: Added syncInstancesToAppGroup() method that encodes instances and writes them to the shared App Groups UserDefaults
  • AppSettings: Call syncInstancesToAppGroup() whenever instances are added or deleted to keep the shared container in sync
  • Entitlements: Added App Groups capability (group.com.ruddarr) to both main app and Share Extension targets
  • Build Configuration: Added CODE_SIGN_ENTITLEMENTS setting to ShareExtension build targets
  • View: Call syncInstancesToAppGroup() during app initialization to ensure Share Extension has access to instances on first launch

Implementation Details

  • Uses UserDefaults(suiteName:) with the group.com.ruddarr suite name to access the shared container
  • Instances are encoded as JSON data before being stored in the shared UserDefaults
  • The iCloud sync observer ensures instances are synced whenever they change on other devices
  • Gracefully handles encoding failures with guard statements

https://claude.ai/code/session_01VsmqhzkysTDdfwKPpdt7Fb

@cloudstorage wraps NSUbiquitousKeyValueStore and cannot be pointed at
an app group container. Instead, mirror `instances` into the shared
UserDefaults (group.com.ruddarr) so the Share Extension can read them:

- Add com.apple.security.application-groups entitlement to the main app
- Add ShareExtension/ShareExtension.entitlements with the same entitlement
  and wire it into the Xcode project (CODE_SIGN_ENTITLEMENTS for both configs)
- Add AppSettings.syncInstancesToAppGroup() and call it from saveInstance(),
  deleteInstance(), and on app launch (WithAppStateModifier)
- Observe NSUbiquitousKeyValueStore.didChangeExternallyNotification to also
  propagate iCloud syncs from other devices into the shared container

Closes the TODO in ShareExtension/README.md.

https://claude.ai/code/session_01VsmqhzkysTDdfwKPpdt7Fb
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.

2 participants