@@ -11,6 +11,7 @@ use crate::sys::inner::ffi::{
11
11
HID_DEVICE_PROPERTY_PRODUCT , IOHIDEventFieldBase , IOHIDEventGetFloatValue ,
12
12
IOHIDEventSystemClientCreate , IOHIDEventSystemClientSetMatching , IOHIDServiceClientCopyEvent ,
13
13
kHIDPage_AppleVendor, kHIDUsage_AppleVendor_TemperatureSensor, kIOHIDEventTypeTemperature,
14
+ kIOHIDSerialNumberKey,
14
15
} ;
15
16
16
17
pub ( crate ) struct ComponentsInner {
@@ -89,11 +90,17 @@ impl ComponentsInner {
89
90
let services = CFRetained :: cast_unchecked :: < CFArray < IOHIDServiceClient > > ( services) ;
90
91
91
92
let key = CFString :: from_static_str ( HID_DEVICE_PROPERTY_PRODUCT ) ;
93
+ let serial_key = CFString :: from_static_str ( kIOHIDSerialNumberKey) ;
92
94
93
95
for service in services {
94
96
let Some ( name) = service. property ( & key) else {
95
97
continue ;
96
98
} ;
99
+ let serial = service
100
+ . property ( & serial_key)
101
+ . and_then ( |value| value. downcast :: < CFString > ( ) . ok ( ) )
102
+ . as_deref ( )
103
+ . map ( CFString :: to_string) ;
97
104
let name = name. downcast :: < CFString > ( ) . unwrap ( ) ;
98
105
let name_str = name. to_string ( ) ;
99
106
@@ -107,7 +114,7 @@ impl ComponentsInner {
107
114
continue ;
108
115
}
109
116
110
- let mut component = ComponentInner :: new ( name_str, None , None , service) ;
117
+ let mut component = ComponentInner :: new ( serial , name_str, None , None , service) ;
111
118
component. refresh ( ) ;
112
119
113
120
self . components . push ( Component { inner : component } ) ;
@@ -117,6 +124,7 @@ impl ComponentsInner {
117
124
}
118
125
119
126
pub ( crate ) struct ComponentInner {
127
+ id : Option < String > ,
120
128
service : CFRetained < IOHIDServiceClient > ,
121
129
temperature : Option < f32 > ,
122
130
label : String ,
@@ -132,12 +140,14 @@ unsafe impl Sync for ComponentInner {}
132
140
133
141
impl ComponentInner {
134
142
pub ( crate ) fn new (
143
+ id : Option < String > ,
135
144
label : String ,
136
145
max : Option < f32 > ,
137
146
critical : Option < f32 > ,
138
147
service : CFRetained < IOHIDServiceClient > ,
139
148
) -> Self {
140
149
Self {
150
+ id,
141
151
service,
142
152
label,
143
153
max : max. unwrap_or ( 0. ) ,
@@ -164,7 +174,7 @@ impl ComponentInner {
164
174
}
165
175
166
176
pub ( crate ) fn id ( & self ) -> Option < & str > {
167
- None
177
+ self . id . as_deref ( )
168
178
}
169
179
170
180
pub ( crate ) fn refresh ( & mut self ) {
0 commit comments