File size: 660 Bytes
d90101d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::path::PathBuf;

use uuid::Uuid;

const CLIENT_ID_FILE: &str = ".forge_client_id";

/// Gets or creates a persistent client ID for Android
pub fn get_or_create_client_id() -> anyhow::Result<String> {
    let home_dir = dirs::home_dir().unwrap_or(PathBuf::from("."));

    let client_id_path: PathBuf = home_dir.join(CLIENT_ID_FILE);

    if let Ok(existing_id) = std::fs::read_to_string(&client_id_path) {
        let trimmed = existing_id.trim();
        if !trimmed.is_empty() {
            return Ok(trimmed.to_string());
        }
    }

    let new_id = Uuid::new_v4().to_string();
    std::fs::write(&client_id_path, &new_id)?;

    Ok(new_id)
}