@@ -10,6 +10,7 @@ use bevy::time::common_conditions::on_timer;
10
10
use bevy_mod_reqwest:: { BevyReqwest , ReqwestErrorEvent , ReqwestResponseEvent } ;
11
11
use bevy_persistent:: Persistent ;
12
12
use serde_json:: { json, Value } ;
13
+ use sha2:: { Digest , Sha256 } ;
13
14
use std:: path:: Path ;
14
15
use std:: time:: Duration ;
15
16
use std:: { env, process} ;
@@ -20,16 +21,26 @@ const TELEMETRY_URL: &str = "https://telemetry.phichain.rs/report";
20
21
const TELEMETRY_REPORT_TIMEOUT : Duration = Duration :: from_secs ( 15 ) ;
21
22
const TELEMETRY_REPORT_INTERVAL : Duration = Duration :: from_secs ( 60 ) ;
22
23
24
+ fn get_device_id ( ) -> String {
25
+ let machine_id = machine_uid:: get ( ) . unwrap_or_else ( |_| Uuid :: new_v4 ( ) . to_string ( ) ) ;
26
+ let mut hasher = Sha256 :: new ( ) ;
27
+ hasher. update ( machine_id. as_bytes ( ) ) ;
28
+ let hash_result = hasher. finalize ( ) ;
29
+ format ! ( "{:x}" , hash_result)
30
+ }
31
+
23
32
#[ derive( Debug , Clone , Resource ) ]
24
33
pub struct TelemetryManager {
25
34
uuid : Uuid ,
35
+ device_id : String ,
26
36
queue : Vec < Value > ,
27
37
}
28
38
29
39
impl TelemetryManager {
30
40
pub fn new ( ) -> Self {
31
41
Self {
32
42
uuid : Uuid :: new_v4 ( ) ,
43
+ device_id : get_device_id ( ) ,
33
44
queue : vec ! [ ] ,
34
45
}
35
46
}
@@ -157,7 +168,8 @@ fn handle_push_telemetry_event_system(
157
168
let payload = json ! ( {
158
169
"timestamp" : chrono:: Utc :: now( ) . to_rfc3339( ) ,
159
170
"reporter" : "phichain-editor" ,
160
- "uuid" : telemetry_manager. uuid,
171
+ "session_id" : telemetry_manager. uuid,
172
+ "device_id" : telemetry_manager. device_id,
161
173
"type" : event. event_type,
162
174
"system" : {
163
175
"arch" : env:: consts:: ARCH ,
0 commit comments