windows: the app's tray, and its Windows build from Linux

- Tray (gpui-tray): a shield coloured by how things are (working, one
  failed, all off, no service), its tooltip saying which; the menu opens
  the window and switches the local proxy, the DPI bypass and the Telegram
  proxy, with their states checked; Quit. Closing the window leaves the
  app in the tray (no tray: it quits); --hidden starts it there.
- The app builds for Windows from Linux: GPUI compiles its HLSL shaders
  with fxc.exe only when the building machine is Windows, so its Windows
  backend is vendored with that one check made on the target instead
  (vendor/gpui-pre-windows/PATCHED.md, tools/vendor-gpui-windows.py), and
  tools/fxc-wine.sh runs Microsoft's fxc.exe under Wine: the compiler from
  the Windows SDK 10.0.26100 installer, pinned by hash, kept on the build
  machine; only the compiled shaders go into the app.
- gui-shot.sh keeps the app off the desktop's session bus.

Under Wine the app starts but cannot draw text (Wine's DirectWrite does
not implement font-set matching), so its Windows rendering is untested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 02:03:18 +03:00
1 parent a7bf347859
commit 77becc235c
35 files changed
+15691 -29

No files matched your search

+1
View File
@@ -11,6 +11,7 @@ path = "src/main.rs"
[dependencies]
gpui-kit = { version = "0.8.1", features = ["tree-sitter"] }
gpui-tray = { version = "0.3", default-features = false, features = ["gpui-kit", "menu-state"] }
ps-client.workspace = true
ps-ipc.workspace = true
anyhow.workspace = true
+25 -17
View File
@@ -2,42 +2,50 @@
//! 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)
//! proxy-suite [--socket ADDRESS] [--hidden] (the service's pipe or socket, as proxy-ctl takes
//! it; --hidden starts in the tray)
#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")]
mod assets;
mod bridge;
mod model;
mod shell;
mod ui;
use gpui_kit::*;
use ps_ipc::transport::Address;
fn address() -> Address {
struct Args {
address: Address,
/// Start in the tray, without the window (for starting at sign-in).
hidden: bool,
}
fn args() -> Args {
let mut out = Args { address: Address::default_for_platform(), hidden: false };
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()) };
match arg.as_str() {
"--socket" => {
if let Some(s) = args.next() {
out.address = if cfg!(windows) { Address::Pipe(s) } else { Address::Unix(s.into()) };
}
}
"--hidden" => out.hidden = true,
_ => {}
}
}
Address::default_for_platform()
out
}
fn main() {
let bridge = bridge::Bridge::start(address());
gpui_kit::application().with_assets(assets::AppAssets).run(move |cx| {
let args = args();
let bridge = bridge::Bridge::start(args.address);
// 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);
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");
shell::start(model, !args.hidden, cx);
});
}
+177
View File
@@ -0,0 +1,177 @@
//! The app's life: one window, opened again from the tray; the tray icon, coloured by how things
//! are, with switches in its menu; quitting. Closing the window leaves the app in the tray; with
//! no tray (a desktop without one), closing it quits.
use gpui_kit::*;
use gpui_tray::{Icon, Tray};
use ps_client::edits;
use serde_json::Value;
use crate::model::{Connection, Model};
use crate::ui::AppView;
actions!(proxy_suite, [OpenWindow, ToggleProxy, ToggleDpi, ToggleTelegram, Quit]);
struct Shell {
model: Entity<Model>,
window: Option<WindowHandle<AppView>>,
tray: Option<Tray>,
/// The icon's colour now, so it is only replaced when that changes.
colour: &'static str,
}
impl Global for Shell {}
pub fn start(model: Entity<Model>, open: bool, cx: &mut App) {
cx.on_action(open_window).on_action(toggle_proxy).on_action(toggle_dpi).on_action(toggle_telegram).on_action(quit);
cx.set_global(Shell { model: model.clone(), window: None, tray: None, colour: "" });
let mut builder = Tray::builder().tooltip("Proxy Suite").on_activate(OpenWindow).menu(menu);
if let Some(icon) = icon("#6b7280", cx) {
builder = builder.icon(icon);
}
let tray = builder.build(cx);
match tray {
Ok(tray) => cx.global_mut::<Shell>().tray = Some(tray),
Err(e) => eprintln!("proxy-suite: no tray icon ({e}); closing the window quits"),
}
cx.on_window_closed(|cx, _| {
if cx.global::<Shell>().tray.is_none() && cx.windows().is_empty() {
cx.quit();
}
})
.detach();
cx.observe(&model, |_, cx| refresh(cx)).detach();
if open || cx.global::<Shell>().tray.is_none() {
open_window(&OpenWindow, cx);
}
}
fn status(cx: &App) -> (Value, bool) {
let m = cx.global::<Shell>().model.read(cx);
(m.status().clone(), *m.connection() == Connection::Up)
}
/// How things are, as a colour: working, something failed, all off, no service.
fn colour(cx: &App) -> &'static str {
let (s, up) = status(cx);
if !up {
return "#dc2626";
}
let parts = [(&s["proxy"]["on"], &s["proxy"]["state"]), (&s["zapret"]["enabled"], &s["zapret"]["state"]), (&s["tgWsProxy"]["enabled"], &s["tgWsProxy"]["state"])];
let wanted: Vec<&Value> = parts.iter().filter(|(on, _)| **on == true).map(|(_, state)| *state).collect();
if wanted.is_empty() {
"#6b7280"
} else if wanted.iter().any(|state| **state == "failed") {
"#d97706"
} else {
"#16a34a"
}
}
/// A filled shield, the app's mark, in `fill`.
fn icon(fill: &str, cx: &App) -> Option<Icon> {
let svg = format!(
r##"<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path d="M12 2.2 4.2 5.1v6.1c0 4.9 3.3 9.1 7.8 10.6 4.5-1.5 7.8-5.7 7.8-10.6V5.1Z" fill="{fill}" stroke="#ffffff" stroke-width="1.4" stroke-linejoin="round"/></svg>"##
);
Icon::from_gpui(&Image::from_bytes(ImageFormat::Svg, svg.into_bytes()), cx).build().inspect_err(|e| eprintln!("proxy-suite: the tray icon: {e}")).ok()
}
fn refresh(cx: &mut App) {
let Some(tray) = cx.global::<Shell>().tray.clone() else { return };
let fill = colour(cx);
if fill != cx.global::<Shell>().colour {
cx.global_mut::<Shell>().colour = fill;
if let Some(icon) = icon(fill, cx)
&& let Err(e) = tray.set_icon(icon, cx)
{
eprintln!("proxy-suite: the tray icon: {e}");
}
}
let (s, up) = status(cx);
let tip = if up {
let on = |v: &Value| if *v == true { "on" } else { "off" };
format!("Proxy Suite — proxy {}, DPI bypass {}, Telegram proxy {}", on(&s["proxy"]["on"]), on(&s["zapret"]["enabled"]), on(&s["tgWsProxy"]["enabled"]))
} else {
"Proxy Suite — the service is not running".into()
};
let _ = tray.set_tooltip(Some(tip), cx);
let _ = tray.refresh_menu(cx);
}
fn menu(cx: &mut App) -> Vec<MenuItem> {
let (s, up) = status(cx);
vec![
MenuItem::action("Open Proxy Suite", OpenWindow),
MenuItem::separator(),
MenuItem::action("Local proxy", ToggleProxy).checked(s["proxy"]["on"] == true).disabled(!up),
MenuItem::action("DPI bypass", ToggleDpi).checked(s["zapret"]["enabled"] == true).disabled(!up),
MenuItem::action("Telegram proxy", ToggleTelegram).checked(s["tgWsProxy"]["enabled"] == true).disabled(!up),
MenuItem::separator(),
MenuItem::action("Quit", Quit),
]
}
fn open_window(_: &OpenWindow, cx: &mut App) {
if let Some(window) = cx.global::<Shell>().window
&& window.update(cx, |_, window, _| window.activate_window()).is_ok()
{
return;
}
let model = cx.global::<Shell>().model.clone();
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()
};
match gpui_kit::open_window(options, cx, |window, cx| cx.new(|cx| AppView::new(model, window, cx))) {
Ok((window, _)) => cx.global_mut::<Shell>().window = window.downcast(),
Err(e) => eprintln!("proxy-suite: opening the window: {e}"),
}
}
fn toggle_proxy(_: &ToggleProxy, cx: &mut App) {
let model = cx.global::<Shell>().model.clone();
let on = model.read(cx).status()["proxy"]["on"] == true;
model.update(cx, |m, cx| m.set_proxy(!on, cx));
}
fn toggle_dpi(_: &ToggleDpi, cx: &mut App) {
let model = cx.global::<Shell>().model.clone();
let on = model.read(cx).status()["zapret"]["enabled"] != true;
model.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,
)
});
}
fn toggle_telegram(_: &ToggleTelegram, cx: &mut App) {
let model = cx.global::<Shell>().model.clone();
let on = model.read(cx).status()["tgWsProxy"]["enabled"] != true;
model.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,
)
});
}
fn quit(_: &Quit, cx: &mut App) {
if let Some(tray) = cx.global::<Shell>().tray.clone() {
let _ = tray.close(cx);
}
cx.quit();
}