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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate::utils::os::{Architecture, Platform};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Rule {
pub action: Action,
pub os: Option<Os>,
pub features: Option<Features>,
}
impl Rule {
pub fn allows(&self) -> bool {
if let Some(os) = &self.os {
if let Some(platform) = &os.platform {
if platform != &Platform::current() {
return !self.action.to_bool();
}
}
}
if let Some(features) = &self.features {
if features.is_demo_user.is_some() || features.has_custom_resolution.is_some() {
return false;
}
}
self.action.to_bool()
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum Action {
#[serde(alias = "allow")]
Allow,
#[serde(alias = "disallow")]
Disallow,
}
impl Action {
pub fn to_bool(&self) -> bool {
match self {
Action::Allow => true,
Action::Disallow => false,
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Os {
#[serde(alias = "name")]
pub platform: Option<Platform>,
pub version: Option<String>,
pub arch: Option<Architecture>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Features {
pub is_demo_user: Option<bool>,
pub has_custom_resolution: Option<bool>,
}