0

Is there a way to force macOS File Provider Extension to re-enumerate items for given parent container?

I am aware that we can signalEnumerator(for: .workingSet) but that would just invoke the enumerateChanges callback in FileProviderEnumerator. What I'm looking for is something like: Internal structure changed so much, that it would be best to re-enumerate the content and rebuild the new model with it. And that should result in invoking the enumerateItems callback in the FileProviderEnumerator.

Are there any options to achieving just that?

mixtly87
  • 1,675
  • 15
  • 32

2 Answers2

1

I found a solution to this by calling the NSFileProviderManager reimportItems function:

manager.reimportItems(below: obj, completionHandler: {_ in })
James Risner
  • 5,451
  • 11
  • 25
  • 47
  • Could you please share how you have handled it in enumerateItems() after triggering, in my case it is actually creating duplicate folder. Not sure how to handle this scenario – Sri Jun 12 '23 at 09:12
  • @mixtly87 if possible could you share a implemetation logic to handle this on enumrator side – Sri Jun 12 '23 at 09:31
  • @mixtly87 currently, I added a refresh button using info list and when it is clicked I am able to trigger a function for example. manager.signalEnumerator(for: itemIdentifiers[0]) I am calling this in the function, however it's only working for workingset and not the other identifiers. My usecase is if I delete a item or add an item on remote server, I want user to be able to click refresh and during that time I want to refresh that specific directory which he clicked refresh on. I am able click refresh and get identifier, however not able to trigger enumerate with signal – Sri Jun 15 '23 at 04:42
  • @mixtly87 here is a post exactly matching my question in detail, your help is much appreciated: https://stackoverflow.com/questions/76479214/how-to-refresh-specific-directory-in-macos-file-provider-extension – Sri Jun 15 '23 at 04:52
0

Maybe deregistering and registering FileProvider domain could help.

To remove all domains and add domain again:

let identifier = NSFileProviderDomainIdentifier(rawValue: "Your-Domain-Identifier")
let domain = NSFileProviderDomain(identifier: identifier, displayName: "Your-Provider-Domain")

NSFileProviderManager.removeAllDomains { error in
    if error != nil {
        print("Error removing all domains: \(error)")
    } else {
        NSFileProviderManager.add(domain) { error in
            print("Error adding domain: \(error)")
        }
    }
}

This should result in re-fetching (enumerating) root container again and all its children as user browses content in Finder.

mixtly87
  • 1,675
  • 15
  • 32