How to make a Finder Sync Extension change badges in response to outside events
Asked Answered
S

0

8

I have a Finder Sync Extension that will display a badge on a file based on the state of a local database. It's straightforward enough to query this database in the requestBadgeIdentifierForURL function, but what if I want the badge to change for a Finder item that's already visible if the state of that database has changed (which can be via a notification through any variety of mechanisms). The documentation (https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/Finder.html) would seem to imply this is possible with this statement:

You might also want to track these URLs, in order to update their badges whenever their state changes.

The only ways I can imagine this would be possible (and most seem wrong) would be:

  • call setBadgeIdentifier:forURL from another application that is aware of the change

  • Launch a thread in the init function of my extension which listens for notifications and calls setBadgeIdentifier:forURL when it receives them

  • Call some OS API that prompts Finder that the extension should be triggered via requestBadgeIdentifierForURL.

Only the last one seems feasible, and could be managed via the extension informing the outside resource what needs refreshing via the beginObservingDirectoryAtURL/endObservingDirectoryAtURL callbacks, but i don't know what mechanism could do this.

Safire answered 7/7, 2017 at 1:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.