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>
This commit is contained in:
1 parent
63aede0dc1
commit
d3ba00087d
11 files changed
+654
-21
No files matched your search
@@ -0,0 +1,100 @@
|
||||
//! The window: a sidebar of pages, the page shown, and what came of each change as a
|
||||
//! notification.
|
||||
|
||||
mod overview;
|
||||
mod widgets;
|
||||
|
||||
use gpui_kit::component::notification::Notification;
|
||||
use gpui_kit::component::sidebar::{Sidebar, SidebarGroup, SidebarHeader, SidebarMenu, SidebarMenuItem};
|
||||
use gpui_kit::assets::IconName;
|
||||
use gpui_kit::component::*;
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::model::{Model, Outcome};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Page {
|
||||
Overview,
|
||||
Dpi,
|
||||
Telegram,
|
||||
Outbounds,
|
||||
Logs,
|
||||
Settings,
|
||||
Components,
|
||||
}
|
||||
|
||||
impl Page {
|
||||
const ALL: [Page; 7] = [Page::Overview, Page::Dpi, Page::Telegram, Page::Outbounds, Page::Logs, Page::Settings, Page::Components];
|
||||
|
||||
fn title(self) -> &'static str {
|
||||
match self {
|
||||
Page::Overview => "Overview",
|
||||
Page::Dpi => "DPI bypass",
|
||||
Page::Telegram => "Telegram proxy",
|
||||
Page::Outbounds => "Outbounds",
|
||||
Page::Logs => "Logs",
|
||||
Page::Settings => "Settings",
|
||||
Page::Components => "Components",
|
||||
}
|
||||
}
|
||||
|
||||
fn icon(self) -> IconName {
|
||||
match self {
|
||||
Page::Overview => IconName::LayoutDashboard,
|
||||
Page::Dpi => IconName::Shield,
|
||||
Page::Telegram => IconName::Send,
|
||||
Page::Outbounds => IconName::Globe,
|
||||
Page::Logs => IconName::SquareTerminal,
|
||||
Page::Settings => IconName::Settings,
|
||||
Page::Components => IconName::Package,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AppView {
|
||||
model: Entity<Model>,
|
||||
page: Page,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl AppView {
|
||||
pub fn new(model: Entity<Model>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let subscriptions = vec![
|
||||
cx.observe(&model, |_, _, cx| cx.notify()),
|
||||
cx.subscribe_in(&model, window, |_, _, outcome: &Outcome, window, cx| {
|
||||
let note = match outcome {
|
||||
Outcome::Done(m) => Notification::success(m.clone()),
|
||||
Outcome::Failed(m) => Notification::error(m.clone()).autohide(false),
|
||||
};
|
||||
window.push_notification(note, cx);
|
||||
}),
|
||||
];
|
||||
Self { model, page: Page::Overview, _subscriptions: subscriptions }
|
||||
}
|
||||
|
||||
fn sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let items = Page::ALL.map(|page| {
|
||||
SidebarMenuItem::new(page.title()).icon(page.icon()).active(self.page == page).on_click(cx.listener(move |this, _, _, cx| {
|
||||
this.page = page;
|
||||
cx.notify();
|
||||
}))
|
||||
});
|
||||
Sidebar::new("pages").header(SidebarHeader::new().child(widgets::brand(cx))).child(SidebarGroup::new("Proxy Suite").child(SidebarMenu::new().children(items)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for AppView {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let page = match self.page {
|
||||
Page::Overview => overview::render(&self.model, window, cx).into_any_element(),
|
||||
other => widgets::page(other.title(), cx).child(div().text_color(cx.theme().muted_foreground).child("Not here yet.")).into_any_element(),
|
||||
};
|
||||
div()
|
||||
.h_flex()
|
||||
.size_full()
|
||||
.bg(cx.theme().background)
|
||||
.text_color(cx.theme().foreground)
|
||||
.child(self.sidebar(cx))
|
||||
.child(div().id("page").flex_1().h_full().overflow_y_scroll().child(page))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
//! 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()))
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//! Pieces the pages share: the page frame, cards, a unit's state as a tag.
|
||||
|
||||
use gpui_kit::component::tag::Tag;
|
||||
use gpui_kit::assets::IconName;
|
||||
use gpui_kit::component::*;
|
||||
use gpui_kit::*;
|
||||
|
||||
pub fn brand(cx: &App) -> impl IntoElement {
|
||||
div().h_flex().gap_2().items_center().child(Icon::new(IconName::Shield).text_color(cx.theme().primary)).child(div().font_semibold().child("Proxy Suite"))
|
||||
}
|
||||
|
||||
/// A page: its title, then what is under it.
|
||||
pub fn page(title: &'static str, cx: &App) -> Div {
|
||||
div().v_flex().gap_4().p_6().w_full().max_w(px(920.)).child(div().text_xl().font_semibold().text_color(cx.theme().foreground).child(title))
|
||||
}
|
||||
|
||||
/// A bordered section of a page, titled, with what it controls on the right of the title.
|
||||
pub fn card(title: impl Into<SharedString>, action: Option<AnyElement>, cx: &App) -> Div {
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_3()
|
||||
.p_4()
|
||||
.rounded_lg()
|
||||
.border_1()
|
||||
.border_color(cx.theme().border)
|
||||
.bg(cx.theme().background)
|
||||
.child(div().h_flex().justify_between().items_center().child(div().font_semibold().child(title.into())).children(action))
|
||||
}
|
||||
|
||||
/// A unit's state, as the service says it, coloured by what it means.
|
||||
pub fn state_tag(state: &str) -> Tag {
|
||||
let tag = match state {
|
||||
"active" => Tag::success(),
|
||||
"activating" | "reloading" | "deactivating" => Tag::warning(),
|
||||
"failed" => Tag::danger(),
|
||||
_ => Tag::secondary(),
|
||||
};
|
||||
tag.child(state.to_owned())
|
||||
}
|
||||
|
||||
/// A label and its value, in a row.
|
||||
pub fn fact(label: &'static str, value: impl Into<SharedString>, cx: &App) -> Div {
|
||||
div().h_flex().gap_2().text_sm().child(div().w(px(110.)).text_color(cx.theme().muted_foreground).child(label)).child(value.into())
|
||||
}
|
||||
Reference in new issue
Block a user