objc2-finder-sync 0.3.2

Bindings to the FinderSync framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
// This file has been automatically generated by `objc2`'s `header-translator`.
// DO NOT EDIT

#![allow(unused_imports)]
#![allow(deprecated)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![allow(missing_docs)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::identity_op)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::doc_lazy_continuation)]
#![allow(rustdoc::broken_intra_doc_links)]
#![allow(rustdoc::bare_urls)]
#![allow(rustdoc::invalid_html_tags)]

#[link(name = "FinderSync", kind = "framework")]
extern "C" {}

use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-app-kit")]
use objc2_app_kit::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// A controller that acts as a bridge between your Finder Sync extension and the Finder itself.
    ///
    /// Use the Finder Sync controller to configure your extension, to set badges
    /// on items in the Finder’s window, and to get a list of selected and targeted
    /// items.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/findersync/fifindersynccontroller?language=objc)
    #[unsafe(super(NSExtensionContext, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct FIFinderSyncController;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for FIFinderSyncController {}
);

impl FIFinderSyncController {
    extern_methods!(
        /// Returns the shared Finder Sync controller object.
        ///
        /// - Returns: The default Finder Sync controller object for this extension.
        #[unsafe(method(defaultController))]
        #[unsafe(method_family = none)]
        pub unsafe fn defaultController() -> Retained<Self>;

        /// The directories managed by this extension.
        ///
        /// The extension receives
        /// ``FIFinderSync/beginObservingDirectoryAtURL:`` and
        /// ``FIFinderSync/endObservingDirectoryAtURL:`` messages for every
        /// directory in this set and for all of their subdirectories.
        ///
        /// Always set `directoryURLs` when the extension starts. If there are no
        /// directories to watch, set `directoryURLs` to an empty set.
        #[unsafe(method(directoryURLs))]
        #[unsafe(method_family = none)]
        pub unsafe fn directoryURLs(&self) -> Retained<NSSet<NSURL>>;

        /// Setter for [`directoryURLs`][Self::directoryURLs].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setDirectoryURLs:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDirectoryURLs(&self, directory_ur_ls: Option<&NSSet<NSURL>>);

        #[cfg(feature = "objc2-app-kit")]
        /// Sets the badge image and label for the given ID.
        ///
        /// Use this method to configure your badges. Finder may display the image, the
        /// label or both. Your Finder Sync extension typically sets up a fixed number
        /// of badges during its `init` method.
        ///
        /// - Parameters:
        /// - image: An
        /// <doc
        /// ://com.apple.documentation/documentation/appkit/nsimage>
        /// object. The system may or may not draw this image on top of the item’s
        /// icon; when it does, the system determines the overlay position. Don't
        /// add any padding to the image to adjust this positioning. The image draws
        /// at up to 320 x 320 points.
        /// - label: A label describing the sync state represented by this badge.
        /// Each label should be a short localized string, such as "Waiting."
        /// - badgeID: A unique ID, identifying this badge.
        #[unsafe(method(setBadgeImage:label:forBadgeIdentifier:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setBadgeImage_label_forBadgeIdentifier(
            &self,
            image: &NSImage,
            label: Option<&NSString>,
            badge_id: &NSString,
        );

        /// Sets the badge for a file or directory.
        ///
        /// Adds the specified badge to the given file or directory. Setting the
        /// identifier to an empty string (`
        /// "
        /// "`) removes the badge.
        ///
        /// Avoid adding badges to items that the Finder hasn't displayed yet.
        /// When setting the initial badge, call this method from your Finder Sync
        /// extension’s ``FIFinderSync/requestBadgeIdentifierForURL:``
        /// method. When updating badges, call this method only for items that have
        /// already received a badge.
        ///
        /// - Parameters:
        /// - badgeID: A unique ID, identifying the badge.
        /// - url: The URL of the file or directory.
        ///
        /// ## See Also
        /// - ``FIFinderSync/requestBadgeIdentifierForURL:``
        #[unsafe(method(setBadgeIdentifier:forURL:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setBadgeIdentifier_forURL(&self, badge_id: &NSString, url: &NSURL);

