File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed 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/).
16
16
* Added ` NSRange ` methods ` new ` , ` is_empty ` , ` contains ` and ` end ` .
17
17
* Added ` NSThread ` object.
18
18
* Added ` is_multi_threaded ` and ` is_main_thread ` helper functions.
19
+ * Added ` NSProcessInfo ` object.
19
20
20
21
### Changed
21
22
* ** 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};
28
28
pub use self :: dictionary:: NSDictionary ;
29
29
pub use self :: enumerator:: { NSEnumerator , NSFastEnumeration , NSFastEnumerator } ;
30
30
pub use self :: object:: NSObject ;
31
+ pub use self :: process_info:: NSProcessInfo ;
31
32
pub use self :: range:: NSRange ;
32
33
pub use self :: string:: NSString ;
33
34
pub use self :: thread:: { is_main_thread, is_multi_threaded, NSThread } ;
@@ -51,6 +52,7 @@ mod data;
51
52
mod dictionary;
52
53
mod enumerator;
53
54
mod object;
55
+ mod process_info;
54
56
mod range;
55
57
mod string;
56
58
mod 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