flare_core/common/platform/
env.rs1use crate::common::device::{DeviceInfo, DevicePlatform};
4
5#[cfg(not(target_arch = "wasm32"))]
7pub fn runtime_instance_id() -> String {
8 format!("native-{}", std::process::id())
9}
10
11#[cfg(target_arch = "wasm32")]
12pub fn runtime_instance_id() -> String {
13 format!("wasm-{:016x}", rand::random::<u64>())
14}
15
16#[cfg(not(target_arch = "wasm32"))]
18pub fn optional_env(key: &str) -> Option<String> {
19 std::env::var(key).ok()
20}
21
22#[cfg(target_arch = "wasm32")]
23pub fn optional_env(_key: &str) -> Option<String> {
24 None
25}
26
27pub fn default_local_ws_url() -> &'static str {
29 "ws://127.0.0.1:8080"
30}
31
32pub fn web_device_info(user_id: &str) -> DeviceInfo {
34 let instance = runtime_instance_id();
35 DeviceInfo::new(format!("web-{instance}"), DevicePlatform::Web)
36 .with_model("Browser".to_string())
37 .with_app_version(env!("CARGO_PKG_VERSION").to_string())
38 .with_system_version(format!("flare-core wasm ({user_id})"))
39}