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