windows: the app's DPI bypass page

zapret on or off and its engine; for Flowseal's presets, the preset (the
release's own list, matched as the service matches names) and game
traffic; for zapret2, learning, IPv6 and the strategy log; the sites to
handle besides the engine's lists and the sites to leave alone; TCP
timestamps. News from the service replaces what the user has not
changed, never what they are typing; a save shows the list as saved.

ps-client: set_path for any one option, set_zapret_sites (tidied,
deduplicated). gui-shot.sh takes ordered steps: click, type, key, wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 01:30:25 +03:00
1 parent d3ba00087d
commit c9ce7a1982
6 files changed
+328 -11

No files matched your search

+44
View File
@@ -222,6 +222,39 @@ pub fn set_tg_ws_proxy_enabled(c: &mut Value, on: bool) {
c["tgWsProxy"]["enable"] = on.into();
}
/// Any option by its path, e.g. `["zapret", "zapret2", "ipv6"]`; the objects above it are
/// made when missing.
pub fn set_path(c: &mut Value, path: &[&str], value: Value) {
let mut cur = c;
for p in path {
if !cur.is_object() {
*cur = json!({});
}
cur = &mut cur[*p];
}
*cur = value;
}
/// The sites an engine also handles and those it leaves alone: for `zapret-discord-youtube`
/// beside its release's lists, for `zapret2` beside its strategies' own.
pub fn set_zapret_sites(c: &mut Value, engine: &str, domains: &[String], exclude: &[String]) -> Result<()> {
if !matches!(engine, "zapret-discord-youtube" | "zapret2") {
bail!("the engine is zapret-discord-youtube or zapret2");
}
let clean = |list: &[String]| -> Vec<Value> {
let mut out: Vec<Value> = Vec::new();
for d in list.iter().map(|d| d.trim().trim_start_matches('.').to_lowercase()).filter(|d| !d.is_empty()) {
if !out.contains(&Value::from(d.as_str())) {
out.push(d.into());
}
}
out
};
c["zapret"][engine]["domains"] = Value::Array(clean(domains));
c["zapret"][engine]["excludeDomains"] = Value::Array(clean(exclude));
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
@@ -265,6 +298,17 @@ mod tests {
assert_eq!(c["proxy"]["routing"]["rules"][0]["disabled"], true);
}
#[test]
fn paths_and_site_lists() {
let mut c = json!({ "zapret": null });
set_path(&mut c, &["zapret", "zapret2", "ipv6"], true.into());
assert_eq!(c["zapret"]["zapret2"]["ipv6"], true);
set_zapret_sites(&mut c, "zapret2", &[" .Example.com".into(), "".into(), "example.com".into()], &["bank.example".into()]).unwrap();
assert_eq!(c["zapret"]["zapret2"]["domains"], json!(["example.com"]));
assert_eq!(c["zapret"]["zapret2"]["excludeDomains"], json!(["bank.example"]));
assert!(set_zapret_sites(&mut c, "goodbyedpi", &[], &[]).is_err());
}
#[test]
fn zapret_settings_are_checked() {
let mut c = json!({});
+23
View File
@@ -30,6 +30,8 @@ pub struct Model {
connection: Connection,
status: Value,
outbounds: Value,
/// The configuration as the service gives it (secrets hidden without that scope).
config: Value,
presets: Vec<SharedString>,
tg_links: Vec<SharedString>,
/// Changes sent and not yet answered.
@@ -70,6 +72,7 @@ impl Model {
connection: Connection::Connecting,
status: Value::Null,
outbounds: Value::Null,
config: Value::Null,
presets: Vec::new(),
tg_links: Vec::new(),
pending: 0,
@@ -84,6 +87,7 @@ impl Model {
self.status = s;
self.connection = Connection::Up;
if !was_up {
self.load_config(cx);
self.load_presets(cx);
self.load_tg_links(cx);
}
@@ -108,6 +112,10 @@ impl Model {
&self.outbounds
}
pub fn config(&self) -> &Value {
&self.config
}
pub fn presets(&self) -> &[SharedString] {
&self.presets
}
@@ -138,6 +146,20 @@ impl Model {
.detach();
}
pub fn load_config(&mut self, cx: &mut Context<Self>) {
let job = self.bridge.call(Request::ConfigGet);
cx.spawn(async move |this, cx| {
if let Ok(r) = job.await {
this.update(cx, |m, cx| {
m.config = r["config"].clone();
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| {
@@ -181,6 +203,7 @@ impl Model {
Err(e) => Outcome::Failed(format!("{what}: {e:#}").into()),
});
m.refresh(cx);
m.load_config(cx);
})
.ok();
})
+238
View File
@@ -0,0 +1,238 @@
//! The DPI bypass: zapret with Flowseal's presets, or zapret2 with its strategies; and the
//! sites it handles beside the lists it comes with.
use gpui_kit::component::button::Button;
use gpui_kit::component::input::{Textarea, TextareaState};
use gpui_kit::component::radio::RadioGroup;
use gpui_kit::component::select::{Select, SelectEvent, SelectState};
use gpui_kit::component::switch::Switch;
use gpui_kit::component::*;
use gpui_kit::*;
use ps_client::edits;
use serde_json::Value;
use super::widgets::{card, hint, page, state_tag};
use crate::model::Model;
const ENGINES: [(&str, &str); 2] = [("zapret-discord-youtube", "Flowseal's presets (zapret)"), ("zapret2", "zapret2")];
const GAME_FILTERS: [(&str, &str); 4] = [("null", "Off"), ("all", "TCP and UDP"), ("tcp", "TCP only"), ("udp", "UDP only")];
/// Preset names as the service matches them: without spaces, any case.
fn same_preset(a: &str, b: &str) -> bool {
let squash = |s: &str| s.chars().filter(|c| !c.is_whitespace()).collect::<String>().to_lowercase();
squash(a) == squash(b)
}
fn lines(v: &Value) -> String {
v.as_array().into_iter().flatten().filter_map(Value::as_str).collect::<Vec<_>>().join("\n")
}
pub struct DpiPage {
model: Entity<Model>,
preset: Entity<SelectState<Vec<SharedString>>>,
presets: Vec<SharedString>,
domains: Entity<TextareaState>,
exclude: Entity<TextareaState>,
/// The engine and lists the text areas were last filled from: news from the service
/// replaces what the user has not changed, never what they have.
shown: (String, String, String),
_subscriptions: Vec<Subscription>,
}
impl DpiPage {
pub fn new(model: Entity<Model>, window: &mut Window, cx: &mut Context<Self>) -> Self {
let preset = cx.new(|cx| SelectState::new(Vec::<SharedString>::new(), None, window, cx).searchable(true));
let domains = cx.new(|cx| TextareaState::new(window, cx).rows(6).placeholder("example.com — one per line"));
let exclude = cx.new(|cx| TextareaState::new(window, cx).rows(6).placeholder("bank.example — one per line"));
let subscriptions = vec![
cx.observe_in(&model, window, |this, _, window, cx| this.sync(window, cx)),
cx.subscribe_in(&preset, window, |this, _, event: &SelectEvent<Vec<SharedString>>, _, cx| {
if let SelectEvent::Confirm(Some(name)) = event {
let name = name.to_string();
this.model.update(cx, |m, cx| {
m.edit(
format!("Preset: {name}"),
move |c| {
edits::set_zapret_preset(c, &name);
Ok(())
},
cx,
)
});
}
}),
];
let mut this = Self { model, preset, presets: Vec::new(), domains, exclude, shown: Default::default(), _subscriptions: subscriptions };
this.sync(window, cx);
this
}
fn engine(config: &Value) -> String {
config["zapret"]["engine"].as_str().unwrap_or("zapret-discord-youtube").to_owned()
}
/// Brings the controls up to what the service says.
fn sync(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let m = self.model.read(cx);
let config = m.config().clone();
let presets = m.presets().to_vec();
if config.is_null() {
return;
}
if presets != self.presets {
self.presets = presets.clone();
self.preset.update(cx, |s, cx| s.set_items(presets, window, cx));
}
let configured = config["zapret"]["zapret-discord-youtube"]["configName"].as_str().unwrap_or("");
if let Some(name) = self.presets.iter().find(|p| same_preset(p, configured)).cloned()
&& self.preset.read(cx).selected_value() != Some(&name)
{
self.preset.update(cx, |s, cx| s.set_selected_value(&name, window, cx));
}
let engine = Self::engine(&config);
let fresh = (engine.clone(), lines(&config["zapret"][&engine]["domains"]), lines(&config["zapret"][&engine]["excludeDomains"]));
if fresh != self.shown {
let switched = fresh.0 != self.shown.0;
if switched || self.domains.read(cx).value() == self.shown.1.as_str() {
let text = fresh.1.clone();
self.domains.update(cx, |s, cx| s.set_value(text, window, cx));
}
if switched || self.exclude.read(cx).value() == self.shown.2.as_str() {
let text = fresh.2.clone();
self.exclude.update(cx, |s, cx| s.set_value(text, window, cx));
}
self.shown = fresh;
}
}
fn save_sites(&mut self, cx: &mut Context<Self>) {
let split = |t: &str| t.split(['\n', ',', ' ']).map(str::to_owned).filter(|d| !d.trim().is_empty()).collect::<Vec<_>>();
let (domains_text, exclude_text) = (self.domains.read(cx).value().to_string(), self.exclude.read(cx).value().to_string());
let (domains, exclude) = (split(&domains_text), split(&exclude_text));
// Handed over: the lists the service saves (tidied) replace what was typed.
self.shown.1 = domains_text;
self.shown.2 = exclude_text;
let engine = Self::engine(self.model.read(cx).config());
self.model.update(cx, |m, cx| m.edit("Sites saved", move |c| edits::set_zapret_sites(c, &engine, &domains, &exclude), cx));
}
/// A switch for one option of the configuration, by its path.
fn option_switch(&self, id: &'static str, label: &'static str, path: &'static [&'static str], config: &Value) -> Switch {
let mut v = config;
for p in path {
v = &v[*p];
}
let model = self.model.clone();
Switch::new(id).label(label).checked(v == true).on_change(move |on, _, cx| {
let on = *on;
model.update(cx, |m, cx| {
m.edit(
format!("{label}: {}", if on { "on" } else { "off" }),
move |c| {
edits::set_path(c, path, on.into());
Ok(())
},
cx,
)
})
})
}
}
impl Render for DpiPage {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let m = self.model.read(cx);
let status = m.status()["zapret"].clone();
let config = m.config().clone();
let engine = Self::engine(&config);
let body = page("DPI bypass", cx);
if config.is_null() {
return body.child(hint("Waiting for the service…", cx));
}
let model = self.model.clone();
let enable = Switch::new("dpi-on").checked(config["zapret"]["enable"] == true).on_change(move |on, _, cx| {
let on = *on;
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,
)
})
});
let model = self.model.clone();
let engines = RadioGroup::horizontal("engine")
.children(ENGINES.map(|(_, label)| label))
.selected_index(ENGINES.iter().position(|(e, _)| *e == engine))
.on_change(move |ix, _, cx| {
let (engine, label) = ENGINES[*ix];
model.update(cx, |m, cx| m.edit(format!("Engine: {label}"), move |c| edits::set_zapret_engine(c, engine), cx));
});
let mut body = body.child(
card("zapret", Some(enable.into_any_element()), cx)
.child(div().h_flex().child(state_tag(status["state"].as_str().unwrap_or("unknown"))))
.child(engines)
.child(hint(
if engine == "zapret2" {
"zapret2 (winws2) with nfqws2-keenetic's strategies; it learns which sites are blocked as it goes."
} else {
"Flowseal's zapret-discord-youtube: winws with one of its presets, for YouTube, Discord and the sites in its lists."
},
cx,
)),
);
if engine == "zapret2" {
body = body.child(
card("zapret2", None, cx)
.child(self.option_switch("autohostlist", "Learn which sites are blocked", &["zapret", "zapret2", "autoHostlist", "enable"], &config))
.child(self.option_switch("ipv6", "IPv6 too", &["zapret", "zapret2", "ipv6"], &config))
.child(self.option_switch("strategy-log", "Log the strategy each site gets", &["zapret", "zapret2", "strategyLog"], &config)),
);
} else {
let model = self.model.clone();
let filter = config["zapret"]["zapret-discord-youtube"]["gameFilter"].as_str().unwrap_or("null");
body = body
.child(
card("Preset", None, cx)
.child(hint("One of the release's strategies. If a site still does not open, try the next one.", cx))
.child(Select::new(&self.preset).placeholder("Choose a preset").menu_max_h(px(320.))),
)
.child(
card("Game traffic", None, cx).child(hint("Also handle game traffic, on ports above 1023.", cx)).child(
RadioGroup::horizontal("game-filter")
.children(GAME_FILTERS.map(|(_, label)| label))
.selected_index(GAME_FILTERS.iter().position(|(v, _)| *v == filter))
.on_change(move |ix, _, cx| {
let (value, label) = GAME_FILTERS[*ix];
model.update(cx, |m, cx| m.edit(format!("Game traffic: {label}"), move |c| edits::set_game_filter(c, value), cx));
}),
),
);
}
body.child(
card(
"Your sites",
Some(Button::new("save-sites").small().label("Save").on_click(cx.listener(|this, _, _, cx| this.save_sites(cx))).into_any_element()),
cx,
)
.child(hint("Sites to handle besides the engine's own lists, and sites to leave alone.", cx))
.child(
div()
.h_flex()
.gap_4()
.items_start()
.child(div().v_flex().gap_1().flex_1().child(div().text_sm().child("Also handle")).child(Textarea::new(&self.domains)))
.child(div().v_flex().gap_1().flex_1().child(div().text_sm().child("Leave alone")).child(Textarea::new(&self.exclude))),
),
)
.child(card("Windows", None, cx).child(self.option_switch("tcp-timestamps", "TCP timestamps (some strategies need them)", &["zapret", "tcpTimestamps"], &config)))
}
}
+5 -1
View File
@@ -1,6 +1,7 @@
//! The window: a sidebar of pages, the page shown, and what came of each change as a
//! notification.
mod dpi;
mod overview;
mod widgets;
@@ -54,6 +55,7 @@ impl Page {
pub struct AppView {
model: Entity<Model>,
page: Page,
dpi: Entity<dpi::DpiPage>,
_subscriptions: Vec<Subscription>,
}
@@ -69,7 +71,8 @@ impl AppView {
window.push_notification(note, cx);
}),
];
Self { model, page: Page::Overview, _subscriptions: subscriptions }
let dpi = cx.new(|cx| dpi::DpiPage::new(model.clone(), window, cx));
Self { model, page: Page::Overview, dpi, _subscriptions: subscriptions }
}
fn sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
@@ -87,6 +90,7 @@ 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(),
Page::Dpi => self.dpi.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()
+5
View File
@@ -38,6 +38,11 @@ pub fn state_tag(state: &str) -> Tag {
tag.child(state.to_owned())
}
/// A quieter line of explanation.
pub fn hint(text: impl Into<SharedString>, cx: &App) -> Div {
div().text_sm().text_color(cx.theme().muted_foreground).child(text.into())
}
/// 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())
+13 -10
View File
@@ -4,8 +4,9 @@
#
# tools/gui-shot.sh OUT.png [SECONDS] [-- APP ARGS...] (APP=target/debug/proxy-suite)
#
# 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.
# Before the shot, SHOT_STEPS does what it lists, in order, each followed by a moment for the
# app to answer: "click:X,Y" (screen points), "type:TEXT" (no spaces), "key:NAME" (xdotool's
# names, e.g. ctrl+a), "wait:SECONDS".
set -euo pipefail
OUT=$(realpath -m "${1:?the screenshot, a .png}"); shift
WAIT=6
@@ -30,14 +31,16 @@ env -u WAYLAND_DISPLAY DISPLAY=":$n" VK_ICD_FILENAMES="$MESA/share/vulkan/icd.d/
APID=$!
sleep "$WAIT"
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
x() { DISPLAY=":$n" "$XDOTOOL/bin/xdotool" "$@"; }
for step in ${SHOT_STEPS:-}; do
case $step in
click:*) p=${step#click:}; x mousemove "${p%,*}" "${p#*,}" click 1 ;;
type:*) x type --delay 40 "${step#type:}" ;;
key:*) x key "${step#key:}" ;;
wait:*) sleep "${step#wait:}" ;;
*) echo "unknown step: $step"; exit 1 ;;
esac
sleep 1.2
done
if [ -n "${SHOT_KEYS:-}" ]; then
# shellcheck disable=SC2086
DISPLAY=":$n" "$XDOTOOL/bin/xdotool" key --delay 150 $SHOT_KEYS
sleep 1.5
fi
DISPLAY=":$n" "$MAGICK/bin/magick" import -window root "$OUT"
echo "$OUT"