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
@@ -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))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user