objc2_file_provider/generated/Extension.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 /// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderextension?language=objc)
12 #[unsafe(super(NSObject))]
13 #[derive(Debug, PartialEq, Eq, Hash)]
14 pub struct NSFileProviderExtension;
15);
16
17extern_conformance!(
18 unsafe impl NSObjectProtocol for NSFileProviderExtension {}
19);
20
21impl NSFileProviderExtension {
22 extern_methods!(
23 #[cfg(feature = "NSFileProviderItem")]
24 #[unsafe(method(itemForIdentifier:error:_))]
25 #[unsafe(method_family = none)]
26 pub unsafe fn itemForIdentifier_error(
27 &self,
28 identifier: &NSFileProviderItemIdentifier,
29 ) -> Result<Retained<NSFileProviderItem>, Retained<NSError>>;
30
31 #[cfg(feature = "NSFileProviderItem")]
32 /// Should return the URL corresponding to a specific identifier. Fail if it's not
33 /// a subpath of documentStorageURL.
34 ///
35 /// This is a static mapping; each identifier must always return a path
36 /// corresponding to the same file. By default, this returns the path relative to
37 /// the path returned by documentStorageURL.
38 #[unsafe(method(URLForItemWithPersistentIdentifier:))]
39 #[unsafe(method_family = none)]
40 pub unsafe fn URLForItemWithPersistentIdentifier(
41 &self,
42 identifier: &NSFileProviderItemIdentifier,
43 ) -> Option<Retained<NSURL>>;
44
45 #[cfg(feature = "NSFileProviderItem")]
46 #[unsafe(method(persistentIdentifierForItemAtURL:))]
47 #[unsafe(method_family = none)]
48 pub unsafe fn persistentIdentifierForItemAtURL(
49 &self,
50 url: &NSURL,
51 ) -> Option<Retained<NSFileProviderItemIdentifier>>;
52
53 #[cfg(feature = "block2")]
54 /// This method is called when a placeholder URL should be provided for the item at
55 /// the given URL.
56 ///
57 /// The implementation of this method should call +[NSFileProviderManager
58 /// writePlaceholderAtURL:withMetadata:error:] with the URL returned by
59 /// +[NSFileProviderManager placeholderURLForURL:], then call the completion
60 /// handler.
61 #[unsafe(method(providePlaceholderAtURL:completionHandler:))]
62 #[unsafe(method_family = none)]
63 pub unsafe fn providePlaceholderAtURL_completionHandler(
64 &self,
65 url: &NSURL,
66 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
67 );
68
69 #[cfg(feature = "block2")]
70 /// Should ensure that the actual file is in the position returned by
71 /// URLForItemWithPersistentIdentifier:, then call the completion handler.
72 #[unsafe(method(startProvidingItemAtURL:completionHandler:))]
73 #[unsafe(method_family = none)]
74 pub unsafe fn startProvidingItemAtURL_completionHandler(
75 &self,
76 url: &NSURL,
77 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
78 );
79
80 /// Called after the last claim to the file has been released. At this point, it is
81 /// safe for the file provider to remove the content file.
82 ///
83 /// Care should be taken that the corresponding placeholder file stays behind after
84 /// the content file has been deleted.
85 #[unsafe(method(stopProvidingItemAtURL:))]
86 #[unsafe(method_family = none)]
87 pub unsafe fn stopProvidingItemAtURL(&self, url: &NSURL);
88
89 /// Called at some point after the file has changed; the provider may then trigger
90 /// an upload.
91 #[unsafe(method(itemChangedAtURL:))]
92 #[unsafe(method_family = none)]
93 pub unsafe fn itemChangedAtURL(&self, url: &NSURL);
94 );
95}
96
97/// Methods declared on superclass `NSObject`.
98impl NSFileProviderExtension {
99 extern_methods!(
100 #[unsafe(method(init))]
101 #[unsafe(method_family = init)]
102 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
103
104 #[unsafe(method(new))]
105 #[unsafe(method_family = new)]
106 pub unsafe fn new() -> Retained<Self>;
107 );
108}
109
110/// Deprecated.
111impl NSFileProviderExtension {
112 extern_methods!(
113 /// Writes out a placeholder at the specified URL. The URL should be one returned
114 /// by placeholderURLForURL:; if URL resource values are requested, the system will
115 /// consult the placeholder before consulting your app extension.
116 ///
117 /// Metadata contains NSURLNameKey, NSURLFileSizeKey, NSURLIsPackageKey.
118 ///
119 /// # Safety
120 ///
121 /// `metadata` generic should be of the correct type.
122 #[deprecated = "Use the corresponding method on NSFileProviderManager instead"]
123 #[unsafe(method(writePlaceholderAtURL:withMetadata:error:_))]
124 #[unsafe(method_family = none)]
125 pub unsafe fn writePlaceholderAtURL_withMetadata_error(
126 placeholder_url: &NSURL,
127 metadata: &NSDictionary<NSURLResourceKey, AnyObject>,
128 ) -> Result<(), Retained<NSError>>;
129
130 /// Returns the designated placeholder URL for a given URL. This placeholder will
131 /// be consulted before falling back to your app extension to enhance
132 /// performance. To write out a placeholder, use the writePlaceHolderAtURL: method
133 /// above.
134 #[deprecated]
135 #[unsafe(method(placeholderURLForURL:))]
136 #[unsafe(method_family = none)]
137 pub unsafe fn placeholderURLForURL(url: &NSURL) -> Retained<NSURL>;
138
139 /// An identifier unique to this provider.
140 ///
141 /// When modifying the files stored in the directory returned by
142 /// documentStorageURL, you should pass this identifier to your file coordinator's
143 /// setPurposeIdentifier: method.
144 #[deprecated]
145 #[unsafe(method(providerIdentifier))]
146 #[unsafe(method_family = none)]
147 pub unsafe fn providerIdentifier(&self) -> Retained<NSString>;
148
149 /// The root URL for provided documents. This URL is derived by consulting the
150 /// NSExtensionFileProviderDocumentGroup property on your extension. The document
151 /// storage URL is the folder "File Provider Storage" in the corresponding
152 /// container.
153 #[deprecated]
154 #[unsafe(method(documentStorageURL))]
155 #[unsafe(method_family = none)]
156 pub unsafe fn documentStorageURL(&self) -> Retained<NSURL>;
157 );
158}
159
160/// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderdomainremovalmode?language=objc)
161// NS_ENUM
162#[repr(transparent)]
163#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
164pub struct NSFileProviderDomainRemovalMode(pub NSInteger);
165impl NSFileProviderDomainRemovalMode {
166 /// Don't keep any files that are current in the domain
167 #[doc(alias = "NSFileProviderDomainRemovalModeRemoveAll")]
168 pub const RemoveAll: Self = Self(0);
169 /// Delete the domain from the system but keeps the at least all the
170 /// dirty corresponding user data around.
171 #[doc(alias = "NSFileProviderDomainRemovalModePreserveDirtyUserData")]
172 pub const PreserveDirtyUserData: Self = Self(1);
173 /// Delete the domain from the system but keeps all the downloaded
174 /// corresponding user data around.
175 #[doc(alias = "NSFileProviderDomainRemovalModePreserveDownloadedUserData")]
176 pub const PreserveDownloadedUserData: Self = Self(2);
177}
178
179unsafe impl Encode for NSFileProviderDomainRemovalMode {
180 const ENCODING: Encoding = NSInteger::ENCODING;
181}
182
183unsafe impl RefEncode for NSFileProviderDomainRemovalMode {
184 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
185}
186
187extern_class!(
188 /// The file provider manager allows you to communicate with the file provider
189 /// framework from both the extension and related processes.
190 ///
191 /// NSFileProviderManager can be used from the following processes:
192 /// - the extension
193 /// - the main app containing the extension
194 /// - sibling extensions to the extension
195 /// - executables contained in the main app bundle (on macOS only)
196 ///
197 /// Executables contained in the main app bundle need to have a bundle identifier that is
198 /// prefixed by the bundle identifier of the main app (note that this is generally required
199 /// for extensions). They must also have access to the document group defined for the provider
200 /// (via its `NSExtensionFileProviderDocumentGroup` key).
201 ///
202 /// The file provider framework will invoke your file provider extension in response
203 /// to those calls if appropriate.
204 ///
205 /// The class also provides methods to manage provider domains. Each domain has a
206 /// corresponding manager.
207 ///
208 /// See also [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileprovidermanager?language=objc)
209 #[unsafe(super(NSObject))]
210 #[derive(Debug, PartialEq, Eq, Hash)]
211 pub struct NSFileProviderManager;
212);
213
214extern_conformance!(
215 unsafe impl NSObjectProtocol for NSFileProviderManager {}
216);
217
218impl NSFileProviderManager {
219 extern_methods!(
220 #[unsafe(method(init))]
221 #[unsafe(method_family = init)]
222 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
223
224 /// Return the manager responsible for the default domain.
225 #[unsafe(method(defaultManager))]
226 #[unsafe(method_family = none)]
227 pub unsafe fn defaultManager() -> Retained<NSFileProviderManager>;
228
229 #[cfg(feature = "NSFileProviderDomain")]
230 /// Return the manager for the specified domain.
231 #[unsafe(method(managerForDomain:))]
232 #[unsafe(method_family = none)]
233 pub unsafe fn managerForDomain(domain: &NSFileProviderDomain) -> Option<Retained<Self>>;
234
235 #[cfg(all(feature = "NSFileProviderItem", feature = "block2"))]
236 /// Call this method either in the app or in the extension to trigger an
237 /// enumeration, typically in response to a push.
238 ///
239 /// When using NSFileProviderExtension, the system will enumerate containers
240 /// while the user is viewing them in the UI. If there are changes to the container
241 /// while an enumerator is open, call this method with the identifier of that
242 /// container. This will trigger another call to
243 /// -[NSFileProviderEnumerator enumerateChangesForObserver:fromSyncAnchor:] on
244 /// that enumerator, and the UI will be refreshed, giving the user live updates on
245 /// the presented enumeration.
246 ///
247 /// If there are changes in the working set, call this method with
248 /// containerItemIdentifier set to NSFileProviderWorkingSetContainerItemIdentifier,
249 /// even if there is no live enumeration for the working set container.
250 ///
251 /// When using NSFileProviderReplicatedExtension, only call this
252 /// method with NSFileProviderWorkingSetContainerItemIdentifier. Other container
253 /// identifiers are ignored. The system will automatically propagate
254 /// working set changes to the UI, without explicitly signaling the
255 /// containers currently being viewed in the UI.
256 ///
257 /// In addition to using this method, your application/extension can register for
258 /// pushes using the PKPushTypeFileProvider push type. Pushes of the form
259 /// {
260 /// "container-identifier": "<identifier>",
261 /// "domain": "<domain identifier>"
262 /// }
263 /// with a topic of "<your application identifier>.pushkit.fileprovider" will be
264 /// translated into a call to signalEnumeratorForContainerItemIdentifier:completionHandler:.
265 #[unsafe(method(signalEnumeratorForContainerItemIdentifier:completionHandler:))]
266 #[unsafe(method_family = none)]
267 pub unsafe fn signalEnumeratorForContainerItemIdentifier_completionHandler(
268 &self,
269 container_item_identifier: &NSFileProviderItemIdentifier,
270 completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
271 );
272
273 #[cfg(all(feature = "NSFileProviderItem", feature = "block2"))]
274 /// Return the security scoped URL to the user visible location for an item identifier.
275 ///
276 /// The caller must use file coordination (see NSFileCoordinator) if it wishes to read the
277 /// content or list the children of the URL. The caller should not try to manipulate files
278 /// in the user visible location. All changes coming from the provider should go through
279 /// updates in the working set that will be applied to the user visible items by the
280 /// system.
281 ///
282 /// The location may differ from the logical parentURL/filename.
283 /// If an item on disk cannot be assigned the requested name (e.g. because the local
284 /// file system has different case collision rules from the provider), one of the items can be assigned
285 /// a different local name. In that case, the "com.apple.fileprovider.before-bounce#PX" extended
286 /// attribute will contain the filename before collision resolution.
287 /// This attribute is only set if the item has been assigned a different local name following
288 /// a collision. Such local names are not synced up to the provider; the purpose of the attribute is
289 /// to enable consistency checkers to detect this case.
290 ///
291 /// Before accessing the content of the returned URL, the caller must call `-[NSURL startAccessingSecurityScopedResource]
292 /// on the returned URL and call `-[NSURL stopAccessingSecurityScopedResource]` when done accessing the content.
293 ///
294 /// The returned URL grants read-write access to the user visible location for the corresponding item.
295 ///
296 /// On iOS, for replicated domains, the extension process will never be granted access to the user
297 /// visible location, this function will always fail with `NSFileReadNoPermissionError`.
298 #[unsafe(method(getUserVisibleURLForItemIdentifier:completionHandler:))]
299 #[unsafe(method_family = none)]
300 pub unsafe fn getUserVisibleURLForItemIdentifier_completionHandler(
301 &self,
302 item_identifier: &NSFileProviderItemIdentifier,
303 completion_handler: &block2::DynBlock<dyn Fn(*mut NSURL, *mut NSError)>,
304 );
305
306 #[cfg(all(
307 feature = "NSFileProviderDomain",
308 feature = "NSFileProviderItem",
309 feature = "block2"
310 ))]
311 /// Return the identifier and domain for a user visible URL.
312 ///
313 /// This method returns the identifier and domain of a user visible URL if
314 /// applicable. Calling this method on a file which doesn't reside in your
315 /// provider/domain, or which hasn't yet been assigned an identifier by
316 /// the provider will return the Cocoa error NSFileNoSuchFileError.
317 #[unsafe(method(getIdentifierForUserVisibleFileAtURL:completionHandler:))]
318 #[unsafe(method_family = none)]
319 pub unsafe fn getIdentifierForUserVisibleFileAtURL_completionHandler(
320 url: &NSURL,
321 completion_handler: &block2::DynBlock<
322 dyn Fn(
323 *mut NSFileProviderItemIdentifier,
324 *mut NSFileProviderDomainIdentifier,
325 *mut NSError,
326 ),
327 >,
328 );
329
330 #[cfg(all(feature = "NSFileProviderItem", feature = "block2"))]
331 /// Registers the given NSURLSessionTask to be responsible for the specified item.
332 /// A given item can only have one task registered at a time. The task must be
333 /// suspended at the time of calling.
334 /// The task's progress is displayed on the item when the task is executed.
335 #[unsafe(method(registerURLSessionTask:forItemWithIdentifier:completionHandler:))]
336 #[unsafe(method_family = none)]
337 pub unsafe fn registerURLSessionTask_forItemWithIdentifier_completionHandler(
338 &self,
339 task: &NSURLSessionTask,
340 identifier: &NSFileProviderItemIdentifier,
341 completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
342 );
343
344 /// The purpose identifier of your file provider extension. A coordination using a
345 /// file coordinator with this purpose identifier set will not trigger your file
346 /// provider extension. You can use this to e.g. perform speculative work on behalf
347 /// of the file provider from the main app.
348 #[unsafe(method(providerIdentifier))]
349 #[unsafe(method_family = none)]
350 pub unsafe fn providerIdentifier(&self) -> Retained<NSString>;
351
352 /// The root URL for provided documents. This URL is derived by consulting the
353 /// NSExtensionFileProviderDocumentGroup property on your extension. The document
354 /// storage URL is the folder "File Provider Storage" in the corresponding
355 /// container.
356 ///
357 /// If the NSExtensionFileProviderDocumentGroup property is not set, calling this
358 /// method will result in an error.
359 #[unsafe(method(documentStorageURL))]
360 #[unsafe(method_family = none)]
361 pub unsafe fn documentStorageURL(&self) -> Retained<NSURL>;
362
363 /// A temporary directory suitable to store files that will be exchanged with the system.
364 ///
365 /// The returned URL is guaranteed to be on the same volume as the user visible URL, making sure the system
366 /// can atomatically clone/move files from that location to the user visible URL. The provider can also use
367 /// that directory as a target for moves and clones of content URL passed to createItemBasedOnTemplate
368 /// or modifyItem.
369 ///
370 /// If the system cannot find a suitable directory, this calls will fail. This could happen e.g. if the domain
371 /// does not exist or is in instance of initialization.
372 ///
373 /// This call succeeds when called from the extension process with an instance of the extension for the domain
374 /// unless domain was disconnected by
375 /// `-[NSFileProviderExternalVolumeHandling shouldConnectExternalDomainWithCompletionHandler:]`.
376 /// It can also fail in the extension process if the domain (external) is being setup for the very first time
377 /// (meaning it never existed).
378 #[unsafe(method(temporaryDirectoryURLWithError:_))]
379 #[unsafe(method_family = none)]
380 pub unsafe fn temporaryDirectoryURLWithError(
381 &self,
382 ) -> Result<Retained<NSURL>, Retained<NSError>>;
383
384 #[cfg(feature = "NSFileProviderItem")]
385 /// Writes out a placeholder at the specified URL. The placeholder is used in place
386 /// of the actual file for operations that do not require the file's actual data to
387 /// be on disk:
388 /// - if attributes are requested by an application via the
389 /// getPromisedItemResourceValue: method on NSURL
390 /// - or via a coordination with the
391 /// NSFileCoordinatorReadingImmediatelyAvailableMetadataOnly flag set
392 /// - to verify whether an application has access to a file
393 ///
394 /// Your extension should provide placeholders by implementing the
395 /// providePlaceholderAtURL: method, but your application may choose to proactively
396 /// write out placeholders to facilitate access to files. This is especially useful
397 /// if your application wants to actively hand out a file URL, e.g. using
398 /// UIActivityViewController, in which case it should ensure that either the file
399 /// or a placeholder is present on disk first.
400 ///
401 /// The path of the placeholder is fixed and must be determined in advance by
402 /// calling the placeholderURLForURL: method.
403 #[unsafe(method(writePlaceholderAtURL:withMetadata:error:_))]
404 #[unsafe(method_family = none)]
405 pub unsafe fn writePlaceholderAtURL_withMetadata_error(
406 placeholder_url: &NSURL,
407 metadata: &NSFileProviderItem,
408 ) -> Result<(), Retained<NSError>>;
409
410 /// Returns the designated placeholder URL for a given file URL. Used in
411 /// conjunction with writePlaceholderAtURL.
412 #[unsafe(method(placeholderURLForURL:))]
413 #[unsafe(method_family = none)]
414 pub unsafe fn placeholderURLForURL(url: &NSURL) -> Retained<NSURL>;
415
416 #[cfg(all(feature = "NSFileProviderDomain", feature = "block2"))]
417 /// Register a domain in which items can be stored.
418 ///
419 /// If a domain with the same identifier already exists, `addDomain` will update the display name
420 /// and hidden state of the domain and succeed.
421 ///
422 /// When the domain is backed by a NSFileProviderReplicatedExtension, the system will create
423 /// a disk location where the domain will be replicated. If that location already exists on disk
424 /// this call will fail with the code NSFileWriteFileExistsError.
425 #[unsafe(method(addDomain:completionHandler:))]
426 #[unsafe(method_family = none)]
427 pub unsafe fn addDomain_completionHandler(
428 domain: &NSFileProviderDomain,
429 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
430 );
431
432 #[cfg(all(feature = "NSFileProviderDomain", feature = "block2"))]
433 /// Remove a domain.
434 #[unsafe(method(removeDomain:completionHandler:))]
435 #[unsafe(method_family = none)]
436 pub unsafe fn removeDomain_completionHandler(
437 domain: &NSFileProviderDomain,
438 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
439 );
440
441 #[cfg(all(feature = "NSFileProviderDomain", feature = "block2"))]
442 /// Remove a domain with options
443 #[unsafe(method(removeDomain:mode:completionHandler:))]
444 #[unsafe(method_family = none)]
445 pub unsafe fn removeDomain_mode_completionHandler(
446 domain: &NSFileProviderDomain,
447 mode: NSFileProviderDomainRemovalMode,
448 completion_handler: &block2::DynBlock<dyn Fn(*mut NSURL, *mut NSError)>,
449 );
450
451 #[cfg(all(feature = "NSFileProviderDomain", feature = "block2"))]
452 /// Get all registered domains.
453 #[unsafe(method(getDomainsWithCompletionHandler:))]
454 #[unsafe(method_family = none)]
455 pub unsafe fn getDomainsWithCompletionHandler(
456 completion_handler: &block2::DynBlock<
457 dyn Fn(NonNull<NSArray<NSFileProviderDomain>>, *mut NSError),
458 >,
459 );
460
461 #[cfg(feature = "block2")]
462 /// Remove all registered domains.
463 #[unsafe(method(removeAllDomainsWithCompletionHandler:))]
464 #[unsafe(method_family = none)]
465 pub unsafe fn removeAllDomainsWithCompletionHandler(
466 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
467 );
468
469 #[cfg(feature = "block2")]
470 /// Calling this method will cause the system to cancel throttling on every item which has been throttled due to the given error.
471 ///
472 /// This call supports the following errors:
473 /// - NSFileProviderErrorNotAuthenticated
474 /// - NSFileProviderErrorInsufficientQuota
475 /// - NSFileProviderErrorServerUnreachable
476 /// - NSFileProviderErrorCannotSynchronize
477 /// - NSFileProviderErrorExcludedFromSync
478 #[unsafe(method(signalErrorResolved:completionHandler:))]
479 #[unsafe(method_family = none)]
480 pub unsafe fn signalErrorResolved_completionHandler(
481 &self,
482 error: &NSError,
483 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
484 );
485
486 /// Returns the global progress for the specified kind of operations
487 ///
488 /// This progress tracks all the ongoing kind of operations (from disk to the provider).
489 /// Uploading operations are the operations from disk to the provider.
490 /// Downloading operations are the operations from the provider to the disk.
491 ///
492 /// The global progress exposes the two following data:
493 /// - Number of items with an ongoing matching kind operation along with the grand total;
494 /// - Number of bytes already transferred along with the total amount of bytes to transfer.
495 ///
496 /// `totalUnitCount` will only be reset when there are no operations left. If new operations of the matching
497 /// kind arrive while the global progress is already ongoing, they will just be summed to the existing global
498 /// progress.
499 ///
500 /// By default, when no matching kind operations are active, the progress has its values set to 1 and its state set
501 /// to finished.
502 ///
503 /// The progress will be updated on the main queue. It is to be retained by the caller and to be observed through
504 /// KVO.
505 ///
506 /// The two only supported values for kind are:
507 /// - NSProgressFileOperationKindUploading
508 /// - NSProgressFileOperationKindDownloading
509 ///
510 /// The returned progress will have its fileOperationKind property set.
511 #[unsafe(method(globalProgressForKind:))]
512 #[unsafe(method_family = none)]
513 pub unsafe fn globalProgressForKind(
514 &self,
515 kind: &NSProgressFileOperationKind,
516 ) -> Retained<NSProgress>;
517 );
518}
519
520/// Methods declared on superclass `NSObject`.
521impl NSFileProviderManager {
522 extern_methods!(
523 #[unsafe(method(new))]
524 #[unsafe(method_family = new)]
525 pub unsafe fn new() -> Retained<Self>;
526 );
527}
528
529extern "C" {
530 /// Posted when the materialized set has changed.
531 ///
532 /// Interested clients can then use the materialized set enumerator returned by -enumeratorForMaterializedItems to enumerate changes on the materialized set.
533 ///
534 /// Note, this notification starts to be posted only after `+[NSFileProviderManager getDomainsWithCompletionHandler:]` is called.
535 ///
536 /// See also [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileprovidermaterializedsetdidchange?language=objc)
537 pub static NSFileProviderMaterializedSetDidChange: &'static NSNotificationName;
538}
539
540/// MaterializedSet.
541impl NSFileProviderManager {
542 extern_methods!(
543 #[cfg(feature = "NSFileProviderEnumerating")]
544 /// Returns an enumerator for the set of materialized items.
545 ///
546 /// When calling -[NSFileProviderEnumerator enumerateItemsForObserver:startingAtPage:] on the returned
547 /// enumerator, pass the result of [NSData new] as the starting page. The sorting page constants
548 /// (NSFileProviderInitialPageSortedByName and NSFileProviderInitialPageSortedByDate) will not influence
549 /// the order of the items enumerated from the materialized set.
550 ///
551 /// This enumerator is unlike other enumerators because the roles of the system
552 /// and the app/extension are reversed:
553 /// - The system enumerates the working set after the extension calls
554 /// 'signalEnumeratorForContainerItemIdentifier';
555 /// - The app/extension enumerates the materialized set after the system calls
556 /// 'materializedItemsDidChangeWithCompletionHandler'.
557 #[unsafe(method(enumeratorForMaterializedItems))]
558 #[unsafe(method_family = none)]
559 pub unsafe fn enumeratorForMaterializedItems(
560 &self,
561 ) -> Retained<ProtocolObject<dyn NSFileProviderEnumerator>>;
562 );
563}
564
565extern "C" {
566 /// Posted when the pending set has changed.
567 ///
568 /// Interested clients can then use the pending set enumerator returned by -enumeratorForPendingItems to enumerate changes on the pending set.
569 ///
570 /// Note, this notification starts to be posted only after `+[NSFileProviderManager getDomainsWithCompletionHandler:]` is called.
571 ///
572 /// See also [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderpendingsetdidchange?language=objc)
573 pub static NSFileProviderPendingSetDidChange: &'static NSNotificationName;
574}
575
576extern_protocol!(
577 /// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileproviderpendingsetenumerator?language=objc)
578 #[cfg(feature = "NSFileProviderEnumerating")]
579 pub unsafe trait NSFileProviderPendingSetEnumerator: NSFileProviderEnumerator {
580 #[cfg(feature = "NSFileProviderDomain")]
581 /// The version of the domain when the pending set was last refreshed by the system.
582 ///
583 /// This property is updated when the enumeration methods are called on the pending set enumerator. The value
584 /// is initially nil.
585 #[unsafe(method(domainVersion))]
586 #[unsafe(method_family = none)]
587 unsafe fn domainVersion(&self) -> Option<Retained<NSFileProviderDomainVersion>>;
588
589 /// The amount of time in seconds at which the pending set is refreshed on modifications.
590 #[unsafe(method(refreshInterval))]
591 #[unsafe(method_family = none)]
592 unsafe fn refreshInterval(&self) -> NSTimeInterval;
593
594 /// This property is set to YES when the enumeration of the pending set was capped at or below its maximum size.
595 /// Under normal conditions, the count of items pending sync will get lower as sync progresses, and this variable
596 /// will eventually be set to NO when the pending set again includes all items pending sync.
597 #[unsafe(method(isMaximumSizeReached))]
598 #[unsafe(method_family = none)]
599 unsafe fn isMaximumSizeReached(&self) -> bool;
600 }
601);
602
603/// PendingSet.
604impl NSFileProviderManager {
605 extern_methods!(
606 #[cfg(feature = "NSFileProviderEnumerating")]
607 /// Returns an enumerator for the set of pending items.
608 ///
609 /// This enumerator behaves like the materialized set enumerator.
610 /// On later modifications in the set, the system will call
611 /// 'pendingItemsDidChangeWithCompletionHandler'.
612 #[unsafe(method(enumeratorForPendingItems))]
613 #[unsafe(method_family = none)]
614 pub unsafe fn enumeratorForPendingItems(
615 &self,
616 ) -> Retained<ProtocolObject<dyn NSFileProviderPendingSetEnumerator>>;
617 );
618}
619
620/// Import.
621impl NSFileProviderManager {
622 extern_methods!(
623 #[cfg(all(feature = "NSFileProviderDomain", feature = "block2"))]
624 /// Request the creation of a new domain that will take ownership of on-disk data that
625 /// were previously managed without a file provider.
626 ///
627 /// You can use this method in order to migrate from a software that managed a file hierarchy
628 /// on disk to a NSFileProviderExtension without having to redownload the data that was
629 /// already on disk.
630 ///
631 /// The URL is expected to point to a directory. That directory will be moved away, its
632 /// ownership being taken by the system. From this point, your extension's
633 /// createItemFromTemplate method will be called for every item found in the directory
634 /// with the special NSFileProviderCreateItemMayAlreadyExist option.
635 ///
636 /// In case a domain with the same name already exists in the file provider manager, the
637 /// call will fail with the code NSFileWriteFileExistsError. The URL will remain untouched.
638 /// In case the system does not allow the extension to request a migration, the call will
639 /// fail with NSFeatureUnsupportedError.
640 ///
641 /// In case of success, the URL will become invalid and the domain will be created. The
642 /// completion handler is called as soon as the domain is created. Your provider will
643 /// receive calls to createItemBasedOnTemplate afterward.
644 ///
645 /// When the import of the file hierarchy is finished, the system calls
646 /// -[NSFileProviderExtension signalDidFinishImportingItemsFromDiskWithCompletionHandler:].
647 /// In case -[NSFileProviderManager reimportItemsBelowItemWithIdentifier:completionHandler:]
648 /// is called before the end of the import, a single call to importDidFinishWithCompletionHandler
649 /// will be received for both the import and the scan.
650 #[unsafe(method(importDomain:fromDirectoryAtURL:completionHandler:))]
651 #[unsafe(method_family = none)]
652 pub unsafe fn importDomain_fromDirectoryAtURL_completionHandler(
653 domain: &NSFileProviderDomain,
654 url: &NSURL,
655 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
656 );
657
658 #[cfg(all(feature = "NSFileProviderItem", feature = "block2"))]
659 /// Notify the system that the itemIdentifiers known by the system are not valid anymore.
660 ///
661 /// This can be called by an extension in case it has lost track of its synchronisation state
662 /// and as a consequence is not able to guarantee the stability of the itemIdentifiers anymore.
663 /// In that case, the system will trigger a scan of any data that is cached on disk and call
664 /// createItemBasedOnTemplate with the special NSFileProviderCreateItemMayAlreadyExist
665 /// option so that the extension can specify the new itemIdentifier for those items. The provided
666 /// item identifier is inclusive, meaning the specified item will be re-import as well as any
667 /// children in case it is a container.
668 ///
669 /// In case the extension has lost its synchronisation state but is still able to guarantee the
670 /// stability of the itemIdentifiers, it should make sure that querying the working set
671 /// enumerator with an anchor that predates the synchronisation loss will cause a
672 /// NSFileProviderErrorSyncAnchorExpired error.
673 ///
674 /// In case the extension has lost its synchronisation state and is not interested in preserving
675 /// the data cached on disk, it can remove and re-add the affected domain.
676 ///
677 /// The completion handler is called as soon as the reimport is initiated and does not not reflect
678 /// the end of the import. When the import of the file hierarchy is finished, the system calls
679 /// -[NSFileProviderExtension importDidFinishWithCompletionHandler:].
680 ///
681 /// In some circumstances, in particular in case the requested item is the root item, calling
682 /// reimport will cause the system to stop the extension process. If the call is initiated
683 /// from the extension, the system does not guarantee that the completion handler will be called
684 /// before the extension is stopped. When called on the root item, reimport will cause the system
685 /// to rebuild its backing store for the domain. See `-[NSFileProviderDomain backingStoreIdentity]`.
686 ///
687 /// If this method succeeds, the system will reimport at least the requested sub-tree, but may
688 /// import more.
689 ///
690 /// If the requested item has no on-disk representation, the completion handler will be called with
691 /// a NSFileProviderErrorNoSuchItem error. The same error will be reported if the reimport request
692 /// happens quickly after a previous import / reimport and the corresponding item hasn't been
693 /// reimported yet.
694 #[unsafe(method(reimportItemsBelowItemWithIdentifier:completionHandler:))]
695 #[unsafe(method_family = none)]
696 pub unsafe fn reimportItemsBelowItemWithIdentifier_completionHandler(
697 &self,
698 item_identifier: &NSFileProviderItemIdentifier,
699 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
700 );
701
702 #[cfg(all(
703 feature = "NSFileProviderItem",
704 feature = "NSFileProviderModifyItemOptions",
705 feature = "block2"
706 ))]
707 /// Request that the system schedules a call to -[NSFileProviderReplicatedExtension modifyItem:] for the given item identifier.
708 /// The fields passed to modifyItem will contain at least the set requested via the `fields` parameter.
709 /// The completion handler is called when the system has persisted the request. There is no guarantee as to when the
710 /// modifyItem call will be scheduled.
711 /// The completion handler may be called with an error. If the provider passes the `.content` field when the item
712 /// is not downloaded, or when the item is a folder, then the system will return CocoaError(.ubiquitousFileUnavailable).
713 #[unsafe(method(requestModificationOfFields:forItemWithIdentifier:options:completionHandler:))]
714 #[unsafe(method_family = none)]
715 pub unsafe fn requestModificationOfFields_forItemWithIdentifier_options_completionHandler(
716 &self,
717 fields: NSFileProviderItemFields,
718 item_identifier: &NSFileProviderItemIdentifier,
719 options: NSFileProviderModifyItemOptions,
720 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
721 );
722 );
723}
724
725/// Eviction.
726impl NSFileProviderManager {
727 extern_methods!(
728 #[cfg(all(feature = "NSFileProviderItem", feature = "block2"))]
729 /// Request that the system remove an item from its cache.
730 ///
731 /// When called on a file, the file will be made dataless.
732 ///
733 /// When called on a directory, first each of the directory's children will be evicted (child files are made
734 /// dataless, child directories are recursively evicted). Then the directory itself will be made dataless.
735 /// If a non-evictable child is encountered, eviction will stop immediately and the completionHandler will be called with
736 /// the NSFileProviderErrorNonEvictableChildren error. The error will include information on why and which
737 /// children could not be evicted in -[NSError underlyingErrors].
738 ///
739 /// The materialization state of the remaining items may be either materialized or evicted, depending on the traversal order.
740 ///
741 /// The completion handler is called after the items have been evicted from disk or immediately when an error occurs.
742 ///
743 /// Eviction might fail with the following errors :
744 /// - NSFileProviderErrorDomain.NSFileProviderErrorUnsyncedEdits if the item had non-uploaded changes.
745 /// - NSFileProviderErrorDomain.NSFileProviderErrorNonEvictable if the item has been marked as non-purgeable by the provider.
746 /// - NSPOSIXErrorDomain.EBUSY : if the item has open file descriptors on it.
747 /// - NSPOSIXErrorDomain.EMLINK : if the item has several hardlinks.
748 /// - other NSPOSIXErrorDomain error codes if the system was unable to access or manipulate the corresponding file.
749 #[unsafe(method(evictItemWithIdentifier:completionHandler:))]
750 #[unsafe(method_family = none)]
751 pub unsafe fn evictItemWithIdentifier_completionHandler(
752 &self,
753 item_identifier: &NSFileProviderItemIdentifier,
754 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
755 );
756 );
757}
758
759/// Barrier.
760impl NSFileProviderManager {
761 extern_methods!(
762 #[cfg(all(feature = "NSFileProviderItem", feature = "block2"))]
763 /// Wait for all changes on disk in the sub-hierarchy of the item to be acknowledged by the extension.
764 ///
765 /// This call can be used to guarantee operation ordering in a sub-hierarchy of the provider. The completion
766 /// handler is called when all the changes for descendents of the item have been acknowledged by the extension.
767 /// If any error is met during that process, an error will be raised, in which case the caller should not
768 /// assume all the changes have been received.
769 ///
770 /// This call will only wait for changes affecting items that were already descendents of the requested item
771 /// in the provider, or items that have been newly created on disk. It will not wait for items that are already
772 /// known from the provider and are being moved in the directory. As a consequence, that call can be used from within a call
773 /// to -[NSFileProviderReplicatedExtension modifyItem:baseVersion:changedFields:contents:options:completionHandler:].
774 /// Also note that the call will return immediately on items that are not directories.
775 ///
776 /// In case a change cannot be applied to the provider, the call will fail with NSFileProviderErrorCannotSynchronize
777 /// including the NSFileProviderErrorItemKey with the identifier of the item that could not be synced if that item
778 /// is known by the provider.
779 #[unsafe(method(waitForChangesOnItemsBelowItemWithIdentifier:completionHandler:))]
780 #[unsafe(method_family = none)]
781 pub unsafe fn waitForChangesOnItemsBelowItemWithIdentifier_completionHandler(
782 &self,
783 item_identifier: &NSFileProviderItemIdentifier,
784 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
785 );
786 );
787}
788
789/// Stabilization.
790impl NSFileProviderManager {
791 extern_methods!(
792 #[cfg(feature = "block2")]
793 /// Wait for stabilization of the domain.
794 ///
795 /// The system will wait until it is caught up with the file system's changes up to
796 /// the time of the call, then wait until it is caught up with the provider's changes up to
797 /// the time of the call.
798 ///
799 /// The completion handler is called when both sets of changes are caught up to at least the time
800 /// of the call. This is useful to enforce a consistent state for testing.
801 #[unsafe(method(waitForStabilizationWithCompletionHandler:))]
802 #[unsafe(method_family = none)]
803 pub unsafe fn waitForStabilizationWithCompletionHandler(
804 &self,
805 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
806 );
807 );
808}
809
810/// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileprovidermanagerdisconnectionoptions?language=objc)
811// NS_OPTIONS
812#[repr(transparent)]
813#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
814pub struct NSFileProviderManagerDisconnectionOptions(pub NSUInteger);
815bitflags::bitflags! {
816 impl NSFileProviderManagerDisconnectionOptions: NSUInteger {
817 #[doc(alias = "NSFileProviderManagerDisconnectionOptionsTemporary")]
818 const Temporary = 1<<0;
819 }
820}
821
822unsafe impl Encode for NSFileProviderManagerDisconnectionOptions {
823 const ENCODING: Encoding = NSUInteger::ENCODING;
824}
825
826unsafe impl RefEncode for NSFileProviderManagerDisconnectionOptions {
827 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
828}
829
830/// Disconnection.
831impl NSFileProviderManager {
832 extern_methods!(
833 #[cfg(feature = "block2")]
834 #[unsafe(method(disconnectWithReason:options:completionHandler:))]
835 #[unsafe(method_family = none)]
836 pub unsafe fn disconnectWithReason_options_completionHandler(
837 &self,
838 localized_reason: &NSString,
839 options: NSFileProviderManagerDisconnectionOptions,
840 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
841 );
842
843 #[cfg(feature = "block2")]
844 #[unsafe(method(reconnectWithCompletionHandler:))]
845 #[unsafe(method_family = none)]
846 pub unsafe fn reconnectWithCompletionHandler(
847 &self,
848 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
849 );
850 );
851}
852
853/// Materialize.
854impl NSFileProviderManager {
855 extern_methods!(
856 #[cfg(all(feature = "NSFileProviderItem", feature = "block2"))]
857 /// Request that the system schedule a download for an item.
858 ///
859 /// The completion handler is called when the system acknowledges the download request,
860 /// or with an error indicating why it didn't (e.g NSFileProviderErrorNoSuchItem.)
861 /// The system will then call -fetchContentsForItemWithIdentifier at the earliest
862 /// convenient time.
863 ///
864 /// Set rangeToMaterialize to NSMakeRange(offset, nbytes) to request a partial download.
865 /// The system will then invoke -fetchPartialContentsForItemWithIdentifier instead of
866 /// fetchContentsForItemWithIdentifier. For a full download, set rangeToMaterialize to
867 /// NSMakeRange(NSNotFound, 0). -[NSFileProviderManager evictItemWithIdentifier:completionHandler:]
868 /// must be called on a partially materialized file before requesting an extent to be downloaded from a
869 /// later version of the file.
870 ///
871 /// This method cannot be used to download directories recursively. When invoked on a
872 /// dataless directory, it will trigger an enumeration of the directory, causing a
873 /// materialization of the directory one level down only. All the children of the
874 /// directory will remain dataless after the enumeration.
875 #[unsafe(method(requestDownloadForItemWithIdentifier:requestedRange:completionHandler:))]
876 #[unsafe(method_family = none)]
877 pub unsafe fn requestDownloadForItemWithIdentifier_requestedRange_completionHandler(
878 &self,
879 item_identifier: &NSFileProviderItemIdentifier,
880 range_to_materialize: NSRange,
881 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
882 );
883 );
884}
885
886/// StateDirectory.
887impl NSFileProviderManager {
888 extern_methods!(
889 /// A directory suitable for storing state information for the domain.
890 ///
891 /// The returned URL is guaranteed to be on the same volume as the user visible URL and the temporary URL, making sure
892 /// the system can atomatically clone/move files from that location to the user visible URL.
893 /// The caller is responsible for managing the security scope of the returned URL.
894 ///
895 /// When syncing a domain on an external volume, all information about the sync state must be kept in this directory
896 /// if the volume is to be shared between multiple machines.
897 ///
898 /// If the system cannot find a suitable directory, this call will fail. This could happen e.g. if the domain
899 /// does not exist or is in instance of initialization.
900 ///
901 /// This call will not fail when called from the extension process with an active instance of the extension
902 /// for that domain unless the domain is being setup for the very first time (meaning it never existed).
903 ///
904 /// Removing the domain will remove the corresponding directory along with it.
905 #[unsafe(method(stateDirectoryURLWithError:_))]
906 #[unsafe(method_family = none)]
907 pub unsafe fn stateDirectoryURLWithError(
908 &self,
909 ) -> Result<Retained<NSURL>, Retained<NSError>>;
910 );
911}
912
913/// [Apple's documentation](https://developer.apple.com/documentation/fileprovider/nsfileprovidervolumeunsupportedreason?language=objc)
914// NS_OPTIONS
915#[repr(transparent)]
916#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
917pub struct NSFileProviderVolumeUnsupportedReason(pub NSUInteger);
918bitflags::bitflags! {
919 impl NSFileProviderVolumeUnsupportedReason: NSUInteger {
920 #[doc(alias = "NSFileProviderVolumeUnsupportedReasonNone")]
921 const None = 0;
922 #[doc(alias = "NSFileProviderVolumeUnsupportedReasonUnknown")]
923 const Unknown = 1<<0;
924 #[doc(alias = "NSFileProviderVolumeUnsupportedReasonNonAPFS")]
925 const NonAPFS = 1<<1;
926 #[doc(alias = "NSFileProviderVolumeUnsupportedReasonNonEncrypted")]
927 const NonEncrypted = 1<<2;
928 #[doc(alias = "NSFileProviderVolumeUnsupportedReasonReadOnly")]
929 const ReadOnly = 1<<3;
930 #[doc(alias = "NSFileProviderVolumeUnsupportedReasonNetwork")]
931 const Network = 1<<4;
932 #[doc(alias = "NSFileProviderVolumeUnsupportedReasonQuarantined")]
933 const Quarantined = 1<<5;
934 }
935}
936
937unsafe impl Encode for NSFileProviderVolumeUnsupportedReason {
938 const ENCODING: Encoding = NSUInteger::ENCODING;
939}
940
941unsafe impl RefEncode for NSFileProviderVolumeUnsupportedReason {
942 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
943}
944
945/// ExternalDomain.
946impl NSFileProviderManager {
947 extern_methods!(
948 /// Check if a URL is eligible for storing a domain.
949 ///
950 /// This returns whether the check has been performed succesfully - NOT whether the drive is eligible.
951 ///
952 /// If an error was encountered while checking, this method returns FALSE and an error describing
953 /// the problem will be set.
954 ///
955 /// The eligible parameter will contain the result of the check and indicate whether the volume can be
956 /// used to store FP domains. Its value is only defined if the call returns YES.
957 ///
958 /// The url can be any existing and accessible URL on the volume for which you want to assess eligibility.
959 /// The checks are volume-wide and the exact location on the volume doesn't impact them.
960 ///
961 /// If a drive is eligible, unsupportedReason will be empty (0). Otherwise it will contain the list of identified
962 /// conditions that currently prevent this drive from being used to store FP domains.
963 ///
964 /// # Safety
965 ///
966 /// - `eligible` must be a valid pointer.
967 /// - `unsupported_reason` must be a valid pointer or null.
968 #[unsafe(method(checkDomainsCanBeStored:onVolumeAtURL:unsupportedReason:error:_))]
969 #[unsafe(method_family = none)]
970 pub unsafe fn checkDomainsCanBeStored_onVolumeAtURL_unsupportedReason_error(
971 eligible: NonNull<Bool>,
972 url: &NSURL,
973 unsupported_reason: *mut NSFileProviderVolumeUnsupportedReason,
974 ) -> Result<(), Retained<NSError>>;
975 );
976}
977
978/// Diagnostics.
979impl NSFileProviderManager {
980 extern_methods!(
981 #[cfg(all(feature = "NSFileProviderItem", feature = "block2"))]
982 /// Request diagnostics collection for the item.
983 ///
984 /// This will prompt the user about an issue with the sync in the provider and ask their permission
985 /// to collection diagnostic information and to send them to Apple for further analysis.
986 ///
987 /// This call is to be used wisely with care given there's global throttling on it preventing
988 /// spamming the users. Furthermore it should be used in collaboration with Apple when you
989 /// detect a misbehavior in the sync in your provider likely caused by a system bug and you need to
990 /// work with Apple in order to resolve it.
991 ///
992 /// This will return whether the call was allowed or not - not if it suceed
993 /// This method will only return an error if the user was not on a Seed build
994 ///
995 /// It is mandatory to provide an error for the item why the collection is requested.
996 /// The error won't be shown to the user (a generic message will be shown instead)
997 /// It will surface in the generated report though
998 ///
999 /// It is important to note that even if the call is allowed, it might not trigger diagnostic collection
1000 /// nor prompt to the user depending on the system state and other throttling parameters
1001 #[unsafe(method(requestDiagnosticCollectionForItemWithIdentifier:errorReason:completionHandler:))]
1002 #[unsafe(method_family = none)]
1003 pub unsafe fn requestDiagnosticCollectionForItemWithIdentifier_errorReason_completionHandler(
1004 &self,
1005 item_identifier: &NSFileProviderItemIdentifier,
1006 error_reason: &NSError,
1007 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
1008 );
1009 );
1010}