From d3ba00087dc7b779b0e3079105ed2d105fd6db65 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 27 Oct 2026 01:25:11 +0300 Subject: [PATCH] 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 --- windows/Cargo.lock | 6 + windows/crates/ps-client/src/edits.rs | 7 +- windows/crates/ps-gui/Cargo.toml | 6 + windows/crates/ps-gui/src/assets.rs | 27 +++ windows/crates/ps-gui/src/bridge.rs | 76 ++++++++ windows/crates/ps-gui/src/main.rs | 48 +++-- windows/crates/ps-gui/src/model.rs | 232 +++++++++++++++++++++++ windows/crates/ps-gui/src/ui/mod.rs | 100 ++++++++++ windows/crates/ps-gui/src/ui/overview.rs | 122 ++++++++++++ windows/crates/ps-gui/src/ui/widgets.rs | 44 +++++ windows/tools/gui-shot.sh | 7 +- 11 files changed, 654 insertions(+), 21 deletions(-) create mode 100644 windows/crates/ps-gui/src/assets.rs create mode 100644 windows/crates/ps-gui/src/bridge.rs create mode 100644 windows/crates/ps-gui/src/model.rs create mode 100644 windows/crates/ps-gui/src/ui/mod.rs create mode 100644 windows/crates/ps-gui/src/ui/overview.rs create mode 100644 windows/crates/ps-gui/src/ui/widgets.rs diff --git a/windows/Cargo.lock b/windows/Cargo.lock index 2593b24..4daba3a 100644 --- a/windows/Cargo.lock +++ b/windows/Cargo.lock @@ -4956,7 +4956,13 @@ dependencies = [ name = "ps-gui" version = "0.1.0-pre.2" dependencies = [ + "anyhow", + "async-channel", "gpui-kit", + "ps-client", + "ps-ipc", + "serde_json", + "tokio", ] [[package]] diff --git a/windows/crates/ps-client/src/edits.rs b/windows/crates/ps-client/src/edits.rs index 3dd717b..b0f46ec 100644 --- a/windows/crates/ps-client/src/edits.rs +++ b/windows/crates/ps-client/src/edits.rs @@ -194,10 +194,11 @@ pub fn set_zapret_enabled(c: &mut Value, on: bool) { c["zapret"]["enable"] = on.into(); } -/// The DPI bypass's engine: `zapret` (Flowseal's presets) or `zapret2`. +/// The DPI bypass's engine, by upstream's names: `zapret-discord-youtube` (Flowseal's +/// presets) or `zapret2`. pub fn set_zapret_engine(c: &mut Value, engine: &str) -> Result<()> { - if !matches!(engine, "zapret" | "zapret2") { - bail!("the engine is zapret or zapret2"); + if !matches!(engine, "zapret-discord-youtube" | "zapret2") { + bail!("the engine is zapret-discord-youtube or zapret2"); } c["zapret"]["engine"] = engine.into(); Ok(()) diff --git a/windows/crates/ps-gui/Cargo.toml b/windows/crates/ps-gui/Cargo.toml index 4104e25..f633d50 100644 --- a/windows/crates/ps-gui/Cargo.toml +++ b/windows/crates/ps-gui/Cargo.toml @@ -11,3 +11,9 @@ path = "src/main.rs" [dependencies] gpui-kit = { version = "0.8.1", features = ["tree-sitter"] } +ps-client.workspace = true +ps-ipc.workspace = true +anyhow.workspace = true +serde_json.workspace = true +tokio.workspace = true +async-channel = "2" diff --git a/windows/crates/ps-gui/src/assets.rs b/windows/crates/ps-gui/src/assets.rs new file mode 100644 index 0000000..5055e68 --- /dev/null +++ b/windows/crates/ps-gui/src/assets.rs @@ -0,0 +1,27 @@ +//! The icons: the components' own (`Assets`), and the few more the app uses, embedded one by +//! one rather than the whole Lucide catalogue. + +use std::borrow::Cow; + +use gpui_kit::*; + +gpui_kit::assets::icon_assets!(Extra, [Shield, Send, Package, Pin, PinOff, RefreshCw, Save, Trash, Plus, Copy, Download, Link, Gauge, Power]); + +pub struct AppAssets; + +impl AssetSource for AppAssets { + fn load(&self, path: &str) -> Result>> { + match Extra.load(path)? { + Some(bytes) => Ok(Some(bytes)), + None => gpui_kit::assets::Assets.load(path), + } + } + + fn list(&self, path: &str) -> Result> { + let mut paths = gpui_kit::assets::Assets.list(path)?; + paths.extend(Extra.list(path)?); + paths.sort(); + paths.dedup(); + Ok(paths) + } +} diff --git a/windows/crates/ps-gui/src/bridge.rs b/windows/crates/ps-gui/src/bridge.rs new file mode 100644 index 0000000..f787057 --- /dev/null +++ b/windows/crates/ps-gui/src/bridge.rs @@ -0,0 +1,76 @@ +//! The service, from the app's side: ps-client on a tokio runtime of its own (the transport is +//! tokio's), its answers awaited from GPUI's executor. A tokio `JoinHandle` is a plain future, +//! so either side can await it. + +use std::sync::Arc; +use std::time::Duration; + +use anyhow::{Result, anyhow}; +use ps_client::{Client, Saved}; +use ps_ipc::Request; +use ps_ipc::transport::Address; +use serde_json::Value; + +/// A log line, or the follow ending (it starts again by itself). +pub enum LogEvent { + Line { unit: String, line: String }, + Lost(String), +} + +#[derive(Clone)] +pub struct Bridge { + rt: Arc, + client: Client, +} + +impl Bridge { + pub fn start(addr: Address) -> Self { + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(2) + .thread_name("proxy-suite-ipc") + .enable_all() + .build() + .expect("a tokio runtime"); + Self { rt: Arc::new(rt), client: Client::new(addr) } + } + + pub fn call(&self, req: Request) -> impl Future> + 'static { + let client = self.client.clone(); + let task = self.rt.spawn(async move { client.call(req).await }); + async move { task.await.map_err(|e| anyhow!("{e}"))? } + } + + /// A configuration edit, made again on a newer configuration when another change came + /// first ([`Client::edit`]). + pub fn edit(&self, edit: impl Fn(&mut Value) -> Result<()> + Send + Sync + 'static) -> impl Future> + 'static { + let client = self.client.clone(); + let task = self.rt.spawn(async move { client.edit(edit).await }); + async move { task.await.map_err(|e| anyhow!("{e}"))? } + } + + /// Every unit's log, the last `lines` and each new line, until the receiver is dropped. + /// A lost connection is said, then made again. + pub fn follow_logs(&self, lines: usize) -> async_channel::Receiver { + let (tx, rx) = async_channel::unbounded(); + let client = self.client.clone(); + self.rt.spawn(async move { + let mut lines = lines; + loop { + let ended = client + .logs(None, lines, true, |unit, line| tx.try_send(LogEvent::Line { unit: unit.into(), line: line.into() }).is_ok()) + .await; + if tx.is_closed() { + break; + } + let why = ended.err().map(|e| e.to_string()).unwrap_or_else(|| "the service ended the log".into()); + if tx.try_send(LogEvent::Lost(why)).is_err() { + break; + } + // What came before the break was seen; only what comes after is wanted. + lines = 0; + tokio::time::sleep(Duration::from_secs(2)).await; + } + }); + rx + } +} diff --git a/windows/crates/ps-gui/src/main.rs b/windows/crates/ps-gui/src/main.rs index 46dddb5..7d1793a 100644 --- a/windows/crates/ps-gui/src/main.rs +++ b/windows/crates/ps-gui/src/main.rs @@ -1,29 +1,43 @@ -//! proxy-suite: the desktop app. A client of the service, as proxy-ctl is. +//! proxy-suite: the desktop app. A client of the service, as proxy-ctl is: it shows what the +//! service runs and sends it each change, which the service checks and applies. The app keeps +//! nothing of its own. +//! +//! proxy-suite [--socket ADDRESS] (the service's pipe or socket, as proxy-ctl takes it) #![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")] -use gpui_kit::component::button::*; -use gpui_kit::component::*; +mod assets; +mod bridge; +mod model; +mod ui; + use gpui_kit::*; +use ps_ipc::transport::Address; -struct Hello; - -impl Render for Hello { - fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { - div() - .v_flex() - .gap_2() - .size_full() - .items_center() - .justify_center() - .child("Proxy Suite") - .child(Button::new("ok").primary().label("On")) +fn address() -> Address { + let mut args = std::env::args().skip(1); + while let Some(arg) = args.next() { + if arg == "--socket" + && let Some(s) = args.next() + { + return if cfg!(windows) { Address::Pipe(s) } else { Address::Unix(s.into()) }; + } } + Address::default_for_platform() } fn main() { - gpui_kit::application().with_assets(gpui_kit::assets::Assets).run(|cx| { + let bridge = bridge::Bridge::start(address()); + gpui_kit::application().with_assets(assets::AppAssets).run(move |cx| { gpui_kit::init(cx); - gpui_kit::open_window(WindowOptions::default(), cx, |_, cx| cx.new(|_| Hello)).expect("opening the window"); + let model = cx.new(|cx| model::Model::new(bridge, cx)); + let options = WindowOptions { + window_bounds: Some(WindowBounds::Windowed(Bounds::centered(None, size(px(1080.), px(720.)), cx))), + titlebar: Some(TitlebarOptions { title: Some("Proxy Suite".into()), ..Default::default() }), + window_min_size: Some(size(px(720.), px(480.))), + app_id: Some("proxy-suite".into()), + ..Default::default() + }; + gpui_kit::open_window(options, cx, |window, cx| cx.new(|cx| ui::AppView::new(model, window, cx))).expect("opening the window"); }); } diff --git a/windows/crates/ps-gui/src/model.rs b/windows/crates/ps-gui/src/model.rs new file mode 100644 index 0000000..81fbd31 --- /dev/null +++ b/windows/crates/ps-gui/src/model.rs @@ -0,0 +1,232 @@ +//! What the app knows of the service, refreshed while it runs, and the changes it asks of it. +//! Views read it and call its methods; it tells them what came of each change ([`Outcome`]). + +use std::time::Duration; + +use anyhow::{Result, bail}; +use gpui_kit::*; +use ps_client::edits; +use ps_ipc::Request; +use serde_json::Value; + +use crate::bridge::Bridge; + +/// What a change came to. +pub enum Outcome { + Done(SharedString), + Failed(SharedString), +} + +#[derive(Clone, PartialEq)] +pub enum Connection { + Connecting, + Up, + /// Why the service cannot be reached. + Down(SharedString), +} + +pub struct Model { + bridge: Bridge, + connection: Connection, + status: Value, + outbounds: Value, + presets: Vec, + tg_links: Vec, + /// Changes sent and not yet answered. + pending: usize, + _poll: Task<()>, +} + +impl EventEmitter for Model {} + +const POLL: Duration = Duration::from_secs(2); + +impl Model { + pub fn new(bridge: Bridge, cx: &mut Context) -> Self { + let poller = bridge.clone(); + let poll = cx.spawn(async move |this, cx| { + let mut round = 0u32; + loop { + let status = poller.call(Request::Status).await; + // Outbounds change less often than states; every fifth round, and on a reconnect. + let reconnect = this.read_with(cx, |m, _| m.connection != Connection::Up).unwrap_or(false); + let outbounds = if round % 5 == 0 || reconnect { Some(poller.call(Request::Outbounds).await) } else { None }; + let alive = this.update(cx, |m, cx| { + m.take_status(status, cx); + if let Some(Ok(o)) = outbounds { + m.outbounds = o; + } + cx.notify(); + }); + if alive.is_err() { + break; + } + round += 1; + cx.background_executor().timer(POLL).await; + } + }); + Self { + bridge, + connection: Connection::Connecting, + status: Value::Null, + outbounds: Value::Null, + presets: Vec::new(), + tg_links: Vec::new(), + pending: 0, + _poll: poll, + } + } + + fn take_status(&mut self, status: Result, cx: &mut Context) { + match status { + Ok(s) => { + let was_up = self.connection == Connection::Up; + self.status = s; + self.connection = Connection::Up; + if !was_up { + self.load_presets(cx); + self.load_tg_links(cx); + } + } + Err(e) => self.connection = Connection::Down(format!("{e:#}").into()), + } + } + + pub fn bridge(&self) -> &Bridge { + &self.bridge + } + + pub fn connection(&self) -> &Connection { + &self.connection + } + + pub fn status(&self) -> &Value { + &self.status + } + + pub fn outbounds(&self) -> &Value { + &self.outbounds + } + + pub fn presets(&self) -> &[SharedString] { + &self.presets + } + + pub fn tg_links(&self) -> &[SharedString] { + &self.tg_links + } + + pub fn busy(&self) -> bool { + self.pending > 0 + } + + /// Status and outbounds now, rather than at the next round. + pub fn refresh(&mut self, cx: &mut Context) { + let status = self.bridge.call(Request::Status); + let outbounds = self.bridge.call(Request::Outbounds); + cx.spawn(async move |this, cx| { + let (status, outbounds) = (status.await, outbounds.await); + this.update(cx, |m, cx| { + m.take_status(status, cx); + if let Ok(o) = outbounds { + m.outbounds = o; + } + cx.notify(); + }) + .ok(); + }) + .detach(); + } + + pub fn load_presets(&mut self, cx: &mut Context) { + let job = self.bridge.call(Request::ZapretPresets); + cx.spawn(async move |this, cx| { + if let Ok(r) = job.await { + let presets = r["presets"].as_array().into_iter().flatten().filter_map(Value::as_str).map(|p| SharedString::from(p.to_owned())).collect(); + this.update(cx, |m, cx| { + m.presets = presets; + cx.notify(); + }) + .ok(); + } + }) + .detach(); + } + + /// tg-ws-proxy's links: none without the secrets scope. + pub fn load_tg_links(&mut self, cx: &mut Context) { + let job = self.bridge.call(Request::TgLinks); + cx.spawn(async move |this, cx| { + let links = job.await.map(|r| r["links"].as_array().into_iter().flatten().filter_map(Value::as_str).map(|l| SharedString::from(l.to_owned())).collect()).unwrap_or_default(); + this.update(cx, |m, cx| { + m.tg_links = links; + cx.notify(); + }) + .ok(); + }) + .detach(); + } + + /// Runs `job`, says what came of it, and refreshes. + pub fn track(&mut self, what: impl Into, job: impl Future> + 'static, cx: &mut Context) { + let what = what.into(); + self.pending += 1; + cx.notify(); + cx.spawn(async move |this, cx| { + let result = job.await; + this.update(cx, |m, cx| { + m.pending -= 1; + cx.emit(match result { + Ok(()) => Outcome::Done(what), + Err(e) => Outcome::Failed(format!("{what}: {e:#}").into()), + }); + m.refresh(cx); + }) + .ok(); + }) + .detach(); + } + + /// A configuration change. Saved but not applied is a failure: the user should hear why. + pub fn edit(&mut self, what: impl Into, edit: impl Fn(&mut Value) -> Result<()> + Send + Sync + 'static, cx: &mut Context) { + let job = self.bridge.edit(edit); + self.track( + what, + async move { + if let Some(e) = job.await?.apply_error { + bail!("saved, but not applied: {e}"); + } + Ok(()) + }, + cx, + ); + } + + pub fn request(&mut self, what: impl Into, req: Request, cx: &mut Context) { + let job = self.bridge.call(req); + self.track(what, async move { job.await.map(drop) }, cx); + } + + /// The local proxy on (in the configuration too, as proxy-ctl's `proxy on`) or off. + pub fn set_proxy(&mut self, on: bool, cx: &mut Context) { + let bridge = self.bridge.clone(); + let job = async move { + if on { + let saved = bridge + .edit(|c| { + edits::set_proxy_enabled(c, true); + Ok(()) + }) + .await?; + if let Some(e) = saved.apply_error { + bail!("saved, but not applied: {e}"); + } + bridge.call(Request::Start { unit: "proxy-suite-socks".into() }).await?; + } else { + bridge.call(Request::Stop { unit: "proxy-suite-socks".into() }).await?; + } + Ok(()) + }; + self.track(if on { "The proxy is on" } else { "The proxy is off" }, job, cx); + } +} diff --git a/windows/crates/ps-gui/src/ui/mod.rs b/windows/crates/ps-gui/src/ui/mod.rs new file mode 100644 index 0000000..11ac1a4 --- /dev/null +++ b/windows/crates/ps-gui/src/ui/mod.rs @@ -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, + page: Page, + _subscriptions: Vec, +} + +impl AppView { + pub fn new(model: Entity, window: &mut Window, cx: &mut Context) -> 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) -> 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) -> 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)) + } +} diff --git a/windows/crates/ps-gui/src/ui/overview.rs b/windows/crates/ps-gui/src/ui/overview.rs new file mode 100644 index 0000000..7528705 --- /dev/null +++ b/windows/crates/ps-gui/src/ui/overview.rs @@ -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, _: &mut Window, cx: &mut Context) -> 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())) +} diff --git a/windows/crates/ps-gui/src/ui/widgets.rs b/windows/crates/ps-gui/src/ui/widgets.rs new file mode 100644 index 0000000..f7e1eed --- /dev/null +++ b/windows/crates/ps-gui/src/ui/widgets.rs @@ -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, action: Option, 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, 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()) +} diff --git a/windows/tools/gui-shot.sh b/windows/tools/gui-shot.sh index 582075f..0f3e4c9 100755 --- a/windows/tools/gui-shot.sh +++ b/windows/tools/gui-shot.sh @@ -4,7 +4,8 @@ # # tools/gui-shot.sh OUT.png [SECONDS] [-- APP ARGS...] (APP=target/debug/proxy-suite) # -# With SHOT_KEYS="key ..." the keys (xdotool names) are typed into the window before the shot. +# Before the shot, SHOT_CLICKS="X,Y ..." clicks those screen points, and SHOT_KEYS="key ..." +# types those keys (xdotool names), each followed by a moment for the app to answer. set -euo pipefail OUT=$(realpath -m "${1:?the screenshot, a .png}"); shift WAIT=6 @@ -29,6 +30,10 @@ env -u WAYLAND_DISPLAY DISPLAY=":$n" VK_ICD_FILENAMES="$MESA/share/vulkan/icd.d/ APID=$! sleep "$WAIT" kill -0 "$APID" 2>/dev/null || { echo "the app exited:"; tail -20 "${OUT%.png}.log"; exit 1; } +for point in ${SHOT_CLICKS:-}; do + DISPLAY=":$n" "$XDOTOOL/bin/xdotool" mousemove "${point%,*}" "${point#*,}" click 1 + sleep 1.5 +done if [ -n "${SHOT_KEYS:-}" ]; then # shellcheck disable=SC2086 DISPLAY=":$n" "$XDOTOOL/bin/xdotool" key --delay 150 $SHOT_KEYS