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