windows: the app's Telegram proxy page

tg-ws-proxy on or off and its state; its tg:// links, to copy or open in
Telegram (none without the secrets scope, and the page says so); whether
other devices may connect; its port and fake-TLS domain (which adds the
ee link). Long links are cut short rather than widening the page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 01:33:10 +03:00
1 parent c9ce7a1982
commit 7dfb3129f4
4 files changed
+170 -3

No files matched your search

+1
View File
@@ -204,6 +204,7 @@ impl Model {
});
m.refresh(cx);
m.load_config(cx);
m.load_tg_links(cx);
})
.ok();
})
+6 -2
View File
@@ -3,6 +3,7 @@
mod dpi;
mod overview;
mod telegram;
mod widgets;
use gpui_kit::component::notification::Notification;
@@ -56,6 +57,7 @@ pub struct AppView {
model: Entity<Model>,
page: Page,
dpi: Entity<dpi::DpiPage>,
telegram: Entity<telegram::TelegramPage>,
_subscriptions: Vec<Subscription>,
}
@@ -72,7 +74,8 @@ impl AppView {
}),
];
let dpi = cx.new(|cx| dpi::DpiPage::new(model.clone(), window, cx));
Self { model, page: Page::Overview, dpi, _subscriptions: subscriptions }
let telegram = cx.new(|cx| telegram::TelegramPage::new(model.clone(), window, cx));
Self { model, page: Page::Overview, dpi, telegram, _subscriptions: subscriptions }
}
fn sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
@@ -91,6 +94,7 @@ impl Render for AppView {
let page = match self.page {
Page::Overview => overview::render(&self.model, window, cx).into_any_element(),
Page::Dpi => self.dpi.clone().into_any_element(),
Page::Telegram => self.telegram.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()
@@ -99,6 +103,6 @@ impl Render for AppView {
.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))
.child(div().id("page").flex_1().min_w_0().h_full().overflow_y_scroll().child(page))
}
}
+161
View File
@@ -0,0 +1,161 @@
//! The Telegram proxy (Flowseal's tg-ws-proxy): on or off, the links to open in Telegram, and
//! where it listens.
use gpui_kit::assets::IconName;
use gpui_kit::component::button::{Button, ButtonVariants as _};
use gpui_kit::component::input::{Input, InputState};
use gpui_kit::component::notification::Notification;
use gpui_kit::component::switch::Switch;
use gpui_kit::component::*;
use gpui_kit::*;
use ps_client::edits;
use serde_json::{Value, json};
use super::widgets::{card, hint, page, state_tag};
use crate::model::Model;
pub struct TelegramPage {
model: Entity<Model>,
port: Entity<InputState>,
fake_tls: Entity<InputState>,
/// The port and domain the inputs were last filled from (see the DPI page's `shown`).
shown: (String, String),
_subscriptions: Vec<Subscription>,
}
impl TelegramPage {
pub fn new(model: Entity<Model>, window: &mut Window, cx: &mut Context<Self>) -> Self {
let port = cx.new(|cx| InputState::new(window, cx).placeholder("1443"));
let fake_tls = cx.new(|cx| InputState::new(window, cx).placeholder("none"));
let subscriptions = vec![cx.observe_in(&model, window, |this, _, window, cx| this.sync(window, cx))];
let mut this = Self { model, port, fake_tls, shown: Default::default(), _subscriptions: subscriptions };
this.sync(window, cx);
this
}
fn sync(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let t = self.model.read(cx).config()["tgWsProxy"].clone();
if t.is_null() {
return;
}
let fresh = (t["listener"]["port"].to_string(), t["fakeTlsDomain"].as_str().unwrap_or("").to_owned());
if fresh != self.shown {
if self.port.read(cx).value() == self.shown.0.as_str() {
let v = fresh.0.clone();
self.port.update(cx, |s, cx| s.set_value(v, window, cx));
}
if self.fake_tls.read(cx).value() == self.shown.1.as_str() {
let v = fresh.1.clone();
self.fake_tls.update(cx, |s, cx| s.set_value(v, window, cx));
}
self.shown = fresh;
}
}
fn save(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let port_text = self.port.read(cx).value().trim().to_owned();
let Ok(port) = port_text.parse::<u16>() else {
window.push_notification(Notification::error(format!("“{port_text}” is not a port (1–65535)")), cx);
return;
};
let domain = self.fake_tls.read(cx).value().trim().to_owned();
self.shown = (self.port.read(cx).value().to_string(), self.fake_tls.read(cx).value().to_string());
self.model.update(cx, |m, cx| {
m.edit(
"Telegram proxy saved",
move |c| {
edits::set_path(c, &["tgWsProxy", "listener", "port"], port.into());
edits::set_path(c, &["tgWsProxy", "fakeTlsDomain"], if domain.is_empty() { Value::Null } else { domain.clone().into() });
Ok(())
},
cx,
)
});
}
}
impl Render for TelegramPage {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let m = self.model.read(cx);
let status = m.status()["tgWsProxy"].clone();
let t = m.config()["tgWsProxy"].clone();
let links = m.tg_links().to_vec();
let body = page("Telegram proxy", cx);
if t.is_null() {
return body.child(hint("Waiting for the service…", cx));
}
let model = self.model.clone();
let enable = Switch::new("tg-enable").checked(t["enable"] == true).on_change(move |on, _, cx| {
let on = *on;
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,
)
})
});
let mut link_card = card("Links", None, cx).child(hint("Open one in Telegram, or copy it to a phone: Telegram then connects through this proxy.", cx));
if links.is_empty() {
link_card = link_card.child(hint("No links: reading them needs the secrets scope (userControl).", cx));
}
for (i, link) in links.into_iter().enumerate() {
let (copy, open) = (link.clone(), link.clone());
link_card = link_card.child(
div()
.h_flex()
.gap_2()
.items_center()
.child(div().flex_1().min_w_0().truncate().text_sm().font_family("monospace").child(link))
.child(Button::new(("copy-link", i)).small().icon(IconName::Copy).label("Copy").on_click(move |_, window, cx| {
cx.write_to_clipboard(ClipboardItem::new_string(copy.to_string()));
window.push_notification(Notification::success("Copied"), cx);
}))
.child(Button::new(("open-link", i)).small().primary().icon(IconName::Send).label("Open in Telegram").on_click(move |_, _, cx| cx.open_url(&open))),
);
}
let shared = t["listener"]["address"] == "0.0.0.0";
let model = self.model.clone();
let lan = Switch::new("tg-lan").label("Let other devices on this network connect (phones, other computers)").checked(shared).on_change(move |on, _, cx| {
let address = if *on { "0.0.0.0" } else { "127.0.0.1" };
model.update(cx, |m, cx| {
m.edit(
if address == "0.0.0.0" { "Other devices may connect" } else { "Only this computer may connect" },
move |c| {
edits::set_path(c, &["tgWsProxy", "listener", "address"], json!(address));
Ok(())
},
cx,
)
})
});
body.child(
card("tg-ws-proxy", Some(enable.into_any_element()), cx)
.child(div().h_flex().child(state_tag(status["state"].as_str().unwrap_or("unknown"))))
.child(hint("Telegram over WebSocket to its own servers, for networks that block its usual connections.", cx)),
)
.child(link_card)
.child(
card(
"Listening",
Some(Button::new("tg-save").small().label("Save").on_click(cx.listener(|this, _, window, cx| this.save(window, cx))).into_any_element()),
cx,
)
.child(lan)
.child(
div()
.h_flex()
.gap_4()
.child(div().v_flex().gap_1().w(px(160.)).child(div().text_sm().child("Port")).child(Input::new(&self.port)))
.child(div().v_flex().gap_1().flex_1().child(div().text_sm().child("Fake-TLS domain (ee links)")).child(Input::new(&self.fake_tls))),
),
)
}
}
+2 -1
View File
@@ -11,7 +11,7 @@ pub fn brand(cx: &App) -> impl IntoElement {
/// 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))
div().v_flex().gap_4().p_6().w_full().min_w_0().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.
@@ -20,6 +20,7 @@ pub fn card(title: impl Into<SharedString>, action: Option<AnyElement>, cx: &App
.v_flex()
.gap_3()
.p_4()
.min_w_0()
.rounded_lg()
.border_1()
.border_color(cx.theme().border)