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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct ClientData {
pub local_client_id: String,
pub recent_clients: HashMap<String, RemoteClient>,
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct RemoteClient {
pub fxa_device_id: Option<String>,
pub device_name: String,
pub device_type: Option<DeviceType>,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum DeviceType {
Desktop,
Mobile,
Tablet,
VR,
TV,
}
impl DeviceType {
pub fn try_from_str(d: impl AsRef<str>) -> Option<DeviceType> {
match d.as_ref() {
"desktop" => Some(DeviceType::Desktop),
"mobile" => Some(DeviceType::Mobile),
"tablet" => Some(DeviceType::Tablet),
"vr" => Some(DeviceType::VR),
"tv" => Some(DeviceType::TV),
_ => None,
}
}
pub fn as_str(self) -> &'static str {
match self {
DeviceType::Desktop => "desktop",
DeviceType::Mobile => "mobile",
DeviceType::Tablet => "tablet",
DeviceType::VR => "vr",
DeviceType::TV => "tv",
}
}
}