        /// Returns the URL of the Finder’s current target.
        ///
        /// Use this method when creating a custom shortcut menu for the Finder. This
        /// returns the URL of the item that the user Control-clicked, letting you
        /// customize the menu for that item.
        ///
        /// This method returns valid values only from the Finder Sync extension’s
        /// ``FIFinderSync/menuForMenuKind:`` method or from one of the menu
        /// actions created in this method. If the selected items are outside the
        /// extension’s managed directories (for example, when the user clicks on the
        /// toolbar button), this method returns `nil`.
        ///
        /// - Returns: The URL of the Finder’s current target.
        #[unsafe(method(targetedURL))]
        #[unsafe(method_family = none)]
        pub unsafe fn targetedURL(&self) -> Option<Retained<NSURL>>;

        /// Returns an array of selected items.
        ///
        /// Use this method when creating a shortcut menu or a menu for the extension’s
        /// toolbar button. You can then modify the menu’s content based on the items
        /// currently selected.
        ///
        /// This method returns valid values only from the Finder Sync extension’s
        /// ``FIFinderSync/menuForMenuKind:`` method or from one of the menu
        /// actions created in this method. If the selected items are outside the
        /// extension’s managed directories (for example, when the user clicks on the
        /// toolbar button), this method returns `nil`.
        ///
        /// - Returns: An array of items currently selected in the Finder window.
        #[unsafe(method(selectedItemURLs))]
        #[unsafe(method_family = none)]
        pub unsafe fn selectedItemURLs(&self) -> Option<Retained<NSArray<NSURL>>>;

        #[unsafe(method(lastUsedDateForItemWithURL:))]
        #[unsafe(method_family = none)]
        pub unsafe fn lastUsedDateForItemWithURL(
            &self,
            item_url: &NSURL,
        ) -> Option<Retained<NSDate>>;

        #[cfg(feature = "block2")]
        #[unsafe(method(setLastUsedDate:forItemWithURL:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLastUsedDate_forItemWithURL_completion(
            &self,
            last_used_date: &NSDate,
            item_url: &NSURL,
            completion: &block2::DynBlock<dyn Fn(NonNull<NSError>)>,
        );

        #[unsafe(method(tagDataForItemWithURL:))]
        #[unsafe(method_family = none)]
        pub unsafe fn tagDataForItemWithURL(&self, item_url: &NSURL) -> Option<Retained<NSData>>;

        #[cfg(feature = "block2")]
        #[unsafe(method(setTagData:forItemWithURL:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTagData_forItemWithURL_completion(
            &self,
            tag_data: Option<&NSData>,
            item_url: &NSURL,
            completion: &block2::DynBlock<dyn Fn(NonNull<NSError>)>,
        );

        #[unsafe(method(isExtensionEnabled))]
        #[unsafe(method_family = none)]
        pub unsafe fn isExtensionEnabled() -> bool;

        #[unsafe(method(showExtensionManagementInterface))]
        #[unsafe(method_family = none)]
        pub unsafe fn showExtensionManagementInterface();
    );
}

