objc2_app_kit/generated/
NSRunningApplication.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
10/// The following flags are for `-activateWithOptions:` and equivalent.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsapplicationactivationoptions?language=objc)
13// NS_OPTIONS
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct NSApplicationActivationOptions(pub NSUInteger);
17bitflags::bitflags! {
18    impl NSApplicationActivationOptions: NSUInteger {
19/// By default, activation brings only the main and key
20/// windows forward. If you specify `activateAllWindows`,
21/// all of the application's windows are brought forward.
22        #[doc(alias = "NSApplicationActivateAllWindows")]
23        const ActivateAllWindows = 1<<0;
24/// The application is activated regardless of the currently
25/// active app.
26        #[doc(alias = "NSApplicationActivateIgnoringOtherApps")]
27#[deprecated = "ignoringOtherApps is deprecated in macOS 14 and will have no effect."]
28        const ActivateIgnoringOtherApps = 1<<1;
29    }
30}
31
32unsafe impl Encode for NSApplicationActivationOptions {
33    const ENCODING: Encoding = NSUInteger::ENCODING;
34}
35
36unsafe impl RefEncode for NSApplicationActivationOptions {
37    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40/// The following activation policies control whether and how an application may be activated.
41/// They are determined by the `Info.plist`.
42///
43/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsapplicationactivationpolicy?language=objc)
44// NS_ENUM
45#[repr(transparent)]
46#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
47pub struct NSApplicationActivationPolicy(pub NSInteger);
48impl NSApplicationActivationPolicy {
49    #[doc(alias = "NSApplicationActivationPolicyRegular")]
50    pub const Regular: Self = Self(0);
51    #[doc(alias = "NSApplicationActivationPolicyAccessory")]
52    pub const Accessory: Self = Self(1);
53    #[doc(alias = "NSApplicationActivationPolicyProhibited")]
54    pub const Prohibited: Self = Self(2);
55}
56
57unsafe impl Encode for NSApplicationActivationPolicy {
58    const ENCODING: Encoding = NSInteger::ENCODING;
59}
60
61unsafe impl RefEncode for NSApplicationActivationPolicy {
62    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
63}
64
65extern_class!(
66    /// `NSRunningApplication` is a class to manipulate and provide information for a single instance of an application.  Only user applications are tracked; this does not provide information about every process on the system.
67    ///
68    /// Some properties of an application are fixed, such as the bundle identifier.  Other properties may vary over time, such as whether the app is hidden.  Properties that vary can be observed with KVO, in which case the description comment for the method will mention it.
69    ///
70    /// Properties that vary over time are inherently race-prone.  For example, a hidden app may unhide itself at any time.  To ameliorate this, properties persist until the next turn of the main run loop in a common mode.  For example, if you repeatedly poll an unhidden app for its hidden property without allowing the run loop to run, it will continue to return `NO`, even if the app hides, until the next turn of the run loop.
71    ///
72    /// `NSRunningApplication` is thread safe, in that its properties are returned atomically.  However, it is still subject to the main run loop policy described above.  If you access an instance of `NSRunningApplication` from a background thread, be aware that its time-varying properties may change from under you as the main run loop runs (or not).
73    ///
74    /// An `NSRunningApplication` instance remains valid after the application exits.  However, most properties lose their significance, and some properties may not be available on a terminated application.
75    ///
76    /// To access the list of all running applications, use the `-runningApplications` method on `NSWorkspace`.
77    ///
78    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrunningapplication?language=objc)
79    #[unsafe(super(NSObject))]
80    #[derive(Debug, PartialEq, Eq, Hash)]
81    pub struct NSRunningApplication;
82);
83
84unsafe impl Send for NSRunningApplication {}
85
86unsafe impl Sync for NSRunningApplication {}
87
88extern_conformance!(
89    unsafe impl NSObjectProtocol for NSRunningApplication {}
90);
91
92impl NSRunningApplication {
93    extern_methods!(
94        /// Indicates that the process is an exited application.
95        /// This is observable through KVO.
96        #[unsafe(method(isTerminated))]
97        #[unsafe(method_family = none)]
98        pub unsafe fn isTerminated(&self) -> bool;
99
100        /// Indicates that the process is finished launching, which corresponds to the
101        /// `NSApplicationDidFinishLaunching`internal notification.
102        /// This is observable through KVO.
103        /// Some applications do not post this notification and so are never reported as finished launching.
104        #[unsafe(method(isFinishedLaunching))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn isFinishedLaunching(&self) -> bool;
107
108        /// Indicates whether the application is currently hidden.
109        /// This is observable through KVO.
110        #[unsafe(method(isHidden))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn isHidden(&self) -> bool;
113
114        /// Indicates whether the application is currently frontmost.
115        /// This is observable through KVO.
116        #[unsafe(method(isActive))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn isActive(&self) -> bool;
119
120        /// Indicates whether the application currently owns the menu bar.
121        /// This is observable through KVO.
122        #[unsafe(method(ownsMenuBar))]
123        #[unsafe(method_family = none)]
124        pub unsafe fn ownsMenuBar(&self) -> bool;
125
126        /// Indicates the activation policy of the application.
127        /// This is observable through KVO (the type is usually fixed, but may be changed through a call to `-[NSApplication setActivationPolicy:]`).
128        #[unsafe(method(activationPolicy))]
129        #[unsafe(method_family = none)]
130        pub unsafe fn activationPolicy(&self) -> NSApplicationActivationPolicy;
131
132        /// Indicates the name of the application.
133        /// This is dependent on the current localization of the referenced app, and is suitable for presentation to the user.
134        #[unsafe(method(localizedName))]
135        #[unsafe(method_family = none)]
136        pub unsafe fn localizedName(&self) -> Option<Retained<NSString>>;
137
138        /// Indicates the `CFBundleIdentifier` of the application, or nil if the application does not have an `Info.plist`.
139        #[unsafe(method(bundleIdentifier))]
140        #[unsafe(method_family = none)]
141        pub unsafe fn bundleIdentifier(&self) -> Option<Retained<NSString>>;
142
143        /// Indicates the URL to the application's bundle, or nil if the application does not have a bundle.
144        #[unsafe(method(bundleURL))]
145        #[unsafe(method_family = none)]
146        pub unsafe fn bundleURL(&self) -> Option<Retained<NSURL>>;
147
148        /// Indicates the URL to the application's executable.
149        #[unsafe(method(executableURL))]
150        #[unsafe(method_family = none)]
151        pub unsafe fn executableURL(&self) -> Option<Retained<NSURL>>;
152
153        #[cfg(feature = "libc")]
154        /// Indicates the process identifier (pid) of the application.
155        /// Do not rely on this for comparing processes.  Use `-isEqual:` instead.
156        ///
157        /// Note: Not all applications have a pid.  Applications without a pid return -1 from this method.
158        /// This is observable through KVO (an application's pid may change if it is automatically terminated).
159        #[unsafe(method(processIdentifier))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn processIdentifier(&self) -> libc::pid_t;
162
163        /// Indicates the date when the application was launched.
164        /// This property is not available for all applications.
165        /// Specifically, it is not available for applications that were launched without going through `LaunchServices`.
166        #[unsafe(method(launchDate))]
167        #[unsafe(method_family = none)]
168        pub unsafe fn launchDate(&self) -> Option<Retained<NSDate>>;
169
170        #[cfg(feature = "NSImage")]
171        /// Returns: The icon of the application.
172        #[unsafe(method(icon))]
173        #[unsafe(method_family = none)]
174        pub unsafe fn icon(&self) -> Option<Retained<NSImage>>;
175
176        /// Indicates the executing processor architecture for the application, as an
177        /// `NSBundleExecutableArchitecture`from `NSBundle.h`.
178        #[unsafe(method(executableArchitecture))]
179        #[unsafe(method_family = none)]
180        pub unsafe fn executableArchitecture(&self) -> NSInteger;
181
182        /// Attempts to hide the receiver.
183        ///
184        /// Returns: `YES` if the request to hide or unhide was successfully sent, `NO` if not (for example, if the application has quit, or is of a type that cannot be unhidden).
185        #[unsafe(method(hide))]
186        #[unsafe(method_family = none)]
187        pub unsafe fn hide(&self) -> bool;
188
189        /// Attempts to unhide the receiver.
190        ///
191        /// Returns: `YES` if the request to hide or unhide was successfully sent, `NO` if not (for example, if the application has quit, or is of a type that cannot be unhidden).
192        #[unsafe(method(unhide))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn unhide(&self) -> bool;
195
196        /// Attempts to activate the application using the specified options.
197        ///
198        /// You shouldn’t assume the app will be active immediately
199        /// after sending this message. The framework also does not
200        /// guarantee that the app will be activated at all.
201        ///
202        /// Additionally allows specifying another application to take
203        /// the active status from, which can be used for coordinated
204        /// or cooperative activation. The other application should
205        /// call `-yieldActivationToApplication:` or equivalent prior to this
206        /// request being sent.
207        ///
208        ///
209        /// Returns: `YES` if the request has been allowed by the system,
210        /// otherwise `NO`.
211        #[unsafe(method(activateFromApplication:options:))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn activateFromApplication_options(
214            &self,
215            application: &NSRunningApplication,
216            options: NSApplicationActivationOptions,
217        ) -> bool;
218
219        /// Attempts to activate the receiver.
220        ///
221        /// Returns: `YES` if the request to activate was successfully sent, `NO` if not (for example, if the application has quit, or is of a type that cannot be activated).
222        #[unsafe(method(activateWithOptions:))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn activateWithOptions(&self, options: NSApplicationActivationOptions) -> bool;
225
226        /// Attempts to quit the receiver normally.
227        ///
228        /// Returns: `YES` if the request was successfully sent, `NO` if not (for example, if the application is no longer running).
229        /// This method may return before the receiver exits; you should observe the terminated property or listen for the notification to detect when the app has exited.
230        #[unsafe(method(terminate))]
231        #[unsafe(method_family = none)]
232        pub unsafe fn terminate(&self) -> bool;
233
234        /// Attempts to force the receiver to quit.
235        ///
236        /// Returns: `YES` if the request was successfully sent, `NO` if not (for example, if the application is no longer running).
237        /// This method may return before the receiver exits; you should observe the terminated property or listen for the notification to detect when the app has exited.
238        #[unsafe(method(forceTerminate))]
239        #[unsafe(method_family = none)]
240        pub unsafe fn forceTerminate(&self) -> bool;
241
242        /// Returns: An array of currently running applications with the given bundle identifier, or an empty array if no apps match.
243        #[unsafe(method(runningApplicationsWithBundleIdentifier:))]
244        #[unsafe(method_family = none)]
245        pub unsafe fn runningApplicationsWithBundleIdentifier(
246            bundle_identifier: &NSString,
247        ) -> Retained<NSArray<NSRunningApplication>>;
248
249        #[cfg(feature = "libc")]
250        /// Returns: The running application with the given process identifier, or nil if no application has that pid.
251        /// Applications that do not have PIDs cannot be returned from this method.
252        #[unsafe(method(runningApplicationWithProcessIdentifier:))]
253        #[unsafe(method_family = none)]
254        pub unsafe fn runningApplicationWithProcessIdentifier(
255            pid: libc::pid_t,
256        ) -> Option<Retained<Self>>;
257
258        /// Returns: An
259        /// `NSRunningApplication`representing this application.
260        #[unsafe(method(currentApplication))]
261        #[unsafe(method_family = none)]
262        pub unsafe fn currentApplication() -> Retained<NSRunningApplication>;
263
264        /// Cause any applications that are invisibly still running (see `NSProcessInfo.h` automatic termination methods and docs) to terminate as if triggered by system memory pressure.
265        /// This is intended for installer apps and the like to make sure that nothing is unexpectedly relying on the files they're replacing.
266        #[unsafe(method(terminateAutomaticallyTerminableApplications))]
267        #[unsafe(method_family = none)]
268        pub unsafe fn terminateAutomaticallyTerminableApplications();
269    );
270}
271
272/// Methods declared on superclass `NSObject`.
273impl NSRunningApplication {
274    extern_methods!(
275        #[unsafe(method(init))]
276        #[unsafe(method_family = init)]
277        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
278
279        #[unsafe(method(new))]
280        #[unsafe(method_family = new)]
281        pub unsafe fn new() -> Retained<Self>;
282    );
283}
284
285/// NSWorkspaceRunningApplications.
286#[cfg(feature = "NSWorkspace")]
287impl NSWorkspace {
288    extern_methods!(
289        /// Returns: An array of `NSRunningApplication`s representing currently running applications.
290        /// The order of the array is unspecified, but it is stable, meaning that the relative order of particular applications will not change across multiple calls to `runningApplications`.
291        /// Similar to `NSRunningApplication`'s properties, this property will only change when the main run loop is run in a common mode.  Instead of polling, use key-value observing to be notified of changes to this array property.
292        /// This property is thread safe, in that it may be called from background threads and the result is returned atomically.  This property is observable through KVO.
293        #[unsafe(method(runningApplications))]
294        #[unsafe(method_family = none)]
295        pub unsafe fn runningApplications(&self) -> Retained<NSArray<NSRunningApplication>>;
296    );
297}