Skip to content

Commit 8ff7f28

Browse files
committed
moving to strongly typed configs
1 parent dfd325b commit 8ff7f28

File tree

6 files changed

+75
-73
lines changed

6 files changed

+75
-73
lines changed

common/src/cfg.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use crate::read_json;
2+
use anyhow::Result;
3+
use serde::{Deserialize, Serialize};
4+
use serde_json::from_value;
5+
6+
#[derive(Serialize, Deserialize)]
7+
pub struct ServerConfig {
8+
pub adaptive: bool,
9+
#[serde(rename = "enableServer")]
10+
pub enable_server: bool,
11+
#[serde(rename = "forceUpdateExcel")]
12+
pub force_update_excel: bool,
13+
pub gadget: bool,
14+
pub host: String,
15+
#[serde(rename = "maintenanceMsg")]
16+
pub maintenance_msg: String,
17+
pub mode: String,
18+
#[serde(rename = "noProxy")]
19+
pub no_proxy: bool,
20+
pub port: i64,
21+
#[serde(rename = "useSu")]
22+
pub use_su: bool,
23+
}
24+
25+
impl ServerConfig {
26+
pub fn load() -> Result<Self> {
27+
let value = read_json("./config/server.json")["server"].clone();
28+
Ok(from_value(value)?)
29+
}
30+
}
31+
32+
#[derive(Serialize, Deserialize)]
33+
pub struct RestorePrevState {
34+
is2: bool,
35+
#[serde(rename = "squadsAndFavs")]
36+
sq_n_fav: bool,
37+
ui: bool,
38+
}
39+
40+
#[derive(Serialize, Deserialize)]
41+
pub struct UserConfig {
42+
#[serde(rename = "activityMaxStartTs")]
43+
pub act_max_start_ts: i64,
44+
#[serde(rename = "activityMinStartTs")]
45+
pub act_min_start_ts: i64,
46+
pub background: String,
47+
#[serde(rename = "fakeTime")]
48+
pub fake_time: i64,
49+
#[serde(rename = "forceEnableBattleReplay")]
50+
pub force_battle_replay: bool,
51+
#[serde(rename = "nickName")]
52+
pub name: String,
53+
#[serde(rename = "nickNumber")]
54+
pub number: String,
55+
#[serde(rename = "restorePreviousStates")]
56+
pub restore_prev_state: RestorePrevState,
57+
pub secretary: String,
58+
#[serde(rename = "secretarySkinId")]
59+
pub secretary_skin: String,
60+
pub theme: String,
61+
pub vision: bool,
62+
}
63+
64+
impl UserConfig {
65+
pub fn load() -> Result<Self> {
66+
let value = read_json("./config/server.json")["userConfig"].clone();
67+
Ok(from_value(value)?)
68+
}
69+
}

common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
mod cfg;
12
mod fs;
23
mod json;
34

45
pub use self::{
6+
cfg::{RestorePrevState, ServerConfig, UserConfig},
57
fs::mkfile,
68
json::{read_json, write_json},
79
};

launcher/src/config.rs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1 @@
1-
use anyhow::Result;
2-
use common_utils::read_json;
3-
use serde::{Deserialize, Serialize};
4-
use serde_json::from_value;
51

6-
#[derive(Serialize, Deserialize)]
7-
pub struct ServerConfig {
8-
pub adaptive: bool,
9-
#[serde(rename = "enableServer")]
10-
pub enable_server: bool,
11-
#[serde(rename = "forceUpdateExcel")]
12-
pub force_update_excel: bool,
13-
pub gadget: bool,
14-
pub host: String,
15-
#[serde(rename = "maintenanceMsg")]
16-
pub maintenance_msg: String,
17-
pub mode: String,
18-
#[serde(rename = "noProxy")]
19-
pub no_proxy: bool,
20-
pub port: i64,
21-
#[serde(rename = "useSu")]
22-
pub use_su: bool,
23-
}
24-
25-
impl ServerConfig {
26-
pub fn load() -> Result<Self> {
27-
let value = read_json("./config/server.json")["server"].clone();
28-
Ok(from_value(value)?)
29-
}
30-
}
31-
32-
#[derive(Serialize, Deserialize)]
33-
pub struct RestorePrevState {
34-
is2: bool,
35-
#[serde(rename = "squadsAndFavs")]
36-
sq_n_fav: bool,
37-
ui: bool,
38-
}
39-
40-
#[derive(Serialize, Deserialize)]
41-
pub struct UserConfig {
42-
#[serde(rename = "activityMaxStartTs")]
43-
pub act_max_start_ts: i64,
44-
#[serde(rename = "activityMinStartTs")]
45-
pub act_min_start_ts: i64,
46-
pub background: String,
47-
#[serde(rename = "fakeTime")]
48-
pub fake_time: i64,
49-
#[serde(rename = "forceEnableBattleReplay")]
50-
pub force_battle_replay: bool,
51-
#[serde(rename = "nickName")]
52-
pub name: String,
53-
#[serde(rename = "nickNumber")]
54-
pub number: String,
55-
#[serde(rename = "restorePreviousStates")]
56-
pub restore_prev_state: RestorePrevState,
57-
pub secretary: String,
58-
#[serde(rename = "secretarySkinId")]
59-
pub secretary_skin: String,
60-
pub theme: String,
61-
pub vision: bool,
62-
}
63-
64-
impl UserConfig {
65-
pub fn load() -> Result<Self> {
66-
let value = read_json("./config/server.json")["userConfig"].clone();
67-
Ok(from_value(value)?)
68-
}
69-
}

launcher/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use adb::Os;
22
use anyhow::Result;
3-
use config::ServerConfig;
3+
use common_utils::ServerConfig;
44
use frida::{DeviceManager, Frida, ScriptOption, ScriptRuntime, Session, SpawnOptions};
55
use scripts::{get_script, get_vision};
66
use std::process::Command;

launcher/src/scripts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::config::{ServerConfig, UserConfig};
21
use anyhow::Result;
2+
use common_utils::{ServerConfig, UserConfig};
33
use std::{fs::File, io::Read};
44

55
pub fn get_script() -> Result<String> {

terraps/src/game/background.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use axum::Json;
2-
use serde_json::json;
3-
41
use crate::{
52
constants::{config::CONFIG_JSON_PATH, user::USER_JSON_PATH},
63
utils::json::JSON,
74
};
5+
use axum::Json;
86
use common_utils::{read_json, write_json};
7+
use serde_json::json;
98

109
pub async fn background_set_bg(Json(payload): JSON) -> JSON {
1110
let bg_id = payload["bgId"].clone();

0 commit comments

Comments
 (0)