/// Methods declared on superclass `NSObject`.
impl FIFinderSyncController {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// The different kinds of custom menus that the Finder Sync extension can
/// provide.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/findersync/fimenukind?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct FIMenuKind(pub NSUInteger);
impl FIMenuKind {
    /// A shortcut menu created when the user control-clicks on an item or a
    /// group of selected items inside the Finder window.
    #[doc(alias = "FIMenuKindContextualMenuForItems")]
    pub const ContextualMenuForItems: Self = Self(0);
    /// A shortcut menu created when the user control-clicks on the Finder
    /// window’s background.
    #[doc(alias = "FIMenuKindContextualMenuForContainer")]
    pub const ContextualMenuForContainer: Self = Self(1);
    /// A shortcut menu created when the user control-clicks on an item in the
    /// sidebar.
    #[doc(alias = "FIMenuKindContextualMenuForSidebar")]
    pub const ContextualMenuForSidebar: Self = Self(2);
    /// A menu created when the user clicks on the extension’s toolbar button.
    #[doc(alias = "FIMenuKindToolbarItemMenu")]
    pub const ToolbarItemMenu: Self = Self(3);
}

unsafe impl Encode for FIMenuKind {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for FIMenuKind {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    /// The group of methods to implement for modifying the Finder user interface to express file synchronization status and control.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/findersync/fifindersyncprotocol?language=objc)
    #[doc(alias = "FIFinderSync")]
    #[name = "FIFinderSync"]
    pub unsafe trait FIFinderSyncProtocol {
        #[cfg(feature = "objc2-app-kit")]
        /// Requests a custom menu from the extension.
        ///
        /// Override this method to provide custom menus in the Finder. You can
        /// customize this menu based both on the menu’s kind and on the selected and
        /// targeted items (if any). You can get the selected and targeted items from
        /// the extension’s ``FIFinderSyncController``.
        ///
        /// If `kind` is ``FIMenuKindToolbarItemMenu``, the system always calls this
        /// method even if the target and selection are not related to the extension.
        ///
        /// The extension's principal object provides a method for each menu item's
        /// assigned action.
        ///
        /// - Parameters:
        /// - menu: The type of menu being displayed. For a list of possible values, see ``FinderSync/FIMenuKind``.
        ///
        /// - Returns: A custom menu.
        ///
        /// ## See Also
        /// - ``FinderSync/FIFinderSyncController/targetedURL``
        /// - ``FinderSync/FIFinderSyncController/selectedItemURLs``
        #[optional]
        #[unsafe(method(menuForMenuKind:))]
        #[unsafe(method_family = none)]
        unsafe fn menuForMenuKind(
            &self,
            menu: FIMenuKind,
            mtm: MainThreadMarker,
        ) -> Option<Retained<NSMenu>>;

        /// Tells the extension that the user is looking at a monitored directory or at
        /// one of its subdirectories.
        ///
        /// Override this method to receive notifications when the user opens the
        /// contents of a monitored directory or one of its subdirectories in the
        /// Finder. The system calls `beginObservingDirectoryAtURL:` only once for each
        /// unique URL. As long as the content remains visible in at least one Finder
        /// window, any additional Finder windows that open to the same URL are ignored.
        ///
        /// - Note: The system creates additional instances of your extension for any
        /// Open and Save dialogs. These extensions receive their own calls to
        /// `beginObservingDirectoryAtURL:`, even if the directory is already open in a
        /// Finder window.
        ///
        /// - Parameters:
        /// - url: The URL of the directory.
        #[optional]
        #[unsafe(method(beginObservingDirectoryAtURL:))]
        #[unsafe(method_family = none)]
        unsafe fn beginObservingDirectoryAtURL(&self, url: &NSURL);

        /// Tells the extension that the user has stopped looking at a monitored
        /// directory or at one of its subdirectories.
        ///
        /// Override this method to receive notifications when the user is no longer
        /// looking at the contents of the given URL. As with
        /// ``FIFinderSync/beginObservingDirectoryAtURL:``, the Open and Save
        /// dialogs are tracked separately from the Finder.
        ///
        /// - Parameters:
        /// - url: The URL of the directory.
        #[optional]
        #[unsafe(method(endObservingDirectoryAtURL:))]
        #[unsafe(method_family = none)]
        unsafe fn endObservingDirectoryAtURL(&self, url: &NSURL);

        /// Requests a badge for the given file or directory.
        ///
        /// Override this method to receive notifications whenever a new item becomes
        /// visible in the Finder. Check the item’s state, and call
        /// ``FIFinderSyncController/setBadgeIdentifier:forURL:`` to set an appropriate
        /// badge.
        ///
        /// - Parameters:
        /// - url: The URL of a file or directory inside the extension’s monitored
        /// directories.
        ///
        /// ## See Also
        /// - ``FinderSync/FIFinderSyncController/setBadgeIdentifier:forURL:``
        #[optional]
        #[unsafe(method(requestBadgeIdentifierForURL:))]
        #[unsafe(method_family = none)]
        unsafe fn requestBadgeIdentifierForURL(&self, url: &NSURL);

