windows: the app's skeleton: the service from GPUI, an overview
- bridge: ps-client on a tokio runtime of its own, awaited from GPUI's executor; log following as a channel that reconnects. - model: status polled every 2 s (outbounds every fifth round and on a reconnect), the zapret presets and tg links on connecting, and changes sent through ps-client's edits; what came of each is a notification, the service's own words when it refuses or cannot apply. - The window: a sidebar of pages; the overview shows the local proxy, the DPI bypass and the Telegram proxy with their states and switches, and what the service warns of. The other pages come next. - Icons: the components' own and the few the app adds, not all of Lucide. - zapret's engines by upstream's names (zapret-discord-youtube, zapret2). - gui-shot.sh can click before the shot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
63aede0dc1
commit
d3ba00087d
11 files changed
+654
-21
No files matched your search
Generated
+6
@@ -4956,7 +4956,13 @@ dependencies = [
|
|||||||
name = "ps-gui"
|
name = "ps-gui"
|
||||||
version = "0.1.0-pre.2"
|
version = "0.1.0-pre.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"async-channel",
|
||||||
"gpui-kit",
|
"gpui-kit",
|
||||||
|
"ps-client",
|
||||||
|
"ps-ipc",
|
||||||
|
"serde_json",
|
||||||
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -194,10 +194,11 @@ pub fn set_zapret_enabled(c: &mut Value, on: bool) {
|
|||||||
c["zapret"]["enable"] = on.into();
|
c["zapret"]["enable"] = on.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The DPI bypass's engine: `zapret` (Flowseal's presets) or `zapret2`.
|
/// The DPI bypass's engine, by upstream's names: `zapret-discord-youtube` (Flowseal's
|
||||||
|
/// presets) or `zapret2`.
|
||||||
pub fn set_zapret_engine(c: &mut Value, engine: &str) -> Result<()> {
|
pub fn set_zapret_engine(c: &mut Value, engine: &str) -> Result<()> {
|
||||||
if !matches!(engine, "zapret" | "zapret2") {
|
if !matches!(engine, "zapret-discord-youtube" | "zapret2") {
|
||||||
bail!("the engine is zapret or zapret2");
|
bail!("the engine is zapret-discord-youtube or zapret2");
|
||||||
}
|
}
|
||||||
c["zapret"]["engine"] = engine.into();
|
c["zapret"]["engine"] = engine.into();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -11,3 +11,9 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gpui-kit = { version = "0.8.1", features = ["tree-sitter"] }
|
gpui-kit = { version = "0.8.1", features = ["tree-sitter"] }
|
||||||
|
ps-client.workspace = true
|
||||||
|
ps-ipc.workspace = true
|
||||||
|
anyhow.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
tokio.workspace = true
|
||||||
|
async-channel = "2"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
//! The icons: the components' own (`Assets`), and the few more the app uses, embedded one by
|
||||||
|
//! one rather than the whole Lucide catalogue.
|
||||||
|
|
||||||
|
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]);
|
||||||
|
|
||||||
|
pub struct AppAssets;
|
||||||
|
|
||||||
|
impl AssetSource for AppAssets {
|
||||||
|
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
|
||||||
|
match Extra.load(path)? {
|
||||||
|
Some(bytes) => Ok(Some(bytes)),
|
||||||
|
None => gpui_kit::assets::Assets.load(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
||||||
|
let mut paths = gpui_kit::assets::Assets.list(path)?;
|
||||||
|
paths.extend(Extra.list(path)?);
|
||||||
|
paths.sort();
|
||||||
|
paths.dedup();
|
||||||
|
Ok(paths)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
//! The service, from the app's side: ps-client on a tokio runtime of its own (the transport is
|
||||||
|
//! tokio's), its answers awaited from GPUI's executor. A tokio `JoinHandle` is a plain future,
|
||||||
|
//! so either side can await it.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use anyhow::{Result, anyhow};
|
||||||
|
use ps_client::{Client, Saved};
|
||||||
|
use ps_ipc::Request;
|
||||||
|
use ps_ipc::transport::Address;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
/// A log line, or the follow ending (it starts again by itself).
|
||||||
|
pub enum LogEvent {
|
||||||
|
Line { unit: String, line: String },
|
||||||
|
Lost(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Bridge {
|
||||||
|
rt: Arc<tokio::runtime::Runtime>,
|
||||||
|
client: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bridge {
|
||||||
|
pub fn start(addr: Address) -> Self {
|
||||||
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.worker_threads(2)
|
||||||
|
.thread_name("proxy-suite-ipc")
|
||||||
|
.enable_all()
|
||||||
|
.build()
|
||||||
|
.expect("a tokio runtime");
|
||||||
|
Self { rt: Arc::new(rt), client: Client::new(addr) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn call(&self, req: Request) -> impl Future<Output = Result<Value>> + 'static {
|
||||||
|
let client = self.client.clone();
|
||||||
|
let task = self.rt.spawn(async move { client.call(req).await });
|
||||||
|
async move { task.await.map_err(|e| anyhow!("{e}"))? }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A configuration edit, made again on a newer configuration when another change came
|
||||||
|
/// first ([`Client::edit`]).
|
||||||
|
pub fn edit(&self, edit: impl Fn(&mut Value) -> Result<()> + Send + Sync + 'static) -> impl Future<Output = Result<Saved>> + 'static {
|
||||||
|
let client = self.client.clone();
|
||||||
|
let task = self.rt.spawn(async move { client.edit(edit).await });
|
||||||
|
async move { task.await.map_err(|e| anyhow!("{e}"))? }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every unit's log, the last `lines` and each new line, until the receiver is dropped.
|
||||||
|
/// A lost connection is said, then made again.
|
||||||
|
pub fn follow_logs(&self, lines: usize) -> async_channel::Receiver<LogEvent> {
|
||||||
|
let (tx, rx) = async_channel::unbounded();
|
||||||
|
let client = self.client.clone();
|
||||||
|
self.rt.spawn(async move {
|
||||||
|
let mut lines = lines;
|
||||||
|
loop {
|
||||||
|
let ended = client
|
||||||
|
.logs(None, lines, true, |unit, line| tx.try_send(LogEvent::Line { unit: unit.into(), line: line.into() }).is_ok())
|
||||||
|
.await;
|
||||||
|
if tx.is_closed() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let why = ended.err().map(|e| e.to_string()).unwrap_or_else(|| "the service ended the log".into());
|
||||||
|
if tx.try_send(LogEvent::Lost(why)).is_err() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// What came before the break was seen; only what comes after is wanted.
|
||||||
|
lines = 0;
|
||||||
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rx
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +1,43 @@
|
|||||||
//! proxy-suite: the desktop app. A client of the service, as proxy-ctl is.
|
//! 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.
|
||||||
|
//!
|
||||||
|
//! proxy-suite [--socket ADDRESS] (the service's pipe or socket, as proxy-ctl takes it)
|
||||||
|
|
||||||
#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")]
|
#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use gpui_kit::component::button::*;
|
mod assets;
|
||||||
use gpui_kit::component::*;
|
mod bridge;
|
||||||
|
mod model;
|
||||||
|
mod ui;
|
||||||
|
|
||||||
use gpui_kit::*;
|
use gpui_kit::*;
|
||||||
|
use ps_ipc::transport::Address;
|
||||||
|
|
||||||
struct Hello;
|
fn address() -> Address {
|
||||||
|
let mut args = std::env::args().skip(1);
|
||||||
impl Render for Hello {
|
while let Some(arg) = args.next() {
|
||||||
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
|
if arg == "--socket"
|
||||||
div()
|
&& let Some(s) = args.next()
|
||||||
.v_flex()
|
{
|
||||||
.gap_2()
|
return if cfg!(windows) { Address::Pipe(s) } else { Address::Unix(s.into()) };
|
||||||
.size_full()
|
}
|
||||||
.items_center()
|
|
||||||
.justify_center()
|
|
||||||
.child("Proxy Suite")
|
|
||||||
.child(Button::new("ok").primary().label("On"))
|
|
||||||
}
|
}
|
||||||
|
Address::default_for_platform()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
gpui_kit::application().with_assets(gpui_kit::assets::Assets).run(|cx| {
|
let bridge = bridge::Bridge::start(address());
|
||||||
|
gpui_kit::application().with_assets(assets::AppAssets).run(move |cx| {
|
||||||
gpui_kit::init(cx);
|
gpui_kit::init(cx);
|
||||||
gpui_kit::open_window(WindowOptions::default(), cx, |_, cx| cx.new(|_| Hello)).expect("opening the window");
|
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");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
//! 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 anyhow::{Result, bail};
|
||||||
|
use gpui_kit::*;
|
||||||
|
use ps_client::edits;
|
||||||
|
use ps_ipc::Request;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use crate::bridge::Bridge;
|
||||||
|
|
||||||
|
/// What a change came to.
|
||||||
|
pub enum Outcome {
|
||||||
|
Done(SharedString),
|
||||||
|
Failed(SharedString),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub enum Connection {
|
||||||
|
Connecting,
|
||||||
|
Up,
|
||||||
|
/// Why the service cannot be reached.
|
||||||
|
Down(SharedString),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Model {
|
||||||
|
bridge: Bridge,
|
||||||
|
connection: Connection,
|
||||||
|
status: Value,
|
||||||
|
outbounds: Value,
|
||||||
|
presets: Vec<SharedString>,
|
||||||
|
tg_links: Vec<SharedString>,
|
||||||
|
/// Changes sent and not yet answered.
|
||||||
|
pending: usize,
|
||||||
|
_poll: Task<()>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<Outcome> for Model {}
|
||||||
|
|
||||||
|
const POLL: Duration = Duration::from_secs(2);
|
||||||
|
|
||||||
|
impl Model {
|
||||||
|
pub fn new(bridge: Bridge, cx: &mut Context<Self>) -> Self {
|
||||||
|
let poller = bridge.clone();
|
||||||
|
let poll = cx.spawn(async move |this, cx| {
|
||||||
|
let mut round = 0u32;
|
||||||
|
loop {
|
||||||
|
let status = poller.call(Request::Status).await;
|
||||||
|
// Outbounds change less often than states; every fifth round, and on a reconnect.
|
||||||
|
let reconnect = this.read_with(cx, |m, _| m.connection != Connection::Up).unwrap_or(false);
|
||||||
|
let outbounds = if round % 5 == 0 || reconnect { Some(poller.call(Request::Outbounds).await) } else { None };
|
||||||
|
let alive = this.update(cx, |m, cx| {
|
||||||
|
m.take_status(status, cx);
|
||||||
|
if let Some(Ok(o)) = outbounds {
|
||||||
|
m.outbounds = o;
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
if alive.is_err() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
round += 1;
|
||||||
|
cx.background_executor().timer(POLL).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Self {
|
||||||
|
bridge,
|
||||||
|
connection: Connection::Connecting,
|
||||||
|
status: Value::Null,
|
||||||
|
outbounds: Value::Null,
|
||||||
|
presets: Vec::new(),
|
||||||
|
tg_links: Vec::new(),
|
||||||
|
pending: 0,
|
||||||
|
_poll: poll,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn take_status(&mut self, status: Result<Value>, cx: &mut Context<Self>) {
|
||||||
|
match status {
|
||||||
|
Ok(s) => {
|
||||||
|
let was_up = self.connection == Connection::Up;
|
||||||
|
self.status = s;
|
||||||
|
self.connection = Connection::Up;
|
||||||
|
if !was_up {
|
||||||
|
self.load_presets(cx);
|
||||||
|
self.load_tg_links(cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => self.connection = Connection::Down(format!("{e:#}").into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bridge(&self) -> &Bridge {
|
||||||
|
&self.bridge
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn connection(&self) -> &Connection {
|
||||||
|
&self.connection
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn status(&self) -> &Value {
|
||||||
|
&self.status
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn outbounds(&self) -> &Value {
|
||||||
|
&self.outbounds
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn presets(&self) -> &[SharedString] {
|
||||||
|
&self.presets
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tg_links(&self) -> &[SharedString] {
|
||||||
|
&self.tg_links
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn busy(&self) -> bool {
|
||||||
|
self.pending > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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);
|
||||||
|
let outbounds = self.bridge.call(Request::Outbounds);
|
||||||
|
cx.spawn(async move |this, cx| {
|
||||||
|
let (status, outbounds) = (status.await, outbounds.await);
|
||||||
|
this.update(cx, |m, cx| {
|
||||||
|
m.take_status(status, cx);
|
||||||
|
if let Ok(o) = outbounds {
|
||||||
|
m.outbounds = o;
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_presets(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let job = self.bridge.call(Request::ZapretPresets);
|
||||||
|
cx.spawn(async move |this, cx| {
|
||||||
|
if let Ok(r) = job.await {
|
||||||
|
let presets = r["presets"].as_array().into_iter().flatten().filter_map(Value::as_str).map(|p| SharedString::from(p.to_owned())).collect();
|
||||||
|
this.update(cx, |m, cx| {
|
||||||
|
m.presets = presets;
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// tg-ws-proxy's links: none without the secrets scope.
|
||||||
|
pub fn load_tg_links(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let job = self.bridge.call(Request::TgLinks);
|
||||||
|
cx.spawn(async move |this, cx| {
|
||||||
|
let links = job.await.map(|r| r["links"].as_array().into_iter().flatten().filter_map(Value::as_str).map(|l| SharedString::from(l.to_owned())).collect()).unwrap_or_default();
|
||||||
|
this.update(cx, |m, cx| {
|
||||||
|
m.tg_links = links;
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Runs `job`, says what came of it, and refreshes.
|
||||||
|
pub fn track(&mut self, what: impl Into<SharedString>, job: impl Future<Output = Result<()>> + 'static, cx: &mut Context<Self>) {
|
||||||
|
let what = what.into();
|
||||||
|
self.pending += 1;
|
||||||
|
cx.notify();
|
||||||
|
cx.spawn(async move |this, cx| {
|
||||||
|
let result = job.await;
|
||||||
|
this.update(cx, |m, cx| {
|
||||||
|
m.pending -= 1;
|
||||||
|
cx.emit(match result {
|
||||||
|
Ok(()) => Outcome::Done(what),
|
||||||
|
Err(e) => Outcome::Failed(format!("{what}: {e:#}").into()),
|
||||||
|
});
|
||||||
|
m.refresh(cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A configuration change. Saved but not applied is a failure: the user should hear why.
|
||||||
|
pub fn edit(&mut self, what: impl Into<SharedString>, edit: impl Fn(&mut Value) -> Result<()> + Send + Sync + 'static, cx: &mut Context<Self>) {
|
||||||
|
let job = self.bridge.edit(edit);
|
||||||
|
self.track(
|
||||||
|
what,
|
||||||
|
async move {
|
||||||
|
if let Some(e) = job.await?.apply_error {
|
||||||
|
bail!("saved, but not applied: {e}");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn request(&mut self, what: impl Into<SharedString>, req: Request, cx: &mut Context<Self>) {
|
||||||
|
let job = self.bridge.call(req);
|
||||||
|
self.track(what, async move { job.await.map(drop) }, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The local proxy on (in the configuration too, as proxy-ctl's `proxy on`) or off.
|
||||||
|
pub fn set_proxy(&mut self, on: bool, cx: &mut Context<Self>) {
|
||||||
|
let bridge = self.bridge.clone();
|
||||||
|
let job = async move {
|
||||||
|
if on {
|
||||||
|
let saved = bridge
|
||||||
|
.edit(|c| {
|
||||||
|
edits::set_proxy_enabled(c, true);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
if let Some(e) = saved.apply_error {
|
||||||
|
bail!("saved, but not applied: {e}");
|
||||||
|
}
|
||||||
|
bridge.call(Request::Start { unit: "proxy-suite-socks".into() }).await?;
|
||||||
|
} else {
|
||||||
|
bridge.call(Request::Stop { unit: "proxy-suite-socks".into() }).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
self.track(if on { "The proxy is on" } else { "The proxy is off" }, job, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
//! The window: a sidebar of pages, the page shown, and what came of each change as a
|
||||||
|
//! notification.
|
||||||
|
|
||||||
|
mod overview;
|
||||||
|
mod widgets;
|
||||||
|
|
||||||
|
use gpui_kit::component::notification::Notification;
|
||||||
|
use gpui_kit::component::sidebar::{Sidebar, SidebarGroup, SidebarHeader, SidebarMenu, SidebarMenuItem};
|
||||||
|
use gpui_kit::assets::IconName;
|
||||||
|
use gpui_kit::component::*;
|
||||||
|
use gpui_kit::*;
|
||||||
|
|
||||||
|
use crate::model::{Model, Outcome};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum Page {
|
||||||
|
Overview,
|
||||||
|
Dpi,
|
||||||
|
Telegram,
|
||||||
|
Outbounds,
|
||||||
|
Logs,
|
||||||
|
Settings,
|
||||||
|
Components,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Page {
|
||||||
|
const ALL: [Page; 7] = [Page::Overview, Page::Dpi, Page::Telegram, Page::Outbounds, Page::Logs, Page::Settings, Page::Components];
|
||||||
|
|
||||||
|
fn title(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Page::Overview => "Overview",
|
||||||
|
Page::Dpi => "DPI bypass",
|
||||||
|
Page::Telegram => "Telegram proxy",
|
||||||
|
Page::Outbounds => "Outbounds",
|
||||||
|
Page::Logs => "Logs",
|
||||||
|
Page::Settings => "Settings",
|
||||||
|
Page::Components => "Components",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn icon(self) -> IconName {
|
||||||
|
match self {
|
||||||
|
Page::Overview => IconName::LayoutDashboard,
|
||||||
|
Page::Dpi => IconName::Shield,
|
||||||
|
Page::Telegram => IconName::Send,
|
||||||
|
Page::Outbounds => IconName::Globe,
|
||||||
|
Page::Logs => IconName::SquareTerminal,
|
||||||
|
Page::Settings => IconName::Settings,
|
||||||
|
Page::Components => IconName::Package,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AppView {
|
||||||
|
model: Entity<Model>,
|
||||||
|
page: Page,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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()),
|
||||||
|
cx.subscribe_in(&model, window, |_, _, outcome: &Outcome, window, cx| {
|
||||||
|
let note = match outcome {
|
||||||
|
Outcome::Done(m) => Notification::success(m.clone()),
|
||||||
|
Outcome::Failed(m) => Notification::error(m.clone()).autohide(false),
|
||||||
|
};
|
||||||
|
window.push_notification(note, cx);
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
Self { model, page: Page::Overview, _subscriptions: subscriptions }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let items = Page::ALL.map(|page| {
|
||||||
|
SidebarMenuItem::new(page.title()).icon(page.icon()).active(self.page == page).on_click(cx.listener(move |this, _, _, cx| {
|
||||||
|
this.page = page;
|
||||||
|
cx.notify();
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
Sidebar::new("pages").header(SidebarHeader::new().child(widgets::brand(cx))).child(SidebarGroup::new("Proxy Suite").child(SidebarMenu::new().children(items)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for AppView {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let page = match self.page {
|
||||||
|
Page::Overview => overview::render(&self.model, window, cx).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()
|
||||||
|
.h_flex()
|
||||||
|
.size_full()
|
||||||
|
.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))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
//! The overview: the local proxy, the DPI bypass and the Telegram proxy, each with its state
|
||||||
|
//! and a switch; what the service warns of.
|
||||||
|
|
||||||
|
use gpui_kit::component::alert::Alert;
|
||||||
|
use gpui_kit::component::switch::Switch;
|
||||||
|
use gpui_kit::component::*;
|
||||||
|
use gpui_kit::prelude::FluentBuilder as _;
|
||||||
|
use gpui_kit::*;
|
||||||
|
use ps_client::edits;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use super::AppView;
|
||||||
|
use super::widgets::{card, fact, page, state_tag};
|
||||||
|
use crate::model::{Connection, Model};
|
||||||
|
|
||||||
|
fn text(v: &Value) -> SharedString {
|
||||||
|
match v {
|
||||||
|
Value::String(s) => s.clone().into(),
|
||||||
|
Value::Null => "—".into(),
|
||||||
|
other => other.to_string().into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render(model: &Entity<Model>, _: &mut Window, cx: &mut Context<AppView>) -> Div {
|
||||||
|
let m = model.read(cx);
|
||||||
|
let s = m.status().clone();
|
||||||
|
let connection = m.connection().clone();
|
||||||
|
let mut body = page("Overview", cx);
|
||||||
|
|
||||||
|
match &connection {
|
||||||
|
Connection::Down(why) => {
|
||||||
|
body = body.child(Alert::error("service-down", format!("The Proxy Suite service cannot be reached: {why}")).title("Not connected"));
|
||||||
|
}
|
||||||
|
Connection::Connecting => body = body.child(Alert::info("connecting", "Connecting to the Proxy Suite service…")),
|
||||||
|
Connection::Up => {}
|
||||||
|
}
|
||||||
|
if connection != Connection::Up {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
if let Some(e) = s["error"].as_str() {
|
||||||
|
body = body.child(Alert::error("service-error", e.to_owned()).title("The configuration did not apply"));
|
||||||
|
}
|
||||||
|
for (i, w) in s["warnings"].as_array().into_iter().flatten().enumerate() {
|
||||||
|
body = body.child(Alert::warning(("warning", i), text(w)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let p = &s["proxy"];
|
||||||
|
let proxy_on = p["on"] == true;
|
||||||
|
let model_p = model.clone();
|
||||||
|
let proxy = card(
|
||||||
|
"Local proxy",
|
||||||
|
Some(
|
||||||
|
Switch::new("proxy-on")
|
||||||
|
.checked(proxy_on)
|
||||||
|
.on_change(move |on, _, cx| model_p.update(cx, |m, cx| m.set_proxy(*on, cx)))
|
||||||
|
.into_any_element(),
|
||||||
|
),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.child(div().h_flex().gap_2().child(state_tag(p["state"].as_str().unwrap_or("unknown"))).when(p["tun"] == true, |d| d.child(tag::Tag::info().child("global TUN"))))
|
||||||
|
.child(fact("Listening on", text(&p["listener"]), cx))
|
||||||
|
.child(fact("Backend", text(&p["backend"]), cx))
|
||||||
|
.child(fact("Mode", p["mode"].as_str().unwrap_or("default").to_owned(), cx))
|
||||||
|
.child(fact("Outbound", p["pinned"].as_str().map(|t| format!("{t} (pinned)")).unwrap_or_else(|| format!("{} selection", p["selection"].as_str().unwrap_or("?"))), cx));
|
||||||
|
|
||||||
|
let z = &s["zapret"];
|
||||||
|
let model_z = model.clone();
|
||||||
|
let dpi = card(
|
||||||
|
"DPI bypass",
|
||||||
|
Some(
|
||||||
|
Switch::new("zapret-on")
|
||||||
|
.checked(z["enabled"] == true)
|
||||||
|
.on_change(move |on, _, cx| {
|
||||||
|
let on = *on;
|
||||||
|
model_z.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,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.into_any_element(),
|
||||||
|
),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.child(div().h_flex().child(state_tag(z["state"].as_str().unwrap_or("unknown"))))
|
||||||
|
.child(fact("Engine", text(&z["engine"]), cx))
|
||||||
|
.when(z["engine"] == "zapret-discord-youtube", |d| d.child(fact("Preset", text(&z["preset"]), cx)));
|
||||||
|
|
||||||
|
let t = &s["tgWsProxy"];
|
||||||
|
let model_t = model.clone();
|
||||||
|
let telegram = card(
|
||||||
|
"Telegram proxy",
|
||||||
|
Some(
|
||||||
|
Switch::new("tg-on")
|
||||||
|
.checked(t["enabled"] == true)
|
||||||
|
.on_change(move |on, _, cx| {
|
||||||
|
let on = *on;
|
||||||
|
model_t.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,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.into_any_element(),
|
||||||
|
),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.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()))
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
//! Pieces the pages share: the page frame, cards, a unit's state as a tag.
|
||||||
|
|
||||||
|
use gpui_kit::component::tag::Tag;
|
||||||
|
use gpui_kit::assets::IconName;
|
||||||
|
use gpui_kit::component::*;
|
||||||
|
use gpui_kit::*;
|
||||||
|
|
||||||
|
pub fn brand(cx: &App) -> impl IntoElement {
|
||||||
|
div().h_flex().gap_2().items_center().child(Icon::new(IconName::Shield).text_color(cx.theme().primary)).child(div().font_semibold().child("Proxy Suite"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A bordered section of a page, titled, with what it controls on the right of the title.
|
||||||
|
pub fn card(title: impl Into<SharedString>, action: Option<AnyElement>, cx: &App) -> Div {
|
||||||
|
div()
|
||||||
|
.v_flex()
|
||||||
|
.gap_3()
|
||||||
|
.p_4()
|
||||||
|
.rounded_lg()
|
||||||
|
.border_1()
|
||||||
|
.border_color(cx.theme().border)
|
||||||
|
.bg(cx.theme().background)
|
||||||
|
.child(div().h_flex().justify_between().items_center().child(div().font_semibold().child(title.into())).children(action))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A unit's state, as the service says it, coloured by what it means.
|
||||||
|
pub fn state_tag(state: &str) -> Tag {
|
||||||
|
let tag = match state {
|
||||||
|
"active" => Tag::success(),
|
||||||
|
"activating" | "reloading" | "deactivating" => Tag::warning(),
|
||||||
|
"failed" => Tag::danger(),
|
||||||
|
_ => Tag::secondary(),
|
||||||
|
};
|
||||||
|
tag.child(state.to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A label and its value, in a row.
|
||||||
|
pub fn fact(label: &'static str, value: impl Into<SharedString>, cx: &App) -> Div {
|
||||||
|
div().h_flex().gap_2().text_sm().child(div().w(px(110.)).text_color(cx.theme().muted_foreground).child(label)).child(value.into())
|
||||||
|
}
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
#
|
#
|
||||||
# tools/gui-shot.sh OUT.png [SECONDS] [-- APP ARGS...] (APP=target/debug/proxy-suite)
|
# tools/gui-shot.sh OUT.png [SECONDS] [-- APP ARGS...] (APP=target/debug/proxy-suite)
|
||||||
#
|
#
|
||||||
# With SHOT_KEYS="key ..." the keys (xdotool names) are typed into the window before the shot.
|
# Before the shot, SHOT_CLICKS="X,Y ..." clicks those screen points, and SHOT_KEYS="key ..."
|
||||||
|
# types those keys (xdotool names), each followed by a moment for the app to answer.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
OUT=$(realpath -m "${1:?the screenshot, a .png}"); shift
|
OUT=$(realpath -m "${1:?the screenshot, a .png}"); shift
|
||||||
WAIT=6
|
WAIT=6
|
||||||
@@ -29,6 +30,10 @@ env -u WAYLAND_DISPLAY DISPLAY=":$n" VK_ICD_FILENAMES="$MESA/share/vulkan/icd.d/
|
|||||||
APID=$!
|
APID=$!
|
||||||
sleep "$WAIT"
|
sleep "$WAIT"
|
||||||
kill -0 "$APID" 2>/dev/null || { echo "the app exited:"; tail -20 "${OUT%.png}.log"; exit 1; }
|
kill -0 "$APID" 2>/dev/null || { echo "the app exited:"; tail -20 "${OUT%.png}.log"; exit 1; }
|
||||||
|
for point in ${SHOT_CLICKS:-}; do
|
||||||
|
DISPLAY=":$n" "$XDOTOOL/bin/xdotool" mousemove "${point%,*}" "${point#*,}" click 1
|
||||||
|
sleep 1.5
|
||||||
|
done
|
||||||
if [ -n "${SHOT_KEYS:-}" ]; then
|
if [ -n "${SHOT_KEYS:-}" ]; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
DISPLAY=":$n" "$XDOTOOL/bin/xdotool" key --delay 150 $SHOT_KEYS
|
DISPLAY=":$n" "$XDOTOOL/bin/xdotool" key --delay 150 $SHOT_KEYS
|
||||||
|
|||||||
Reference in new issue
Block a user