Skip to content

Commit 565aeac

Browse files
committed
🐛 fix translations * pingfall flags
1 parent a7bb00d commit 565aeac

6 files changed

Lines changed: 38 additions & 29 deletions

File tree

crates/desktop/src/daemon/api_controller.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ use wsrx::utils::create_tcp_listener;
2121
use super::latency_worker::update_instance_latency;
2222
use crate::{
2323
bridges::ui_state::sync_scoped_instance,
24-
daemon::model::{FeatureFlags, InstanceData, ProxyInstance, ScopeData, ServerState},
24+
daemon::{
25+
latency_worker::update_instance_state,
26+
model::{FeatureFlags, InstanceData, ProxyInstance, ScopeData, ServerState},
27+
},
2528
ui::{Instance, InstanceBridge, Scope, ScopeBridge},
2629
};
2730

@@ -199,9 +202,10 @@ async fn launch_instance(
199202

200203
tokio::spawn(async move {
201204
let client = reqwest::Client::new();
202-
update_instance_latency(state_clone, instance, &client)
203-
.await
204-
.ok();
205+
match update_instance_latency(&instance, &client).await {
206+
Ok(elapsed) => update_instance_state(state_clone, &instance, elapsed).await,
207+
Err(_) => update_instance_state(state_clone, &instance, -1).await,
208+
};
205209
});
206210

207211
match slint::invoke_from_event_loop(move || {

crates/desktop/src/daemon/latency_worker.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ pub async fn start(state: ServerState) {
2626
let client = client.clone();
2727
let state = state.clone();
2828
tokio::spawn(async move {
29-
let result =
30-
update_instance_latency(state.clone(), instance.clone(), &client).await;
29+
let result = update_instance_latency(&instance, &client).await;
30+
if let Ok(elapsed) = result {
31+
update_instance_state(state.clone(), &instance, elapsed).await;
32+
} else {
33+
update_instance_state(state.clone(), &instance, -1).await;
34+
}
3135
if let Err(e) = result {
3236
pingfall(state.clone(), instance.clone(), e).await;
3337
}
@@ -49,7 +53,7 @@ pub enum LatencyError {
4953
}
5054

5155
pub async fn update_instance_latency(
52-
state: ServerState, instance: InstanceData, client: &reqwest::Client,
56+
instance: &InstanceData, client: &reqwest::Client,
5357
) -> Result<i32, LatencyError> {
5458
let req = client
5559
.request(Method::OPTIONS, instance.remote.replace("ws", "http"))
@@ -68,13 +72,18 @@ pub async fn update_instance_latency(
6872
return Err(LatencyError::NonSuccessStatus(resp.status().as_u16()));
6973
};
7074

75+
Ok(elapsed)
76+
}
77+
78+
pub async fn update_instance_state(state: ServerState, instance: &InstanceData, elapsed: i32) {
7179
for proxy_instance in state.instances.write().await.iter_mut() {
7280
if instance.remote != proxy_instance.remote {
7381
continue;
7482
}
7583

7684
proxy_instance.latency = elapsed;
7785
let window = state.ui.clone();
86+
let instance = instance.clone();
7887

7988
let _ = slint::invoke_from_event_loop(move || {
8089
let window = window.upgrade().unwrap();
@@ -104,21 +113,23 @@ pub async fn update_instance_latency(
104113

105114
break;
106115
}
107-
108-
Ok(elapsed)
109116
}
110117

111118
async fn pingfall(state: ServerState, instance: InstanceData, err: LatencyError) {
119+
warn!(
120+
"Pingfall triggered for instance {} due to error: {err:?}",
121+
instance.local
122+
);
112123
let scopes = state.scopes.read().await;
113124

114125
let scope = scopes
115126
.iter()
116127
.find(|scope| scope.host == instance.scope_host.as_str());
117-
128+
debug!("Pingfall settings: {:?}", scope);
118129
if let Some(scope) = scope
119130
&& scope.features.contains(FeatureFlags::PingFall)
120131
{
121-
let settings = scope.settings.get(&FeatureFlags::PingFall);
132+
let settings = scope.settings.get("pingfall");
122133
if let Some(settings) = settings {
123134
let pingfall_settings: super::model::PingFallSettings =
124135
serde_json::from_value(settings.to_owned()).unwrap_or_default();
@@ -128,19 +139,11 @@ async fn pingfall(state: ServerState, instance: InstanceData, err: LatencyError)
128139
if pingfall_settings.fail_status.contains(&code)
129140
|| pingfall_settings.fail_status.is_empty()
130141
{
131-
warn!(
132-
"PingFall triggered for instance {} due to status code {}",
133-
instance.local, code
134-
);
135142
on_instance_del(&state, &instance.local).await;
136143
}
137144
}
138145
LatencyError::Rewqest(_) => {
139146
if pingfall_settings.drop_unknown {
140-
warn!(
141-
"PingFall triggered for instance {} due to request error",
142-
instance.local
143-
);
144147
on_instance_del(&state, &instance.local).await;
145148
}
146149
}

crates/desktop/src/daemon/model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct ScopeData {
3030
pub state: String,
3131
pub features: FeatureFlags,
3232
#[serde(default)]
33-
pub settings: HashMap<FeatureFlags, Value>,
33+
pub settings: HashMap<String, Value>,
3434
}
3535

3636
#[derive(Clone)]

crates/desktop/src/daemon/ui_controller.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
bridges::ui_state::sync_scoped_instance,
88
daemon::{
99
default_label,
10+
latency_worker::update_instance_state,
1011
model::{ProxyInstance, ServerState},
1112
},
1213
ui::{Instance, InstanceBridge, MainWindow, Scope, ScopeBridge},
@@ -44,9 +45,10 @@ pub async fn on_instance_add(state: &ServerState, remote: &str, local: &str) {
4445

4546
tokio::spawn(async move {
4647
let client = reqwest::Client::new();
47-
update_instance_latency(state_clone, instance_data, &client)
48-
.await
49-
.ok();
48+
match update_instance_latency(&instance_data, &client).await {
49+
Ok(elapsed) => update_instance_state(state_clone, &instance_data, elapsed).await,
50+
Err(_) => update_instance_state(state_clone, &instance_data, -1).await,
51+
};
5052
});
5153

5254
let label = instance.label.clone();

crates/desktop/ui/i18n/zh_CN/LC_MESSAGES/wsrx-desktop.po

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ msgstr "外部控制"
7171
#: crates/desktop/ui/pages/connections.slint:90
7272
msgctxt "ConnectionsPage"
7373
msgid "This scope is controlled by you manually."
74-
msgstr "此连接池由你手动控制。"
74+
msgstr "这个连接池由你手动控制。"
7575

7676
#: crates/desktop/ui/pages/connections.slint:90
7777
msgctxt "ConnectionsPage"
7878
msgid "This domain can control wsrx on your local network."
79-
msgstr "此域名可以控制你本地网络上的 wsrx。"
79+
msgstr "这个域名可以控制你本地网络上的 wsrx。"
8080

8181
#: crates/desktop/ui/pages/connections.slint:90
8282
msgctxt "ConnectionsPage"
8383
msgid "This domain requested controlling wsrx."
84-
msgstr "此域名请求控制 wsrx。"
84+
msgstr "这个域名请求控制 wsrx。"
8585

8686
#: crates/desktop/ui/pages/connections.slint:99
8787
msgctxt "ConnectionsPage"

crates/desktop/ui/i18n/zh_TW/LC_MESSAGES/wsrx-desktop.po

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ msgstr "外部控制"
7171
#: crates/desktop/ui/pages/connections.slint:90
7272
msgctxt "ConnectionsPage"
7373
msgid "This scope is controlled by you manually."
74-
msgstr "此連接池由你手動控制。"
74+
msgstr "这个連接池由你手動控制。"
7575

7676
#: crates/desktop/ui/pages/connections.slint:90
7777
msgctxt "ConnectionsPage"
7878
msgid "This domain can control wsrx on your local network."
79-
msgstr "此域名可以控制你本地網絡上的 wsrx。"
79+
msgstr "这个域名可以控制你本地網絡上的 wsrx。"
8080

8181
#: crates/desktop/ui/pages/connections.slint:90
8282
msgctxt "ConnectionsPage"
8383
msgid "This domain requested controlling wsrx."
84-
msgstr "此域名請求控制 wsrx。"
84+
msgstr "这个域名請求控制 wsrx。"
8585

8686
#: crates/desktop/ui/pages/connections.slint:99
8787
msgctxt "ConnectionsPage"

0 commit comments

Comments
 (0)