Skip to content

Commit 90a52c7

Browse files
committed
added device_id
1 parent 77cdbbc commit 90a52c7

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Cargo.lock

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phichain-editor/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@ uuid = { version = "1.13.1", features = ["v4"] }
9999
bevy_mod_reqwest = "0.18.0"
100100
os_info = "3.10.0"
101101
sysinfo = "0.33.1"
102+
machine-uid = "0.5.3"
103+
sha2 = "0.10"

phichain-editor/src/telemetry.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use bevy::time::common_conditions::on_timer;
1010
use bevy_mod_reqwest::{BevyReqwest, ReqwestErrorEvent, ReqwestResponseEvent};
1111
use bevy_persistent::Persistent;
1212
use serde_json::{json, Value};
13+
use sha2::{Digest, Sha256};
1314
use std::path::Path;
1415
use std::time::Duration;
1516
use std::{env, process};
@@ -20,16 +21,26 @@ const TELEMETRY_URL: &str = "https://telemetry.phichain.rs/report";
2021
const TELEMETRY_REPORT_TIMEOUT: Duration = Duration::from_secs(15);
2122
const TELEMETRY_REPORT_INTERVAL: Duration = Duration::from_secs(60);
2223

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+
2332
#[derive(Debug, Clone, Resource)]
2433
pub struct TelemetryManager {
2534
uuid: Uuid,
35+
device_id: String,
2636
queue: Vec<Value>,
2737
}
2838

2939
impl TelemetryManager {
3040
pub fn new() -> Self {
3141
Self {
3242
uuid: Uuid::new_v4(),
43+
device_id: get_device_id(),
3344
queue: vec![],
3445
}
3546
}
@@ -157,7 +168,8 @@ fn handle_push_telemetry_event_system(
157168
let payload = json!({
158169
"timestamp": chrono::Utc::now().to_rfc3339(),
159170
"reporter": "phichain-editor",
160-
"uuid": telemetry_manager.uuid,
171+
"session_id": telemetry_manager.uuid,
172+
"device_id": telemetry_manager.device_id,
161173
"type": event.event_type,
162174
"system": {
163175
"arch": env::consts::ARCH,

0 commit comments

Comments
 (0)