Files
proxy-suite-flake/windows/crates/ps-gui/src/ui/overview.rs
T
faumarayandClaude Opus 5.5 d3ba00087d windows: the app's skeleton: the service from GPUI, an overview
- bridge: ps-client on a tokio runtime of its own, awaited from GPUI's
  executor; log following as a channel that reconnects.
- model: status polled every 2 s (outbounds every fifth round and on a
  reconnect), the zapret presets and tg links on connecting, and changes
  sent through ps-client's edits; what came of each is a notification,
  the service's own words when it refuses or cannot apply.
- The window: a sidebar of pages; the overview shows the local proxy, the
  DPI bypass and the Telegram proxy with their states and switches, and
  what the service warns of. The other pages come next.
- Icons: the components' own and the few the app adds, not all of Lucide.
- zapret's engines by upstream's names (zapret-discord-youtube, zapret2).
- gui-shot.sh can click before the shot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:25:11 +03:00

123 lines
4.6 KiB
Rust

//! The overview: the local proxy, the DPI bypass and the Telegram proxy, each with its state
//! and a switch; what the service warns of.
use gpui_kit::component::alert::Alert;
use gpui_kit::component::switch::Switch;
use gpui_kit::component::*;
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
use ps_client::edits;
use serde_json::Value;
use super::AppView;
use super::widgets::{card, fact, page, state_tag};
use crate::model::{Connection, Model};
fn text(v: &Value) -> SharedString {
match v {
Value::String(s) => s.clone().into(),
Value::Null => "—".into(),
other => other.to_string().into(),
}
}
pub fn render(model: &Entity<Model>, _: &mut Window, cx: &mut Context<AppView>) -> Div {
let m = model.read(cx);
let s = m.status().clone();
let connection = m.connection().clone();
let mut body = page("Overview", cx);
match &connection {
Connection::Down(why) => {
body = body.child(Alert::error("service-down", format!("The Proxy Suite service cannot be reached: {why}")).title("Not connected"));
}
Connection::Connecting => body = body.child(Alert::info("connecting", "Connecting to the Proxy Suite service…")),
Connection::Up => {}
}
if connection != Connection::Up {
return body;
}
if let Some(e) = s["error"].as_str() {
body = body.child(Alert::error("service-error", e.to_owned()).title("The configuration did not apply"));
}
for (i, w) in s["warnings"].as_array().into_iter().flatten().enumerate() {
body = body.child(Alert::warning(("warning", i), text(w)));
}
let p = &s["proxy"];
let proxy_on = p["on"] == true;
let model_p = model.clone();
let proxy = card(
"Local proxy",
Some(
Switch::new("proxy-on")
.checked(proxy_on)
.on_change(move |on, _, cx| model_p.update(cx, |m, cx| m.set_proxy(*on, cx)))
.into_any_element(),
),
cx,
)
.child(div().h_flex().gap_2().child(state_tag(p["state"].as_str().unwrap_or("unknown"))).when(p["tun"] == true, |d| d.child(tag::Tag::info().child("global TUN"))))
.child(fact("Listening on", text(&p["listener"]), cx))
.child(fact("Backend", text(&p["backend"]), cx))
.child(fact("Mode", p["mode"].as_str().unwrap_or("default").to_owned(), cx))
.child(fact("Outbound", p["pinned"].as_str().map(|t| format!("{t} (pinned)")).unwrap_or_else(|| format!("{} selection", p["selection"].as_str().unwrap_or("?"))), cx));
let z = &s["zapret"];
let model_z = model.clone();
let dpi = card(
"DPI bypass",
Some(
Switch::new("zapret-on")
.checked(z["enabled"] == true)
.on_change(move |on, _, cx| {
let on = *on;
model_z.update(cx, |m, cx| {
m.edit(
if on { "The DPI bypass is on" } else { "The DPI bypass is off" },
move |c| {
edits::set_zapret_enabled(c, on);
Ok(())
},
cx,
)
})
})
.into_any_element(),
),
cx,
)
.child(div().h_flex().child(state_tag(z["state"].as_str().unwrap_or("unknown"))))
.child(fact("Engine", text(&z["engine"]), cx))
.when(z["engine"] == "zapret-discord-youtube", |d| d.child(fact("Preset", text(&z["preset"]), cx)));
let t = &s["tgWsProxy"];
let model_t = model.clone();
let telegram = card(
"Telegram proxy",
Some(
Switch::new("tg-on")
.checked(t["enabled"] == true)
.on_change(move |on, _, cx| {
let on = *on;
model_t.update(cx, |m, cx| {
m.edit(
if on { "The Telegram proxy is on" } else { "The Telegram proxy is off" },
move |c| {
edits::set_tg_ws_proxy_enabled(c, on);
Ok(())
},
cx,
)
})
})
.into_any_element(),
),
cx,
)
.child(div().h_flex().child(state_tag(t["state"].as_str().unwrap_or("unknown"))))
.child(fact("Listening on", text(&t["listener"]), cx));
body.child(proxy).child(div().h_flex().gap_4().items_start().child(dpi.flex_1()).child(telegram.flex_1()))
}