windows: the app's Settings page: the whole configuration

Upstream's option tree as JSON in a code editor (highlighted, folding),
loaded with its revision; Check asks the service to validate without
taking it; Save sends it against the revision loaded, so a change made
elsewhere meanwhile is refused, not overwritten, and the page says so.
The validator's notes and an apply failure are shown under the editor;
redacted secrets are explained (left as they are, they keep their
values). Every option the other pages do not show is editable here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 01:44:55 +03:00
1 parent 23c1687118
commit 69759cfbce
2 files changed
+198 -1

No files matched your search

+8 -1
View File
@@ -5,6 +5,7 @@ mod dpi;
mod logs;
mod outbounds;
mod overview;
mod settings;
mod telegram;
mod widgets;
@@ -63,6 +64,8 @@ pub struct AppView {
outbounds: Entity<outbounds::OutboundsPage>,
/// Made when first shown: following the logs starts then.
logs: Option<Entity<logs::LogsPage>>,
/// Made when first shown, as it loads the configuration into its editor then.
settings: Option<Entity<settings::SettingsPage>>,
_subscriptions: Vec<Subscription>,
}
@@ -81,7 +84,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, _subscriptions: subscriptions }
Self { model, page: Page::Overview, dpi, telegram, outbounds, logs: None, settings: None, _subscriptions: subscriptions }
}
fn sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
@@ -106,6 +109,10 @@ impl Render for AppView {
let model = self.model.clone();
self.logs.get_or_insert_with(|| cx.new(|cx| logs::LogsPage::new(model, cx))).clone().into_any_element()
}
Page::Settings => {
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(),
};
div()
+190
View File
@@ -0,0 +1,190 @@
//! Settings: the whole configuration, upstream's option tree as JSON, edited here and checked
//! by the service before it takes it. Every option the other pages show is here too, and the
//! ones they do not.
use gpui_kit::assets::IconName;
use gpui_kit::component::button::{Button, ButtonVariants as _};
use gpui_kit::component::input::{Editor, EditorState, InputEvent};
use gpui_kit::component::*;
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
use ps_client::Issue;
use ps_ipc::Request;
use serde_json::Value;
use super::widgets::{card, hint, page};
use crate::model::Model;
/// What the service shows in place of a secret the caller may not read; saved back as it is,
/// the secret keeps its value.
const REDACTED: &str = "\u{2022}\u{2022}\u{2022}redacted\u{2022}\u{2022}\u{2022}";
enum Verdict {
None,
Working(&'static str),
Issues(Vec<Issue>),
Failed(String),
Saved { revision: u64, issues: Vec<Issue>, apply_error: Option<String> },
}
pub struct SettingsPage {
model: Entity<Model>,
editor: Entity<EditorState>,
/// The text and revision last loaded: what is saved against, and what "changed" means.
loaded: Option<(String, u64)>,
verdict: Verdict,
_subscriptions: Vec<Subscription>,
}
impl SettingsPage {
pub fn new(model: Entity<Model>, window: &mut Window, cx: &mut Context<Self>) -> Self {
let editor = cx.new(|cx| EditorState::new(window, cx).language("json").line_number(true).folding(true));
// Save is offered once the text differs from what was loaded.
let subscriptions = vec![cx.subscribe(&editor, |_, _, event: &InputEvent, cx| {
if matches!(event, InputEvent::Change) {
cx.notify();
}
})];
let mut this = Self { model, editor, loaded: None, verdict: Verdict::None, _subscriptions: subscriptions };
this.reload(window, cx);
this
}
fn reload(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.verdict = Verdict::Working("Loading…");
cx.notify();
let job = self.model.read(cx).bridge().call(Request::ConfigGet);
cx.spawn_in(window, async move |this, cx| {
let got = job.await;
this.update_in(cx, |this, window, cx| {
match got {
Ok(r) => {
let text = serde_json::to_string_pretty(&r["config"]).unwrap_or_default();
this.loaded = Some((text.clone(), r["revision"].as_u64().unwrap_or(0)));
this.verdict = Verdict::None;
this.editor.update(cx, |s, cx| s.set_value(text, window, cx));
}
Err(e) => this.verdict = Verdict::Failed(format!("{e:#}")),
}
cx.notify();
})
.ok();
})
.detach();
}
/// The editor's text as JSON, or where it is not.
fn parsed(&self, cx: &App) -> Result<Value, String> {
serde_json::from_str(&self.editor.read(cx).value()).map_err(|e| format!("Not valid JSON: {e}"))
}
fn validate(&mut self, cx: &mut Context<Self>) {
let config = match self.parsed(cx) {
Ok(c) => c,
Err(e) => {
self.verdict = Verdict::Failed(e);
return cx.notify();
}
};
self.verdict = Verdict::Working("Checking…");
cx.notify();
let job = self.model.read(cx).bridge().call(Request::ConfigValidate { config });
cx.spawn(async move |this, cx| {
let r = job.await;
this.update(cx, |this, cx| {
this.verdict = match r {
Ok(r) => Verdict::Issues(ps_client::issues(&r)),
Err(e) => Verdict::Failed(format!("{e:#}")),
};
cx.notify();
})
.ok();
})
.detach();
}
fn save(&mut self, cx: &mut Context<Self>) {
let config = match self.parsed(cx) {
Ok(c) => c,
Err(e) => {
self.verdict = Verdict::Failed(e);
return cx.notify();
}
};
let base = self.loaded.as_ref().map(|(_, r)| *r);
self.verdict = Verdict::Working("Saving…");
cx.notify();
let job = self.model.read(cx).bridge().call(Request::ConfigSet { config, base });
let model = self.model.clone();
cx.spawn(async move |this, cx| {
let r = job.await;
this.update(cx, |this, cx| {
this.verdict = match r {
Ok(r) => {
let revision = r["revision"].as_u64().unwrap_or(0);
let text = this.editor.read(cx).value().to_string();
this.loaded = Some((text, revision));
Verdict::Saved { revision, issues: ps_client::issues(&r), apply_error: r["error"].as_str().map(str::to_owned) }
}
Err(e) if e.to_string().contains("changed since revision") => {
Verdict::Failed("The configuration was changed elsewhere since it was loaded. Reload to see it (your edits here are then lost; copy them first).".into())
}
Err(e) => Verdict::Failed(format!("{e:#}")),
};
cx.notify();
})
.ok();
model.update(cx, |m, cx| {
m.refresh(cx);
m.load_config(cx);
});
})
.detach();
}
}
fn issue_list(issues: &[Issue], cx: &App) -> Div {
let mut list = div().v_flex().gap_1();
for i in issues {
let colour = if i.severity == "error" { cx.theme().danger } else { cx.theme().warning };
list = list.child(div().text_sm().h_flex().gap_2().child(div().text_color(colour).child(i.severity.clone())).child(div().font_family("monospace").child(i.path.clone())).child(div().flex_1().min_w_0().child(i.message.clone())));
}
list
}
impl Render for SettingsPage {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let text = self.editor.read(cx).value();
let changed = self.loaded.as_ref().is_some_and(|(t, _)| t.as_str() != text.as_ref());
let redacted = text.contains(REDACTED);
let actions = div()
.h_flex()
.gap_2()
.child(Button::new("cfg-reload").small().ghost().icon(IconName::RefreshCw).label("Reload").on_click(cx.listener(|this, _, window, cx| this.reload(window, cx))))
.child(Button::new("cfg-validate").small().label("Check").on_click(cx.listener(|this, _, _, cx| this.validate(cx))))
.child(Button::new("cfg-save").small().primary().icon(IconName::Save).label("Save").disabled(!changed).on_click(cx.listener(|this, _, _, cx| this.save(cx))));
let verdict = match &self.verdict {
Verdict::None => div(),
Verdict::Working(what) => hint(*what, cx),
Verdict::Failed(e) => div().text_sm().text_color(cx.theme().danger).child(e.clone()),
Verdict::Issues(issues) if issues.is_empty() => div().text_sm().text_color(cx.theme().success).child("It is valid."),
Verdict::Issues(issues) => issue_list(issues, cx),
Verdict::Saved { revision, issues, apply_error } => div()
.v_flex()
.gap_1()
.child(div().text_sm().text_color(cx.theme().success).child(format!("Saved as revision {revision}.")))
.when_some(apply_error.clone(), |d, e| d.child(div().text_sm().text_color(cx.theme().danger).child(format!("Saved, but not applied: {e}"))))
.child(issue_list(issues, cx)),
};
page("Settings", cx).child(
card("Configuration", Some(actions.into_any_element()), cx)
.child(hint("Upstream's options (services.proxy-suite…) as JSON, as proxy-ctl config get prints them. The service checks them before taking them; options that run programs or read files need an administrator.", cx))
.when(redacted, |d| d.child(hint("Values shown as •••redacted••• are secrets you may not read here; left as they are, they keep their values.", cx)))
.child(div().h(px(480.)).border_1().border_color(cx.theme().border).rounded_md().child(Editor::new(&self.editor).h_full()))
.child(verdict),
)
}
}