core_services/
launch_services.rs

1#![allow(non_upper_case_globals)]
2#![allow(bad_style)]
3
4pub use core_foundation::array::CFArray;
5pub use core_foundation::array::CFArrayRef;
6/// The functions you want are probably missing - please make a [pull request](https://github.com/kornelski/core-services) adding whatever you need!
7///
8/// [The original Apple docs are here](https://developer.apple.com/documentation/coreservices?language=objc)
9use core_foundation::array::CFIndex;
10use core_foundation::base::CFAllocatorRef;
11use core_foundation::base::CFTypeID;
12use core_foundation::base::CFTypeRef;
13use core_foundation::base::OSStatus;
14pub use core_foundation::base::TCFType;
15use core_foundation::dictionary::CFDictionaryRef;
16use core_foundation::error::CFErrorRef;
17use core_foundation::runloop::CFRunLoopRef;
18pub use core_foundation::string::CFString;
19pub use core_foundation::string::CFStringRef;
20use core_foundation::url::CFURLRef;
21use std::os::raw::c_void;
22
23/// Requests the role None (the application cannot open the item, but provides an icon and a kind string for it).
24pub const kLSRolesNone: LSRolesMask = 0x00000001;
25
26/// Requests the role Viewer (the application can read and present the item, but cannot manipulate or save it).
27pub const kLSRolesViewer: LSRolesMask = 0x00000002;
28
29/// Requests the role Editor (the application can read, present, manipulate, and save the item).
30pub const kLSRolesEditor: LSRolesMask = 0x00000004;
31
32/// Requests the role Shell (the application can execute the item).
33pub const kLSRolesShell: LSRolesMask = 0x00000008;
34
35/// Accepts any role with respect to the item.
36pub const kLSRolesAll: LSRolesMask = 0xFFFFFFFF;
37
38/// Requests the default behavior (as opposed to the behavior specified by the kLSAcceptAllowLoginUI flag).
39pub const kLSAcceptDefault: LSAcceptanceFlags = 0x00000001;
40
41/// Requests that the user interface to log in be presented if necessary. If LSCanRefAcceptItem or
42/// LSCanURLAcceptURL is called during a drag-and-drop operation, showing a server login dialog would
43/// be an inappropriate user experience. If the target designated in the function call is an alias to
44/// an application, Launch Services needs to resolve the alias to ascertain what file types the
45/// application can open; however, if the application is on a server that needs to be authenticated,
46/// Launch Services will by default fail to resolve the alias, to avoid having to present the login interface.
47/// To override this default behavior by allowing the server login interface, set the kLSAcceptAllowLoginUI flag.
48pub const kLSAcceptAllowLoginUI: LSAcceptanceFlags = 0x00000002;
49
50pub type FourCharCode = u32;
51pub type OSType = FourCharCode;
52pub type ResType = FourCharCode;
53
54pub type DescType = ResType;
55#[repr(C)]
56#[derive(Debug, Copy, Clone)]
57pub struct OpaqueAEDataStorageType {
58    _unused: [u8; 0],
59}
60pub type AEDataStorageType = *mut OpaqueAEDataStorageType;
61pub type AEDataStorage = *mut AEDataStorageType;
62#[repr(C, packed(2))]
63#[derive(Debug, Copy, Clone)]
64pub struct AEDesc {
65    pub descriptorType: DescType,
66    pub dataHandle: AEDataStorage,
67}
68pub type OptionBits = u32;
69pub type AEDescList = AEDesc;
70pub type AERecord = AEDescList;
71pub type AppleEvent = AERecord;
72pub type LSRolesMask = OptionBits;
73/// Specify the desired role or roles for an application to claim with respect to an item or family of items.
74pub type LSAcceptanceFlags = OptionBits;
75pub type LSRequestedInfo = OptionBits;
76pub type LSItemInfoFlags = OptionBits;
77#[repr(C, packed(2))]
78#[derive(Debug, Copy, Clone)]
79pub struct LSItemInfoRecord {
80    pub flags: LSItemInfoFlags,
81    pub filetype: OSType,
82    pub creator: OSType,
83    pub extension: CFStringRef,
84}
85pub type LSHandlerOptions = OptionBits;
86#[repr(C)]
87#[derive(Copy, Clone)]
88pub struct FSRef {
89    pub hidden: [u8; 80usize],
90}
91
92pub type ItemCount = ::std::os::raw::c_ulong;
93
94#[repr(C, packed(2))]
95#[derive(Debug, Copy, Clone)]
96pub struct LSLaunchFSRefSpec {
97    pub appRef: *const FSRef,
98    pub numDocs: ItemCount,
99    pub itemRefs: *const FSRef,
100    pub passThruParams: *const AEDesc,
101    pub launchFlags: LSLaunchFlags,
102    pub asyncRefCon: *mut ::std::os::raw::c_void,
103}
104#[repr(C, packed(2))]
105#[derive(Debug, Copy, Clone)]
106pub struct LSApplicationParameters {
107    pub version: CFIndex,
108    pub flags: LSLaunchFlags,
109    pub application: *const FSRef,
110    pub asyncLaunchRefCon: *mut ::std::os::raw::c_void,
111    pub environment: CFDictionaryRef,
112    pub argv: CFArrayRef,
113    pub initialEvent: *mut AppleEvent,
114}
115#[repr(C)]
116#[derive(Debug, Copy, Clone)]
117pub struct OpaqueLSSharedFileListItemRef {
118    _unused: [u8; 0],
119}
120pub type LSSharedFileListItemRef = *mut OpaqueLSSharedFileListItemRef;
121pub type LSSharedFileListResolutionFlags = u32;
122pub type LSSharedFileListChangedProcPtr = ::std::option::Option<
123    unsafe extern "C" fn(inList: LSSharedFileListRef, context: *mut ::std::os::raw::c_void),
124>;
125
126#[repr(C)]
127#[derive(Debug, Copy, Clone)]
128pub struct OpaqueIconRef {
129    _unused: [u8; 0],
130}
131pub type IconRef = *mut OpaqueIconRef;
132
133#[repr(C)]
134#[derive(Debug, Copy, Clone)]
135pub struct AuthorizationOpaqueRef {
136    _unused: [u8; 0],
137}
138pub type AuthorizationRef = *const AuthorizationOpaqueRef;
139
140#[repr(C, packed(2))]
141pub struct LSLaunchURLSpec {
142    /// A Core Foundation URL reference designating the application to launch.
143    /// The URL must have scheme file and contain a valid path to an application file or application bundle.
144    /// Set this field to NULL to request that each item in the itemURLs array be opened in its own preferred application.
145    pub appURL: CFURLRef,
146    /// items to open/print
147    pub itemURLs: CFArrayRef,
148    /// passed untouched to application as optional parameter
149    pub passThruParams: *const AEDesc,
150    pub launchFlags: LSLaunchFlags,
151    /// used if you register for app birth/death notification
152    pub asyncRefCon: *mut c_void,
153}
154
155pub type LSLaunchFlags = u32;
156
157/// Defaults = open, async
158pub const kLSLaunchDefaults: LSLaunchFlags = 0x00000001;
159/// Print items instead of open them
160pub const kLSLaunchAndPrint: LSLaunchFlags = 0x00000002;
161/// Report launch/open failures in the UI
162pub const kLSLaunchAndDisplayErrors: LSLaunchFlags = 0x00000040;
163/// Do not add app or documents to recents menus.
164pub const kLSLaunchDontAddToRecents: LSLaunchFlags = 0x00000100;
165/// Do not bring new app to the foreground.
166pub const kLSLaunchDontSwitch: LSLaunchFlags = 0x00000200;
167/// Asynchronous launch; return as soon as the app starts launching.
168pub const kLSLaunchAsync: LSLaunchFlags = 0x00010000;
169/// Instantiate app even if it is already running.
170pub const kLSLaunchNewInstance: LSLaunchFlags = 0x00080000;
171/// Send child a "hide" request as soon as it checks in.
172pub const kLSLaunchAndHide: LSLaunchFlags = 0x00100000;
173/// Hide all other apps when the app checks in.
174pub const kLSLaunchAndHideOthers: LSLaunchFlags = 0x00200000;
175
176#[link(name = "CoreServices", kind = "framework")]
177extern "C" {
178    /// Indicates that the tag is a filename extension.
179    pub static kUTTagClassFilenameExtension: CFStringRef;
180    /// Indicates that the tag is a MIME type.
181    pub static kUTTagClassMIMEType: CFStringRef;
182    /// Indicates that the tag is an NSPasteBoard type.
183    pub static kUTTagClassNSPboardType: CFStringRef;
184    /// Indicates that the tag is an OSType.
185    pub static kUTTagClassOSType: CFStringRef;
186
187    pub fn UTTypeCreatePreferredIdentifierForTag(
188        inTagClass: CFStringRef,
189        inTag: CFStringRef,
190        inConformingToUTI: CFStringRef,
191    ) -> CFStringRef;
192
193    pub fn LSCopyDefaultRoleHandlerForContentType(
194        inContentType: CFStringRef,
195        inRole: LSRolesMask,
196    ) -> CFStringRef;
197    /// Locates an array of application bundle identifiers for applications capable of handling a specified content type with the specified roles.
198    pub fn LSCopyAllRoleHandlersForContentType(
199        inContentType: CFStringRef,
200        inRole: LSRolesMask,
201    ) -> CFArrayRef;
202
203    /// Locates all URLs for applications that correspond to the specified bundle identifier.
204    pub fn LSCopyApplicationURLsForBundleIdentifier(
205        inBundleIdentifier: CFStringRef,
206        outError: *mut CFErrorRef,
207    ) -> CFArrayRef;
208
209    /// Tests whether an application can accept (open) an item designated by URL.
210    pub fn LSCanURLAcceptURL(
211        inItemURL: CFURLRef,
212        inTargetURL: CFURLRef,
213        inRoleMask: LSRolesMask,
214        inFlags: LSAcceptanceFlags,
215        outAcceptsItem: *mut bool,
216    ) -> OSStatus;
217
218    /// Opens one or more items designated by URL, in either their preferred applications or a designated application.
219    pub fn LSOpenFromURLSpec(
220        inLaunchSpec: *const LSLaunchURLSpec,
221        outLaunchedURL: *mut CFURLRef,
222    ) -> OSStatus;
223}
224
225#[repr(C)]
226#[derive(Debug, Copy, Clone)]
227pub struct OpaqueLSSharedFileListRef {
228    _unused: [u8; 0],
229}
230pub type LSSharedFileListRef = *mut OpaqueLSSharedFileListRef;
231
232extern "C" {
233    pub fn LSSharedFileListGetTypeID() -> CFTypeID;
234
235    pub fn LSSharedFileListItemGetTypeID() -> CFTypeID;
236
237    pub fn LSSharedFileListCreate(
238        inAllocator: CFAllocatorRef,
239        inListType: CFStringRef,
240        listOptions: CFTypeRef,
241    ) -> LSSharedFileListRef;
242
243    pub fn LSSharedFileListSetAuthorization(
244        inList: LSSharedFileListRef,
245        inAuthorization: AuthorizationRef,
246    ) -> OSStatus;
247
248    pub fn LSSharedFileListAddObserver(
249        inList: LSSharedFileListRef,
250        inRunloop: CFRunLoopRef,
251        inRunloopMode: CFStringRef,
252        callback: LSSharedFileListChangedProcPtr,
253        context: *mut ::std::os::raw::c_void,
254    );
255
256    pub fn LSSharedFileListRemoveObserver(
257        inList: LSSharedFileListRef,
258        inRunloop: CFRunLoopRef,
259        inRunloopMode: CFStringRef,
260        callback: LSSharedFileListChangedProcPtr,
261        context: *mut ::std::os::raw::c_void,
262    );
263
264    pub fn LSSharedFileListGetSeedValue(inList: LSSharedFileListRef) -> u32;
265
266    pub fn LSSharedFileListCopyProperty(
267        inList: LSSharedFileListRef,
268        inPropertyName: CFStringRef,
269    ) -> CFTypeRef;
270
271    pub fn LSSharedFileListSetProperty(
272        inList: LSSharedFileListRef,
273        inPropertyName: CFStringRef,
274        inPropertyData: CFTypeRef,
275    ) -> OSStatus;
276
277    pub fn LSSharedFileListCopySnapshot(
278        inList: LSSharedFileListRef,
279        outSnapshotSeed: *mut u32,
280    ) -> CFArrayRef;
281
282    pub fn LSSharedFileListInsertItemURL(
283        inList: LSSharedFileListRef,
284        insertAfterThisItem: LSSharedFileListItemRef,
285        inDisplayName: CFStringRef,
286        inIconRef: IconRef,
287        inURL: CFURLRef,
288        inPropertiesToSet: CFDictionaryRef,
289        inPropertiesToClear: CFArrayRef,
290    ) -> LSSharedFileListItemRef;
291
292    pub fn LSSharedFileListInsertItemFSRef(
293        inList: LSSharedFileListRef,
294        insertAfterThisItem: LSSharedFileListItemRef,
295        inDisplayName: CFStringRef,
296        inIconRef: IconRef,
297        inFSRef: *const FSRef,
298        inPropertiesToSet: CFDictionaryRef,
299        inPropertiesToClear: CFArrayRef,
300    ) -> LSSharedFileListItemRef;
301
302    pub fn LSSharedFileListItemMove(
303        inList: LSSharedFileListRef,
304        inItem: LSSharedFileListItemRef,
305        inMoveAfterItem: LSSharedFileListItemRef,
306    ) -> OSStatus;
307
308    pub fn LSSharedFileListItemRemove(
309        inList: LSSharedFileListRef,
310        inItem: LSSharedFileListItemRef,
311    ) -> OSStatus;
312
313    pub fn LSSharedFileListRemoveAllItems(inList: LSSharedFileListRef) -> OSStatus;
314
315    pub fn LSSharedFileListItemGetID(inItem: LSSharedFileListItemRef) -> u32;
316
317    pub fn LSSharedFileListItemCopyIconRef(inItem: LSSharedFileListItemRef) -> IconRef;
318
319    pub fn LSSharedFileListItemCopyDisplayName(inItem: LSSharedFileListItemRef) -> CFStringRef;
320
321    pub fn LSSharedFileListItemResolve(
322        inItem: LSSharedFileListItemRef,
323        inFlags: LSSharedFileListResolutionFlags,
324        outURL: *mut CFURLRef,
325        outRef: *mut FSRef,
326    ) -> OSStatus;
327
328    pub fn LSSharedFileListItemCopyResolvedURL(
329        inItem: LSSharedFileListItemRef,
330        inFlags: LSSharedFileListResolutionFlags,
331        outError: *mut CFErrorRef,
332    ) -> CFURLRef;
333
334    pub fn LSSharedFileListItemCopyProperty(
335        inItem: LSSharedFileListItemRef,
336        inPropertyName: CFStringRef,
337    ) -> CFTypeRef;
338
339    pub fn LSSharedFileListItemSetProperty(
340        inItem: LSSharedFileListItemRef,
341        inPropertyName: CFStringRef,
342        inPropertyData: CFTypeRef,
343    ) -> OSStatus;
344}
345
346pub const kLSNo32BitEnvironmentErr: no_overview_available_1191 = -10386;
347pub const kLSAppInTrashErr: no_overview_available_1191 = -10660;
348pub const kLSExecutableIncorrectFormat: no_overview_available_1191 = -10661;
349pub const kLSAttributeNotFoundErr: no_overview_available_1191 = -10662;
350pub const kLSAttributeNotSettableErr: no_overview_available_1191 = -10663;
351pub const kLSIncompatibleApplicationVersionErr: no_overview_available_1191 = -10664;
352pub const kLSNoRosettaEnvironmentErr: no_overview_available_1191 = -10665;
353pub const kLSGarbageCollectionUnsupportedErr: no_overview_available_1191 = -10666;
354pub const kLSUnknownErr: no_overview_available_1191 = -10810;
355pub const kLSNotAnApplicationErr: no_overview_available_1191 = -10811;
356pub const kLSNotInitializedErr: no_overview_available_1191 = -10812;
357pub const kLSDataUnavailableErr: no_overview_available_1191 = -10813;
358pub const kLSApplicationNotFoundErr: no_overview_available_1191 = -10814;
359pub const kLSUnknownTypeErr: no_overview_available_1191 = -10815;
360pub const kLSDataTooOldErr: no_overview_available_1191 = -10816;
361pub const kLSDataErr: no_overview_available_1191 = -10817;
362pub const kLSLaunchInProgressErr: no_overview_available_1191 = -10818;
363pub const kLSNotRegisteredErr: no_overview_available_1191 = -10819;
364pub const kLSAppDoesNotClaimTypeErr: no_overview_available_1191 = -10820;
365pub const kLSAppDoesNotSupportSchemeWarning: no_overview_available_1191 = -10821;
366pub const kLSServerCommunicationErr: no_overview_available_1191 = -10822;
367pub const kLSCannotSetInfoErr: no_overview_available_1191 = -10823;
368pub const kLSNoRegistrationInfoErr: no_overview_available_1191 = -10824;
369pub const kLSIncompatibleSystemVersionErr: no_overview_available_1191 = -10825;
370pub const kLSNoLaunchPermissionErr: no_overview_available_1191 = -10826;
371pub const kLSNoExecutableErr: no_overview_available_1191 = -10827;
372pub const kLSNoClassicEnvironmentErr: no_overview_available_1191 = -10828;
373pub const kLSMultipleSessionsNotSupportedErr: no_overview_available_1191 = -10829;
374pub type no_overview_available_1191 = i32;
375pub const kLSUnknownType: no_overview_available_1193 = 0;
376pub const kLSUnknownCreator: no_overview_available_1193 = 0;
377pub type no_overview_available_1193 = u32;
378
379pub const kLSRequestExtension: LSRequestedInfo = 1;
380pub const kLSRequestTypeCreator: LSRequestedInfo = 2;
381pub const kLSRequestBasicFlagsOnly: LSRequestedInfo = 4;
382pub const kLSRequestAppTypeFlags: LSRequestedInfo = 8;
383pub const kLSRequestAllFlags: LSRequestedInfo = 16;
384pub const kLSRequestIconAndKind: LSRequestedInfo = 32;
385pub const kLSRequestExtensionFlagsOnly: LSRequestedInfo = 64;
386pub const kLSRequestAllInfo: LSRequestedInfo = 4294967295;
387
388pub const kLSItemInfoIsPlainFile: LSItemInfoFlags = 1;
389pub const kLSItemInfoIsPackage: LSItemInfoFlags = 2;
390pub const kLSItemInfoIsApplication: LSItemInfoFlags = 4;
391pub const kLSItemInfoIsContainer: LSItemInfoFlags = 8;
392pub const kLSItemInfoIsAliasFile: LSItemInfoFlags = 16;
393pub const kLSItemInfoIsSymlink: LSItemInfoFlags = 32;
394pub const kLSItemInfoIsInvisible: LSItemInfoFlags = 64;
395pub const kLSItemInfoIsNativeApp: LSItemInfoFlags = 128;
396pub const kLSItemInfoIsClassicApp: LSItemInfoFlags = 256;
397pub const kLSItemInfoAppPrefersNative: LSItemInfoFlags = 512;
398pub const kLSItemInfoAppPrefersClassic: LSItemInfoFlags = 1024;
399pub const kLSItemInfoAppIsScriptable: LSItemInfoFlags = 2048;
400pub const kLSItemInfoIsVolume: LSItemInfoFlags = 4096;
401pub const kLSItemInfoExtensionIsHidden: LSItemInfoFlags = 1048576;
402
403extern "C" {
404    pub static mut kLSSharedFileListFavoriteVolumes: CFStringRef;
405    pub static mut kLSSharedFileListFavoriteItems: CFStringRef;
406    pub static mut kLSSharedFileListRecentApplicationItems: CFStringRef;
407    pub static mut kLSSharedFileListRecentDocumentItems: CFStringRef;
408    pub static mut kLSSharedFileListRecentServerItems: CFStringRef;
409    pub static mut kLSSharedFileListSessionLoginItems: CFStringRef;
410    pub static mut kLSSharedFileListGlobalLoginItems: CFStringRef;
411    pub static mut kLSSharedFileListRecentItemsMaxAmount: CFStringRef;
412    pub static mut kLSSharedFileListVolumesComputerVisible: CFStringRef;
413    pub static mut kLSSharedFileListVolumesIDiskVisible: CFStringRef;
414    pub static mut kLSSharedFileListVolumesNetworkVisible: CFStringRef;
415    pub static mut kLSSharedFileListItemBeforeFirst: LSSharedFileListItemRef;
416    pub static mut kLSSharedFileListItemLast: LSSharedFileListItemRef;
417    pub static mut kLSSharedFileListItemHidden: CFStringRef;
418    pub static mut kLSSharedFileListLoginItemHidden: CFStringRef;
419}
420extern "C" {
421    pub static kLSItemContentType: CFStringRef;
422    pub static kLSItemFileType: CFStringRef;
423    pub static kLSItemFileCreator: CFStringRef;
424    pub static kLSItemExtension: CFStringRef;
425    pub static kLSItemDisplayName: CFStringRef;
426    pub static kLSItemDisplayKind: CFStringRef;
427    pub static kLSItemRoleHandlerDisplayName: CFStringRef;
428    pub static kLSItemIsInvisible: CFStringRef;
429    pub static kLSItemExtensionIsHidden: CFStringRef;
430    pub static kLSItemQuarantineProperties: CFStringRef;
431}
432
433extern "C" {
434    pub static kLSQuarantineAgentNameKey: CFStringRef;
435    pub static kLSQuarantineAgentBundleIdentifierKey: CFStringRef;
436    pub static kLSQuarantineTimeStampKey: CFStringRef;
437    pub static kLSQuarantineTypeKey: CFStringRef;
438    pub static kLSQuarantineTypeWebDownload: CFStringRef;
439    pub static kLSQuarantineTypeOtherDownload: CFStringRef;
440    pub static kLSQuarantineTypeEmailAttachment: CFStringRef;
441    pub static kLSQuarantineTypeInstantMessageAttachment: CFStringRef;
442    pub static kLSQuarantineTypeCalendarEventAttachment: CFStringRef;
443    pub static kLSQuarantineTypeOtherAttachment: CFStringRef;
444    pub static kLSQuarantineOriginURLKey: CFStringRef;
445    pub static kLSQuarantineDataURLKey: CFStringRef;
446}
447
448pub const kLSLaunchInhibitBGOnly: no_overview_available_1199 = 128;
449pub const kLSLaunchNoParams: no_overview_available_1199 = 2048;
450pub const kLSLaunchStartClassic: no_overview_available_1199 = 131072;
451pub const kLSLaunchInClassic: no_overview_available_1199 = 262144;
452pub const kLSLaunchHasUntrustedContents: no_overview_available_1199 = 4194304;
453pub type no_overview_available_1199 = u32;
454
455pub const kLSSharedFileListNoUserInteraction: LSSharedFileListResolutionFlags = 1;
456pub const kLSSharedFileListDoNotMountVolumes: LSSharedFileListResolutionFlags = 2;