File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1616* Added ` NSRange ` methods ` new ` , ` is_empty ` , ` contains ` and ` end ` .
1717* Added ` NSThread ` object.
1818* Added ` is_multi_threaded ` and ` is_main_thread ` helper functions.
19+ * Added ` NSProcessInfo ` object.
1920
2021### Changed
2122* ** BREAKING** : Removed the following helper traits in favor of inherent
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ pub use self::data::{NSData, NSMutableData};
2828pub use self :: dictionary:: NSDictionary ;
2929pub use self :: enumerator:: { NSEnumerator , NSFastEnumeration , NSFastEnumerator } ;
3030pub use self :: object:: NSObject ;
31+ pub use self :: process_info:: NSProcessInfo ;
3132pub use self :: range:: NSRange ;
3233pub use self :: string:: NSString ;
3334pub use self :: thread:: { is_main_thread, is_multi_threaded, NSThread } ;
@@ -51,6 +52,7 @@ mod data;
5152mod dictionary;
5253mod enumerator;
5354mod object;
55+ mod process_info;
5456mod range;
5557mod string;
5658mod thread;
Original file line number Diff line number Diff line change 1+ use core:: ptr:: NonNull ;
2+
3+ use objc2:: msg_send;
4+ use objc2:: rc:: { Id , Shared } ;
5+
6+ use crate :: { NSObject , NSString } ;
7+
8+ object ! {
9+ /// A collection of information about the current process.
10+ ///
11+ /// See [Apple's documentation](https://developer.apple.com/documentation/foundation/nsprocessinfo?language=objc).
12+ unsafe pub struct NSProcessInfo : NSObject ;
13+
14+ // TODO: This contains a lot more important functionality!
15+ }
16+
17+ // The documentation explicitly states:
18+ // > NSProcessInfo is thread-safe in macOS 10.7 and later.
19+ unsafe impl Send for NSProcessInfo { }
20+ unsafe impl Sync for NSProcessInfo { }
21+
22+ impl NSProcessInfo {
23+ pub fn process_info ( ) -> Id < NSProcessInfo , Shared > {
24+ // currentThread is @property(strong), what does that mean?
25+ let obj: * mut Self = unsafe { msg_send ! [ Self :: class( ) , processInfo] } ;
26+ let obj = unsafe { NonNull :: new_unchecked ( obj) } ;
27+ unsafe { Id :: retain ( obj) }
28+ }
29+
30+ pub fn process_name ( & self ) -> Id < NSString , Shared > {
31+ let obj: * mut NSString = unsafe { msg_send ! [ Self :: class( ) , processName] } ;
32+ let obj = NonNull :: new ( obj) . unwrap ( ) ;
33+ unsafe { Id :: retain ( obj) }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments