Skip to content

Commit 2f67a6b

Browse files
committed
切换为 HiPer 而不是 HiPer Plus
运行状态会隐藏凭证框了 可以从设置页面里打开 HiPer 安装目录了 新增调试模式,在 HiPer 运行时将显示控制台方便实时观察日志 修正了部分布局
1 parent 75381f3 commit 2f67a6b

File tree

8 files changed

+268
-172
lines changed

8 files changed

+268
-172
lines changed

Cargo.lock

Lines changed: 11 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ scl-gui-widgets = { path = "../SharpCraftLauncher/scl-gui-widgets" }
1111
anyhow = "1.0"
1212
clipboard = "0.5"
1313
druid = { git = "https://github.com/Steve-xmh/druid.git", features = ["im"] }
14-
nom = "^7.1"
1514
oneshot = "0.1.3"
15+
sha1_smol = { version = "1", features = ["std"] }
1616
path-absolutize = "3.0"
17-
serde = "1.0"
18-
serde_json = "1.0"
17+
tinyjson = "2"
1918
tinyget = { version = "1.0", features = ["https"] }
2019

2120
[target.'cfg(target_os = "windows")'.dependencies.winapi]

src/app_state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub struct AppState {
4343
pub warning: String,
4444
pub use_tun: bool,
4545
pub auto_restart: bool,
46+
pub debug_mode: bool,
4647
}
4748

4849
impl Default for AppState {
@@ -59,6 +60,7 @@ impl Default for AppState {
5960
run_time: 0,
6061
use_tun: true,
6162
auto_restart: true,
63+
debug_mode: false,
6264
}
6365
}
6466
}

src/config.rs

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
use serde::*;
2-
use std::path::PathBuf;
3-
41
use crate::{app_state::AppState, hiper::get_hiper_dir, DynResult};
5-
6-
#[derive(Clone, Deserialize, Serialize)]
7-
struct Config {
8-
pub auto_restart: bool,
9-
pub use_tun: bool,
10-
pub token: String,
11-
}
2+
use std::{collections::HashMap, io::Write, path::PathBuf};
3+
use tinyjson::*;
124

135
pub fn get_save_path() -> DynResult<PathBuf> {
146
let hiper_path = get_hiper_dir()?;
@@ -17,33 +9,67 @@ pub fn get_save_path() -> DynResult<PathBuf> {
179

1810
pub fn save_config(app_state: &AppState) {
1911
if let Ok(save_path) = get_save_path() {
20-
let config = Config {
21-
auto_restart: app_state.auto_restart,
22-
use_tun: app_state.use_tun,
23-
token: app_state.inner_token.to_owned(),
24-
};
25-
if let Ok(file) = std::fs::OpenOptions::new()
12+
if let Ok(mut file) = std::fs::OpenOptions::new()
2613
.write(true)
2714
.create(true)
2815
.truncate(true)
2916
.open(save_path)
3017
{
31-
let _ = serde_json::to_writer(file, &config);
18+
let mut data_hashmap = HashMap::with_capacity(16);
19+
20+
data_hashmap.insert(
21+
"token".into(),
22+
JsonValue::String(app_state.inner_token.to_owned()),
23+
);
24+
data_hashmap.insert("use_tun".into(), JsonValue::Boolean(app_state.use_tun));
25+
data_hashmap.insert(
26+
"auto_restart".into(),
27+
JsonValue::Boolean(app_state.auto_restart),
28+
);
29+
data_hashmap.insert(
30+
"debug_mode".into(),
31+
JsonValue::Boolean(app_state.debug_mode),
32+
);
33+
34+
let data = JsonValue::Object(data_hashmap);
35+
36+
if let Ok(data) = data.stringify() {
37+
let _ = file.write_all(data.as_bytes());
38+
let _ = file.sync_all();
39+
}
3240
}
3341
}
3442
}
3543

3644
pub fn load_config(app_state: &mut AppState) {
3745
if let Ok(save_path) = get_save_path() {
3846
if save_path.exists() {
39-
if let Ok(file) = std::fs::read(save_path) {
40-
if let Ok(data) = serde_json::from_slice::<Config>(&file) {
41-
if !data.token.is_empty() {
42-
app_state.inner_token = data.token;
43-
app_state.token = "••••••••".into();
47+
if let Ok(file) = std::fs::read_to_string(save_path) {
48+
if let Ok(JsonValue::Object(data)) = file.parse::<JsonValue>() {
49+
if let Some(Some(token)) = data.get("token").map(|x| x.get::<String>()) {
50+
if !token.is_empty() {
51+
app_state.inner_token = token.to_owned();
52+
app_state.token = "••••••••".into();
53+
}
54+
}
55+
if let Some(use_tun) = data
56+
.get("use_tun")
57+
.map(|x| x.get::<bool>().copied().unwrap_or(false))
58+
{
59+
app_state.use_tun = use_tun;
60+
}
61+
if let Some(auto_restart) = data
62+
.get("auto_restart")
63+
.map(|x| x.get::<bool>().copied().unwrap_or(false))
64+
{
65+
app_state.auto_restart = auto_restart;
66+
}
67+
if let Some(debug_mode) = data
68+
.get("debug_mode")
69+
.map(|x| x.get::<bool>().copied().unwrap_or(false))
70+
{
71+
app_state.debug_mode = debug_mode;
4472
}
45-
app_state.use_tun = data.use_tun;
46-
app_state.auto_restart = data.auto_restart;
4773
}
4874
}
4975
}

0 commit comments

Comments
 (0)