windows: the app's Components page; the connection in the sidebar

- Components: each program's pinned version, the one installed (or
  missing), its license and source; fetching them all again, which the
  service allows administrators only, with each failure named.
- The sidebar's foot says whether the service is reachable, and
  "Applying…" while a change is under way; when it is not running, the
  overview says how to start it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 01:46:58 +03:00
1 parent 69759cfbce
commit a7bf347859
3 files changed
+134 -7

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
//! Components: the programs the service runs, the version each should be and the one
//! installed; fetching them again (an administrator's call, which the service enforces).
use gpui_kit::assets::IconName;
use gpui_kit::component::button::Button;
use gpui_kit::component::tag::Tag;
use gpui_kit::component::*;
use gpui_kit::*;
use ps_ipc::Request;
use serde_json::Value;
use super::widgets::{card, hint, page};
use crate::model::Model;
pub struct ComponentsPage {
model: Entity<Model>,
list: Result<Vec<Value>, String>,
installing: bool,
}
impl ComponentsPage {
pub fn new(model: Entity<Model>, cx: &mut Context<Self>) -> Self {
let mut this = Self { model, list: Ok(Vec::new()), installing: false };
this.load(cx);
this
}
fn load(&mut self, cx: &mut Context<Self>) {
let job = self.model.read(cx).bridge().call(Request::Components);
cx.spawn(async move |this, cx| {
let r = job.await;
this.update(cx, |this, cx| {
this.list = r.map(|v| v.as_array().cloned().unwrap_or_default()).map_err(|e| format!("{e:#}"));
cx.notify();
})
.ok();
})
.detach();
}
fn install(&mut self, names: Vec<String>, cx: &mut Context<Self>) {
self.installing = true;
cx.notify();
let what = if names.is_empty() { "Components installed".to_owned() } else { format!("{} installed", names.join(", ")) };
let job = self.model.read(cx).bridge().call(Request::ComponentsInstall { names });
let model = self.model.clone();
cx.spawn(async move |this, cx| {
// Each component's own failure comes back in the list, not as an error.
let result = job.await.and_then(|r| {
let failed: Vec<String> = r.as_array().into_iter().flatten().filter_map(|c| Some(format!("{}: {}", c["name"].as_str()?, c["error"].as_str()?))).collect();
if failed.is_empty() { Ok(()) } else { Err(anyhow::anyhow!(failed.join("; "))) }
});
model.update(cx, |m, cx| m.track(what, async move { result }, cx));
this.update(cx, |this, cx| {
this.installing = false;
this.load(cx);
})
.ok();
})
.detach();
}
}
impl Render for ComponentsPage {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let actions = div()
.h_flex()
.gap_2()
.child(Button::new("comp-reload").small().icon(IconName::RefreshCw).label("Reload").on_click(cx.listener(|this, _, _, cx| this.load(cx))))
.child(
Button::new("comp-install")
.small()
.icon(IconName::Download)
.label(if self.installing { "Installing…" } else { "Fetch all again" })
.disabled(self.installing)
.on_click(cx.listener(|this, _, _, cx| this.install(Vec::new(), cx))),
);
let mut list = card("Programs", Some(actions.into_any_element()), cx).child(hint(
"Each is pinned by version and hash, and checked before it runs. Fetching them again needs an administrator: run the app as one, or proxy-ctl components install in an administrator's terminal.",
cx,
));
match &self.list {
Err(e) => list = list.child(div().text_sm().text_color(cx.theme().danger).child(e.clone())),
Ok(items) => {
for c in items {
let want = c["version"].as_str().unwrap_or("");
let have = c["installed"].as_str();
let state = match have {
Some(v) if v == want => Tag::success().child("installed"),
Some(v) => Tag::warning().child(format!("{v} installed")),
None => Tag::danger().child("missing"),
};
list = list.child(
div()
.h_flex()
.gap_3()
.items_center()
.py_2()
.border_t_1()
.border_color(cx.theme().border)
.child(div().w(px(130.)).font_medium().child(c["name"].as_str().unwrap_or("").to_owned()))
.child(div().w(px(190.)).text_sm().child(want.to_owned()))
.child(state)
.child(div().flex_1().min_w_0().truncate().text_xs().text_color(cx.theme().muted_foreground).child(format!("{} · {}", c["license"].as_str().unwrap_or(""), c["homepage"].as_str().unwrap_or("")))),
);
}
}
}
page("Components", cx).child(list)
}
}
+18 -5
View File
@@ -1,6 +1,7 @@
//! The window: a sidebar of pages, the page shown, and what came of each change as a
//! notification.
mod components;
mod dpi;
mod logs;
mod outbounds;
@@ -10,12 +11,12 @@ mod telegram;
mod widgets;
use gpui_kit::component::notification::Notification;
use gpui_kit::component::sidebar::{Sidebar, SidebarGroup, SidebarHeader, SidebarMenu, SidebarMenuItem};
use gpui_kit::component::sidebar::{Sidebar, SidebarFooter, SidebarGroup, SidebarHeader, SidebarMenu, SidebarMenuItem};
use gpui_kit::assets::IconName;
use gpui_kit::component::*;
use gpui_kit::*;
use crate::model::{Model, Outcome};
use crate::model::{Connection, Model, Outcome};
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Page {
@@ -66,6 +67,7 @@ pub struct AppView {
logs: Option<Entity<logs::LogsPage>>,
/// Made when first shown, as it loads the configuration into its editor then.
settings: Option<Entity<settings::SettingsPage>>,
components: Option<Entity<components::ComponentsPage>>,
_subscriptions: Vec<Subscription>,
}
@@ -84,7 +86,7 @@ impl AppView {
let dpi = cx.new(|cx| dpi::DpiPage::new(model.clone(), window, cx));
let telegram = cx.new(|cx| telegram::TelegramPage::new(model.clone(), window, cx));
let outbounds = cx.new(|cx| outbounds::OutboundsPage::new(model.clone(), window, cx));
Self { model, page: Page::Overview, dpi, telegram, outbounds, logs: None, settings: None, _subscriptions: subscriptions }
Self { model, page: Page::Overview, dpi, telegram, outbounds, logs: None, settings: None, components: None, _subscriptions: subscriptions }
}
fn sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
@@ -94,7 +96,15 @@ impl AppView {
cx.notify();
}))
});
Sidebar::new("pages").header(SidebarHeader::new().child(widgets::brand(cx))).child(SidebarGroup::new("Proxy Suite").child(SidebarMenu::new().children(items)))
let m = self.model.read(cx);
let (colour, state) = match m.connection() {
Connection::Up if m.busy() => (cx.theme().warning, "Applying…"),
Connection::Up => (cx.theme().success, "Connected to the service"),
Connection::Connecting => (cx.theme().muted_foreground, "Connecting…"),
Connection::Down(_) => (cx.theme().danger, "The service is not running"),
};
let footer = SidebarFooter::new().child(div().h_flex().gap_2().items_center().text_xs().text_color(cx.theme().muted_foreground).child(div().size_2().rounded_full().bg(colour)).child(state));
Sidebar::new("pages").header(SidebarHeader::new().child(widgets::brand(cx))).child(SidebarGroup::new("Proxy Suite").child(SidebarMenu::new().children(items))).footer(footer)
}
}
@@ -113,7 +123,10 @@ impl Render for AppView {
let model = self.model.clone();
self.settings.get_or_insert_with(|| cx.new(|cx| settings::SettingsPage::new(model, window, cx))).clone().into_any_element()
}
other => widgets::page(other.title(), cx).child(div().text_color(cx.theme().muted_foreground).child("Not here yet.")).into_any_element(),
Page::Components => {
let model = self.model.clone();
self.components.get_or_insert_with(|| cx.new(|cx| components::ComponentsPage::new(model, cx))).clone().into_any_element()
}
};
div()
.h_flex()
+5 -2
View File
@@ -10,7 +10,7 @@ use ps_client::edits;
use serde_json::Value;
use super::AppView;
use super::widgets::{card, fact, page, state_tag};
use super::widgets::{card, fact, hint, page, state_tag};
use crate::model::{Connection, Model};
fn text(v: &Value) -> SharedString {
@@ -29,7 +29,10 @@ pub fn render(model: &Entity<Model>, _: &mut Window, cx: &mut Context<AppView>)
match &connection {
Connection::Down(why) => {
body = body.child(Alert::error("service-down", format!("The Proxy Suite service cannot be reached: {why}")).title("Not connected"));
body = body.child(Alert::error("service-down", why.clone()).title("Not connected")).child(hint(
"The service runs everything; this app only controls it. Install it with install.cmd from the release, or start it as an administrator: sc start ProxySuite.",
cx,
));
}
Connection::Connecting => body = body.child(Alert::info("connecting", "Connecting to the Proxy Suite service…")),
Connection::Up => {}