windows: updates from the app, and a dark theme

The service looks at the project's releases (windows-v* tags; pre-releases
for a pre-release), fetches the newer setup program, checks its SHA-256
against the one published beside it, and runs it silently, detached, out of
any job: the setup stops the service, replaces it, and starts it again.
Run by the service (session 0), the setup's install starts the app in each
signed-in user's session with their token rather than through Explorer. A
failed copy during an upgrade starts the old service and app again.
Request::UpdateCheck (anyone), UpdateInstall (services scope);
proxy-ctl update [check|install]; the app's Overview card.

The app's own preferences (%APPDATA%\ProxySuite\app.json): the theme
(light, dark, or as Windows, followed as it changes; the title bar too) and
whether to look for updates at start and daily. Settings > This app, and a
sun/moon toggle in the sidebar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 22:21:27 +03:00
1 parent ed9275250b
commit 5bd47f7676
32 files changed
+911 -26

No files matched your search

+9 -1
View File
@@ -15,9 +15,17 @@ gpui-tray = { version = "0.3", default-features = false, features = ["gpui-kit",
ps-client.workspace = true
ps-ipc.workspace = true
anyhow.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true
async-channel = "2"
[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_System_Registry", "Win32_Networking_WinInet"] }
windows-sys = { workspace = true, features = [
"Win32_Foundation",
"Win32_System_Registry",
"Win32_Networking_WinInet",
"Win32_Graphics_Dwm",
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
] }
+1 -1
View File
@@ -5,7 +5,7 @@ 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, Video, FileUp, Route, Lock]);
gpui_kit::assets::icon_assets!(Extra, [Shield, Send, Package, Pin, PinOff, RefreshCw, Save, Trash, Plus, Copy, Download, Link, Gauge, Power, Video, FileUp, Route, Lock, ExternalLink, Sun, Moon]);
pub struct AppAssets;
+4 -1
View File
@@ -1,6 +1,6 @@
//! 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.
//! only its own look, and whether it looks for updates (prefs.rs).
//!
//! proxy-suite [--socket ADDRESS] [--hidden] (the service's pipe or socket, as proxy-ctl takes
//! it; --hidden starts in the tray)
@@ -10,6 +10,7 @@
mod assets;
mod bridge;
mod model;
mod prefs;
mod shell;
mod sysproxy;
mod ui;
@@ -46,6 +47,8 @@ fn main() {
// The window closing does not end the app: the tray does (shell.rs).
gpui_kit::application().with_assets(assets::AppAssets).with_quit_mode(QuitMode::Explicit).run(move |cx| {
gpui_kit::init(cx);
cx.set_global(prefs::load());
prefs::apply_theme(None, cx);
let model = cx.new(|cx| model::Model::new(bridge, cx));
shell::start(model, !args.hidden, cx);
});
+105 -1
View File
@@ -1,7 +1,7 @@
//! 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 std::time::{Duration, Instant};
use anyhow::{Result, bail};
use gpui_kit::*;
@@ -17,6 +17,20 @@ pub enum Outcome {
Failed(SharedString),
}
/// Whether a newer release of Proxy Suite is out, as the service last found.
#[derive(Clone, PartialEq)]
pub enum Update {
/// Not looked for (yet, or the preference says not to).
Unknown,
Checking,
Newest,
Available { version: SharedString, page: SharedString },
/// Its setup program being fetched and checked (`started`: and then run, which closes
/// this app and opens the new one), since `at`.
Installing { version: SharedString, started: bool, at: Instant },
Failed(SharedString),
}
#[derive(Clone, PartialEq)]
pub enum Connection {
Connecting,
@@ -36,12 +50,21 @@ pub struct Model {
tg_links: Vec<SharedString>,
/// Changes sent and not yet answered.
pending: usize,
update: Update,
/// The version the service runs, from its last update check.
version: SharedString,
/// When updates were last looked for.
update_checked: Option<Instant>,
_poll: Task<()>,
}
impl EventEmitter<Outcome> for Model {}
const POLL: Duration = Duration::from_secs(2);
/// How often a running app looks for updates again (when the preference has it look).
const UPDATE_CHECK: Duration = Duration::from_secs(24 * 3600);
/// How long the setup has to close this app once it runs.
const SETUP_WAIT: Duration = Duration::from_secs(5 * 60);
impl Model {
pub fn new(bridge: Bridge, cx: &mut Context<Self>) -> Self {
@@ -58,6 +81,16 @@ impl Model {
if let Some(Ok(o)) = outbounds {
m.outbounds = o;
}
// A setup that ran and left this app running did not replace it.
if let Update::Installing { version, started: true, at } = &m.update
&& at.elapsed() >= SETUP_WAIT
{
m.update = Update::Failed(format!("the setup of {version} did not finish (the service's log, on the Logs page, may say why)").into());
}
let due = m.update_checked.is_none_or(|t| t.elapsed() >= UPDATE_CHECK);
if m.connection == Connection::Up && due && cx.global::<crate::prefs::Prefs>().check_updates {
m.check_update(cx);
}
cx.notify();
});
if alive.is_err() {
@@ -76,6 +109,9 @@ impl Model {
presets: Vec::new(),
tg_links: Vec::new(),
pending: 0,
update: Update::Unknown,
version: env!("CARGO_PKG_VERSION").into(),
update_checked: None,
_poll: poll,
}
}
@@ -128,6 +164,74 @@ impl Model {
self.pending > 0
}
pub fn update(&self) -> &Update {
&self.update
}
pub fn version(&self) -> &SharedString {
&self.version
}
/// Asks the service whether a newer release is out.
pub fn check_update(&mut self, cx: &mut Context<Self>) {
if matches!(self.update, Update::Checking | Update::Installing { .. }) {
return;
}
self.update = Update::Checking;
self.update_checked = Some(Instant::now());
cx.notify();
let job = self.bridge.call(Request::UpdateCheck);
cx.spawn(async move |this, cx| {
let r = job.await;
this.update(cx, |m, cx| {
m.update = match r {
Ok(r) => {
if let Some(v) = r["current"].as_str() {
m.version = v.to_owned().into();
}
match r["available"].as_object() {
Some(a) => Update::Available {
version: a.get("version").and_then(Value::as_str).unwrap_or("?").to_owned().into(),
page: a.get("page").and_then(Value::as_str).unwrap_or_default().to_owned().into(),
},
None => Update::Newest,
}
}
Err(e) => Update::Failed(format!("{e:#}").into()),
};
cx.notify();
})
.ok();
})
.detach();
}
/// Has the service fetch the newest release and run its setup, which replaces the service
/// and this app, and opens the new one.
pub fn install_update(&mut self, cx: &mut Context<Self>) {
let Update::Available { version, .. } = &self.update else { return };
let version = version.clone();
self.update = Update::Installing { version: version.clone(), started: false, at: Instant::now() };
cx.notify();
let job = self.bridge.call(Request::UpdateInstall);
cx.spawn(async move |this, cx| {
let r = job.await;
this.update(cx, |m, cx| {
match r {
Ok(_) => m.update = Update::Installing { version, started: true, at: Instant::now() },
Err(e) => {
let e: SharedString = format!("{e:#}").into();
cx.emit(Outcome::Failed(format!("Updating to {version}: {e}").into()));
m.update = Update::Failed(e);
}
}
cx.notify();
})
.ok();
})
.detach();
}
/// Status and outbounds now, rather than at the next round.
pub fn refresh(&mut self, cx: &mut Context<Self>) {
let status = self.bridge.call(Request::Status);
+108
View File
@@ -0,0 +1,108 @@
//! The app's own preferences, each user's: its look, and whether it looks for updates. All
//! else is the service's configuration.
//!
//! In `%APPDATA%\ProxySuite\app.json` (elsewhere `$XDG_CONFIG_HOME/proxy-suite/app.json`).
use std::path::PathBuf;
use gpui_kit::component::{Theme, ThemeMode};
use gpui_kit::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ThemeChoice {
/// Windows' own: light or dark as apps are set to be (Settings → Personalization → Colors).
#[default]
System,
Light,
Dark,
}
impl ThemeChoice {
pub const ALL: [(ThemeChoice, &'static str); 3] = [(ThemeChoice::System, "As Windows"), (ThemeChoice::Light, "Light"), (ThemeChoice::Dark, "Dark")];
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default)]
pub struct Prefs {
pub theme: ThemeChoice,
/// At start and daily, ask the service whether a newer release is out.
pub check_updates: bool,
}
impl Default for Prefs {
fn default() -> Self {
Self { theme: ThemeChoice::System, check_updates: true }
}
}
impl Global for Prefs {}
fn path() -> Option<PathBuf> {
if cfg!(windows) {
std::env::var_os("APPDATA").map(|d| PathBuf::from(d).join("ProxySuite").join("app.json"))
} else {
let base = std::env::var_os("XDG_CONFIG_HOME").map(PathBuf::from).or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".config")))?;
Some(base.join("proxy-suite").join("app.json"))
}
}
/// The saved preferences, or the defaults where there are none (or they do not read).
pub fn load() -> Prefs {
path().and_then(|p| std::fs::read(p).ok()).and_then(|b| serde_json::from_slice(&b).ok()).unwrap_or_default()
}
impl Prefs {
fn save(&self) {
let Some(path) = path() else { return };
if let Some(dir) = path.parent() {
let _ = std::fs::create_dir_all(dir);
}
if let Err(e) = std::fs::write(&path, serde_json::to_vec_pretty(self).unwrap_or_default()) {
eprintln!("proxy-suite: saving {}: {e}", path.display());
}
}
}
/// Changes the preferences, saves them, and shows what changed.
pub fn change(cx: &mut App, edit: impl FnOnce(&mut Prefs)) {
let before = cx.global::<Prefs>().theme;
edit(cx.global_mut::<Prefs>());
cx.global::<Prefs>().save();
if cx.global::<Prefs>().theme != before {
apply_theme(None, cx);
}
cx.refresh_windows();
}
/// The theme the preference picks: Windows' appearance (the window's, when there is one), or
/// the one chosen.
pub fn apply_theme(window: Option<&mut Window>, cx: &mut App) {
match cx.global::<Prefs>().theme {
ThemeChoice::System => Theme::sync_system_appearance(window, cx),
ThemeChoice::Light => Theme::change(ThemeMode::Light, window, cx),
ThemeChoice::Dark => Theme::change(ThemeMode::Dark, window, cx),
}
#[cfg(windows)]
title_bars(Theme::global(cx).is_dark());
}
/// Windows draws the window's title bar, light or dark as Windows' own appearance is (GPUI sets
/// it so): as the theme chosen instead. The app's windows are its main thread's.
#[cfg(windows)]
fn title_bars(dark: bool) {
use windows_sys::Win32::Foundation::{HWND, LPARAM};
use windows_sys::Win32::Graphics::Dwm::{DWMWA_USE_IMMERSIVE_DARK_MODE, DwmSetWindowAttribute};
use windows_sys::Win32::System::Threading::GetCurrentThreadId;
use windows_sys::Win32::UI::WindowsAndMessaging::EnumThreadWindows;
unsafe extern "system" fn each(hwnd: HWND, dark: LPARAM) -> windows_sys::core::BOOL {
let value: windows_sys::core::BOOL = (dark != 0).into();
// SAFETY: a window of this thread, and a BOOL as long as said.
unsafe { DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE as u32, (&value as *const windows_sys::core::BOOL).cast(), 4) };
1
}
// SAFETY: the callback only reads its arguments.
unsafe { EnumThreadWindows(GetCurrentThreadId(), Some(each), dark as LPARAM) };
}
+22 -1
View File
@@ -13,6 +13,7 @@ mod telegram;
mod whitelist;
mod widgets;
use gpui_kit::component::button::{Button, ButtonVariants as _};
use gpui_kit::component::notification::Notification;
use gpui_kit::component::sidebar::{Sidebar, SidebarFooter, SidebarGroup, SidebarHeader, SidebarMenu, SidebarMenuItem};
use gpui_kit::assets::IconName;
@@ -102,6 +103,12 @@ 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()),
// As Windows' appearance changes, when the theme follows it.
cx.observe_window_appearance(window, |_, window, cx| {
if cx.global::<crate::prefs::Prefs>().theme == crate::prefs::ThemeChoice::System {
crate::prefs::apply_theme(Some(window), cx);
}
}),
cx.subscribe_in(&model, window, |_, _, outcome: &Outcome, window, cx| {
let note = match outcome {
Outcome::Done(m) => Notification::success(m.clone()),
@@ -110,6 +117,8 @@ impl AppView {
window.push_notification(note, cx);
}),
];
// The window's appearance is the one to follow (the app's, before a window, may not be).
crate::prefs::apply_theme(Some(window), cx);
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));
@@ -131,7 +140,19 @@ impl AppView {
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)
// Light or dark at a click; Settings → This app has "as Windows" too.
let dark = cx.theme().is_dark();
let theme = Button::new("theme-toggle")
.ghost()
.xsmall()
.icon(if dark { IconName::Sun } else { IconName::Moon })
.tooltip(if dark { "Light theme" } else { "Dark theme" })
.on_click(move |_, _, cx| {
let choice = if dark { crate::prefs::ThemeChoice::Light } else { crate::prefs::ThemeChoice::Dark };
crate::prefs::change(cx, |p| p.theme = choice);
});
let header = SidebarHeader::new().child(div().h_flex().w_full().justify_between().items_center().child(widgets::brand(cx)).child(theme));
Sidebar::new("pages").header(header).child(SidebarGroup::new("Proxy Suite").child(SidebarMenu::new().children(items))).footer(footer)
}
}
+48 -3
View File
@@ -1,7 +1,9 @@
//! The overview: the local proxy, the DPI bypass and the Telegram proxy, each with its state
//! and a switch; what the service warns of.
//! and a switch; what the service warns of; Proxy Suite's version, and a newer one to install.
use gpui_kit::assets::IconName;
use gpui_kit::component::alert::Alert;
use gpui_kit::component::button::{Button, ButtonVariants as _};
use gpui_kit::component::switch::Switch;
use gpui_kit::component::*;
use gpui_kit::prelude::FluentBuilder as _;
@@ -11,7 +13,7 @@ use serde_json::Value;
use super::AppView;
use super::widgets::{card, fact, hint, page, state_tag};
use crate::model::{Connection, Model};
use crate::model::{Connection, Model, Update};
fn text(v: &Value) -> SharedString {
match v {
@@ -138,5 +140,48 @@ pub fn render(model: &Entity<Model>, _: &mut Window, cx: &mut Context<AppView>)
.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()))
body.child(proxy).child(div().h_flex().gap_4().items_start().child(dpi.flex_1()).child(telegram.flex_1())).child(updates(model, cx))
}
/// The version, and the newest release when it is newer: installed from here by the service.
fn updates(model: &Entity<Model>, cx: &mut Context<AppView>) -> Div {
let m = model.read(cx);
let update = m.update().clone();
let busy = matches!(update, Update::Checking | Update::Installing { .. });
let check = {
let model = model.clone();
Button::new("update-check")
.small()
.ghost()
.icon(IconName::RefreshCw)
.label("Check for updates")
.disabled(busy)
.on_click(move |_, _, cx| model.update(cx, |m, cx| m.check_update(cx)))
};
let card = card(format!("Proxy Suite {}", m.version()), Some(check.into_any_element()), cx);
let explain = "The service fetches its setup program from the project's releases, checks its SHA-256 and runs it: the service and this app close for a moment and start again, new. Settings stay.";
match update {
Update::Unknown if !cx.global::<crate::prefs::Prefs>().check_updates => card.child(hint("Updates are not looked for by themselves (Settings → This app).", cx)),
Update::Unknown => card.child(hint("Updates are looked for when the app starts, and daily.", cx)),
Update::Checking => card.child(hint("Looking for a newer release…", cx)),
Update::Newest => card.child(hint("This is the newest release.", cx)),
Update::Failed(e) => card.child(div().text_sm().text_color(cx.theme().danger).child(format!("Could not look for updates: {e}"))),
Update::Available { version, page } => {
let install = {
let model = model.clone();
Button::new("update-install")
.small()
.primary()
.icon(IconName::Download)
.label(format!("Install {version}"))
.on_click(move |_, _, cx| model.update(cx, |m, cx| m.install_update(cx)))
};
let notes = Button::new("update-notes").small().ghost().icon(IconName::ExternalLink).label("What's new").on_click(move |_, _, cx| cx.open_url(&page));
card.child(div().h_flex().gap_3().items_center().child(div().text_sm().font_semibold().child(format!("{version} is out."))).child(install).child(notes)).child(hint(explain, cx))
}
Update::Installing { version, started: false, .. } => card.child(Alert::info("update-fetching", format!("Fetching {version} and checking it…"))),
Update::Installing { version, started: true, .. } => {
card.child(Alert::info("update-running", format!("Installing {version}: this app closes, and opens again in a moment.")))
}
}
}
+30 -4
View File
@@ -1,10 +1,12 @@
//! 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.
//! Settings: this app's own (its look, updates), and 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::radio::RadioGroup;
use gpui_kit::component::switch::Switch;
use gpui_kit::component::*;
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
@@ -14,6 +16,7 @@ use serde_json::Value;
use super::widgets::{card, hint, page};
use crate::model::Model;
use crate::prefs::{self, Prefs, ThemeChoice};
/// What the service shows in place of a secret the caller may not read; saved back as it is,
/// the secret keeps its value.
@@ -152,6 +155,29 @@ fn issue_list(issues: &[Issue], cx: &App) -> Div {
list
}
/// The app's own preferences, this user's: not the service's configuration.
fn this_app(cx: &App) -> Div {
let p = cx.global::<Prefs>().clone();
let theme = RadioGroup::horizontal("app-theme")
.children(ThemeChoice::ALL.map(|(_, label)| label))
.selected_index(ThemeChoice::ALL.iter().position(|(t, _)| *t == p.theme))
.on_change(|ix, _, cx| {
let choice = ThemeChoice::ALL[*ix].0;
prefs::change(cx, |p| p.theme = choice);
});
let updates = Switch::new("app-check-updates")
.label("Look for a newer release when the app starts, and daily")
.checked(p.check_updates)
.on_change(|on, _, cx| {
let on = *on;
prefs::change(cx, |p| p.check_updates = on);
});
card("This app", None, cx)
.child(div().h_flex().gap_4().items_center().child(div().text_sm().w(px(110.)).text_color(cx.theme().muted_foreground).child("Theme")).child(theme))
.child(updates)
.child(hint("Yours alone, kept with your Windows account; the service's configuration is below.", cx))
}
impl Render for SettingsPage {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let text = self.editor.read(cx).value();
@@ -179,7 +205,7 @@ impl Render for SettingsPage {
.child(issue_list(issues, cx)),
};
page("Settings", cx).child(
page("Settings", cx).child(this_app(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)))