        /// The name of the extension’s toolbar button.
        ///
        /// To add a toolbar item to the Finder, override the getter method for the
        /// toolbar image, name, and tooltip properties.
        #[optional]
        #[unsafe(method(toolbarItemName))]
        #[unsafe(method_family = none)]
        unsafe fn toolbarItemName(&self) -> Retained<NSString>;

        #[cfg(feature = "objc2-app-kit")]
        /// The image for the extension’s toolbar button.
        ///
        /// To add a toolbar item to the Finder, override the getter method for the
        /// toolbar image, name, and tooltip properties.
        #[optional]
        #[unsafe(method(toolbarItemImage))]
        #[unsafe(method_family = none)]
        unsafe fn toolbarItemImage(&self) -> Retained<NSImage>;

        /// The tooltip text for the extension’s toolbar button.
        ///
        /// To add a toolbar item to the Finder, override the getter method for the
        /// toolbar image, name, and tooltip properties.
        #[optional]
        #[unsafe(method(toolbarItemToolTip))]
        #[unsafe(method_family = none)]
        unsafe fn toolbarItemToolTip(&self) -> Retained<NSString>;

        #[optional]
        #[unsafe(method(supportedServiceNamesForItemWithURL:))]
        #[unsafe(method_family = none)]
        unsafe fn supportedServiceNamesForItemWithURL(
            &self,
            item_url: &NSURL,
        ) -> Retained<NSArray<NSFileProviderServiceName>>;

        #[optional]
        #[unsafe(method(makeListenerEndpointForServiceName:itemURL:andReturnError:_))]
        #[unsafe(method_family = none)]
        unsafe fn makeListenerEndpointForServiceName_itemURL_andReturnError(
            &self,
            service_name: &NSFileProviderServiceName,
            item_url: &NSURL,
        ) -> Result<Retained<NSXPCListenerEndpoint>, Retained<NSError>>;

        #[cfg(feature = "block2")]
        #[optional]
        #[unsafe(method(valuesForAttributes:forItemWithURL:completion:))]
        #[unsafe(method_family = none)]
        unsafe fn valuesForAttributes_forItemWithURL_completion(
            &self,
            attributes: &NSArray<NSURLResourceKey>,
            item_url: &NSURL,
            completion: &block2::DynBlock<
                dyn Fn(NonNull<NSDictionary<NSURLResourceKey, AnyObject>>, *mut NSError),
            >,
        );
    }
);

extern_class!(
    /// A type to subclass to add badges, custom shortcut menus, and toolbar buttons to the Finder.
    ///
    /// Subclass the FIFinderSync class when you want to customize the appearance of
    /// the Finder. Although the FIFinderSync class doesn’t provide any developer
    /// accessible API, it does adopt the ``FIFinderSyncProtocol``
    /// protocol. This protocol declares methods you can implement to modify the
    /// appearance of the Finder. For more information on these methods, see
    /// ``FIFinderSyncProtocol``. To learn more about creating a Finder Sync
    /// extension, see [Finder
    /// Sync](https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Finder.html#//apple_ref/doc/uid/TP40014214-CH15)
    /// in [App Extension Programming
    /// Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/index.html#//apple_ref/doc/uid/TP40014214).
    ///
    /// ## See Also
    /// - ``FinderSync/FIFinderSyncProtocol``
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/findersync/fifindersync?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct FIFinderSync;
);

extern_conformance!(
    unsafe impl FIFinderSyncProtocol for FIFinderSync {}
);

extern_conformance!(
    unsafe impl NSExtensionRequestHandling for FIFinderSync {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for FIFinderSync {}
);

impl FIFinderSync {
    extern_methods!();
}

/// Methods declared on superclass `NSObject`.
impl FIFinderSync {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}