windows: the app's whitelist-bypass page, and its icon
A page for whitelist-bypass: on or off; joiners with their state and the call link to join; creators with theirs, their call link to copy, a new call, and their login (a cookies export picked from disk, or DION's and Bitrix's email and password); adding and removing either. The app carries an icon now (tools/make-icon.py draws it; llvm-rc makes it the exe's resource 1, where GPUI, Explorer and the Start Menu take it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b6e54f963d
commit
ae31e499ca
8 files changed
+524
-4
No files matched your search
@@ -235,6 +235,39 @@ pub fn set_path(c: &mut Value, path: &[&str], value: Value) {
|
||||
*cur = value;
|
||||
}
|
||||
|
||||
/// whitelist-bypass's platforms, as its options name them.
|
||||
pub const WL_PLATFORMS: [&str; 5] = ["wbstream", "telemost", "dion", "bitrix", "vk"];
|
||||
|
||||
/// A whitelist-bypass joiner or creator (`role`: "joiners" or "creators") on `platform`. A name
|
||||
/// is one of either: `proxy-ctl wl` takes them by name alone.
|
||||
pub fn add_wl(c: &mut Value, role: &str, name: &str, platform: &str) -> Result<()> {
|
||||
if !matches!(role, "joiners" | "creators") {
|
||||
bail!("a whitelist-bypass role is joiners or creators");
|
||||
}
|
||||
if !ps_core::config::path_name_ok(name) {
|
||||
bail!("a name takes letters, digits, '.', '_' and '-', and no leading dot");
|
||||
}
|
||||
if !WL_PLATFORMS.contains(&platform) {
|
||||
bail!("no platform '{platform}': {}", WL_PLATFORMS.join(", "));
|
||||
}
|
||||
if role == "joiners" && platform == "vk" {
|
||||
bail!("VK has no joiner, only creators");
|
||||
}
|
||||
let wl = &c["whitelistBypass"];
|
||||
if wl["joiners"].get(name).is_some() || wl["creators"].get(name).is_some() {
|
||||
bail!("'{name}' is taken");
|
||||
}
|
||||
set_path(c, &["whitelistBypass", role, name], json!({ "platform": platform }));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_wl(c: &mut Value, role: &str, name: &str) -> Result<()> {
|
||||
match c.get_mut("whitelistBypass").and_then(|w| w.get_mut(role)).and_then(Value::as_object_mut).and_then(|o| o.remove(name)) {
|
||||
Some(_) => Ok(()),
|
||||
None => bail!("no whitelist-bypass {} '{name}'", role.trim_end_matches('s')),
|
||||
}
|
||||
}
|
||||
|
||||
/// 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<()> {
|
||||
@@ -259,6 +292,22 @@ pub fn set_zapret_sites(c: &mut Value, engine: &str, domains: &[String], exclude
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn whitelist_bypass_entries_are_added_once_and_removed() {
|
||||
let mut c = json!({});
|
||||
add_wl(&mut c, "joiners", "wl", "wbstream").unwrap();
|
||||
add_wl(&mut c, "creators", "laptop", "vk").unwrap();
|
||||
assert_eq!(c["whitelistBypass"]["joiners"]["wl"], json!({ "platform": "wbstream" }));
|
||||
assert!(add_wl(&mut c, "creators", "wl", "dion").is_err(), "a name is one of either");
|
||||
assert!(add_wl(&mut c, "joiners", "phone", "vk").is_err(), "VK has no joiner");
|
||||
assert!(add_wl(&mut c, "joiners", "phone", "zoom").is_err());
|
||||
assert!(add_wl(&mut c, "joiners", "../x", "wbstream").is_err());
|
||||
assert!(add_wl(&mut c, "joiners", "CON", "wbstream").is_err());
|
||||
remove_wl(&mut c, "joiners", "wl").unwrap();
|
||||
assert!(remove_wl(&mut c, "joiners", "wl").is_err());
|
||||
assert_eq!(c["whitelistBypass"]["creators"]["laptop"]["platform"], "vk");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outbounds_are_added_once_and_removed() {
|
||||
let mut c = json!({});
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
@@ -0,0 +1,33 @@
|
||||
//! The Windows build carries the app's icon as its resource 1, where GPUI loads its windows'
|
||||
//! icon from (and Explorer, the Start Menu and Settings > Apps show it). The resource compiler
|
||||
//! is LLVM's (`llvm-rc`, in the dev shell; `RC` names another); without one the app builds
|
||||
//! with Windows' default icon, and says so.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let icon = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("assets/proxy-suite.ico");
|
||||
println!("cargo:rerun-if-changed={}", icon.display());
|
||||
println!("cargo:rerun-if-env-changed=RC");
|
||||
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
||||
return;
|
||||
}
|
||||
let out = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
let rc = out.join("app.rc");
|
||||
let res = out.join("app.res");
|
||||
// The resource script's strings are C strings: backslashes doubled.
|
||||
std::fs::write(&rc, format!("1 ICON \"{}\"\n", icon.display().to_string().replace('\\', "\\\\"))).unwrap();
|
||||
let compiler = std::env::var("RC").unwrap_or_else(|_| if cfg!(windows) { "rc.exe".into() } else { "llvm-rc".into() });
|
||||
let mut command = Command::new(&compiler);
|
||||
command.arg("/nologo");
|
||||
if compiler.contains("llvm-rc") {
|
||||
// Nothing to preprocess, so no C compiler needed for it.
|
||||
command.arg("/no-preprocess");
|
||||
}
|
||||
match command.arg("/fo").arg(&res).arg(&rc).status() {
|
||||
Ok(s) if s.success() => println!("cargo:rustc-link-arg-bins={}", res.display()),
|
||||
Ok(s) => println!("cargo:warning=the app's icon: {compiler} failed ({s}); building without it"),
|
||||
Err(e) => println!("cargo:warning=the app's icon: no {compiler} ({e}); building without it"),
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ 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]);
|
||||
gpui_kit::assets::icon_assets!(Extra, [Shield, Send, Package, Pin, PinOff, RefreshCw, Save, Trash, Plus, Copy, Download, Link, Gauge, Power, Video, FileUp]);
|
||||
|
||||
pub struct AppAssets;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ mod outbounds;
|
||||
mod overview;
|
||||
mod settings;
|
||||
mod telegram;
|
||||
mod whitelist;
|
||||
mod widgets;
|
||||
|
||||
use gpui_kit::component::notification::Notification;
|
||||
@@ -23,6 +24,7 @@ pub enum Page {
|
||||
Overview,
|
||||
Dpi,
|
||||
Telegram,
|
||||
Whitelist,
|
||||
Outbounds,
|
||||
Logs,
|
||||
Settings,
|
||||
@@ -30,13 +32,14 @@ pub enum Page {
|
||||
}
|
||||
|
||||
impl Page {
|
||||
const ALL: [Page; 7] = [Page::Overview, Page::Dpi, Page::Telegram, Page::Outbounds, Page::Logs, Page::Settings, Page::Components];
|
||||
const ALL: [Page; 8] = [Page::Overview, Page::Dpi, Page::Telegram, Page::Whitelist, 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::Whitelist => "Whitelist bypass",
|
||||
Page::Outbounds => "Outbounds",
|
||||
Page::Logs => "Logs",
|
||||
Page::Settings => "Settings",
|
||||
@@ -49,6 +52,7 @@ impl Page {
|
||||
Page::Overview => IconName::LayoutDashboard,
|
||||
Page::Dpi => IconName::Shield,
|
||||
Page::Telegram => IconName::Send,
|
||||
Page::Whitelist => IconName::Video,
|
||||
Page::Outbounds => IconName::Globe,
|
||||
Page::Logs => IconName::SquareTerminal,
|
||||
Page::Settings => IconName::Settings,
|
||||
@@ -63,6 +67,8 @@ pub struct AppView {
|
||||
dpi: Entity<dpi::DpiPage>,
|
||||
telegram: Entity<telegram::TelegramPage>,
|
||||
outbounds: Entity<outbounds::OutboundsPage>,
|
||||
/// Made when first shown.
|
||||
whitelist: Option<Entity<whitelist::WhitelistPage>>,
|
||||
/// Made when first shown: following the logs starts then.
|
||||
logs: Option<Entity<logs::LogsPage>>,
|
||||
/// Made when first shown, as it loads the configuration into its editor then.
|
||||
@@ -86,7 +92,7 @@ impl AppView {
|
||||
let dpi = cx.new(|cx| dpi::DpiPage::new(model.clone(), window, cx));
|
||||
let telegram = cx.new(|cx| telegram::TelegramPage::new(model.clone(), window, cx));
|
||||
let outbounds = cx.new(|cx| outbounds::OutboundsPage::new(model.clone(), window, cx));
|
||||
Self { model, page: Page::Overview, dpi, telegram, outbounds, logs: None, settings: None, components: None, _subscriptions: subscriptions }
|
||||
Self { model, page: Page::Overview, dpi, telegram, outbounds, whitelist: None, logs: None, settings: None, components: None, _subscriptions: subscriptions }
|
||||
}
|
||||
|
||||
fn sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
@@ -114,6 +120,10 @@ impl Render for AppView {
|
||||
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(),
|
||||
Page::Whitelist => {
|
||||
let model = self.model.clone();
|
||||
self.whitelist.get_or_insert_with(|| cx.new(|cx| whitelist::WhitelistPage::new(model, window, cx))).clone().into_any_element()
|
||||
}
|
||||
Page::Outbounds => self.outbounds.clone().into_any_element(),
|
||||
Page::Logs => {
|
||||
let model = self.model.clone();
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
//! whitelist-bypass: its joiners (outbounds of the proxy, through a video call) and creators
|
||||
//! (the calls' other ends), their state; a joiner's call link given, a creator's shown, its
|
||||
//! login given (a cookies export, or DION's and Bitrix's email and password); which there are.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
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::radio::RadioGroup;
|
||||
use gpui_kit::component::switch::Switch;
|
||||
use gpui_kit::component::*;
|
||||
use gpui_kit::*;
|
||||
use ps_client::edits;
|
||||
use ps_ipc::Request;
|
||||
use serde_json::Value;
|
||||
|
||||
use super::widgets::{card, hint, page, state_tag};
|
||||
use crate::model::Model;
|
||||
|
||||
const PLATFORMS: [(&str, &str); 5] = [("wbstream", "WB Stream"), ("telemost", "Telemost"), ("dion", "DION"), ("bitrix", "Bitrix24"), ("vk", "VK (creators only)")];
|
||||
|
||||
/// A creator's login by email and password, for the platforms that take one.
|
||||
struct PasswordLogin {
|
||||
email: Entity<InputState>,
|
||||
password: Entity<InputState>,
|
||||
/// Bitrix only: the portal's address.
|
||||
portal: Option<Entity<InputState>>,
|
||||
}
|
||||
|
||||
pub struct WhitelistPage {
|
||||
model: Entity<Model>,
|
||||
name: Entity<InputState>,
|
||||
platform: usize,
|
||||
/// Each joiner's link input, by name.
|
||||
joins: BTreeMap<String, Entity<InputState>>,
|
||||
/// DION's and Bitrix's creators' login inputs, by name.
|
||||
logins: BTreeMap<String, PasswordLogin>,
|
||||
/// Each creator's call link, or why there is none, once asked for.
|
||||
links: BTreeMap<String, Result<String, String>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl WhitelistPage {
|
||||
pub fn new(model: Entity<Model>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let name = cx.new(|cx| InputState::new(window, cx).placeholder("laptop"));
|
||||
let subscriptions = vec![cx.observe_in(&model, window, |this, _, window, cx| this.sync(window, cx))];
|
||||
let mut this = Self { model, name, platform: 0, joins: BTreeMap::new(), logins: BTreeMap::new(), links: BTreeMap::new(), _subscriptions: subscriptions };
|
||||
this.sync(window, cx);
|
||||
this
|
||||
}
|
||||
|
||||
/// Inputs for the creators and joiners there are now.
|
||||
fn sync(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let w = self.model.read(cx).config()["whitelistBypass"].clone();
|
||||
let joiners: Vec<String> = w["joiners"].as_object().map(|o| o.keys().cloned().collect()).unwrap_or_default();
|
||||
self.joins.retain(|n, _| joiners.contains(n));
|
||||
for n in joiners {
|
||||
self.joins.entry(n).or_insert_with(|| cx.new(|cx| InputState::new(window, cx).placeholder("the creator's call link")));
|
||||
}
|
||||
let creators: Vec<(String, String)> =
|
||||
w["creators"].as_object().map(|o| o.iter().map(|(n, c)| (n.clone(), c["platform"].as_str().unwrap_or("").to_owned())).collect()).unwrap_or_default();
|
||||
self.logins.retain(|n, _| creators.iter().any(|(c, p)| c == n && matches!(p.as_str(), "dion" | "bitrix")));
|
||||
for (n, platform) in creators {
|
||||
if matches!(platform.as_str(), "dion" | "bitrix") && !self.logins.contains_key(&n) {
|
||||
let login = PasswordLogin {
|
||||
email: cx.new(|cx| InputState::new(window, cx).placeholder("email")),
|
||||
password: cx.new(|cx| InputState::new(window, cx).placeholder("password").masked(true)),
|
||||
portal: (platform == "bitrix").then(|| cx.new(|cx| InputState::new(window, cx).placeholder("portal.bitrix24.ru"))),
|
||||
};
|
||||
self.logins.insert(n, login);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add(&mut self, role: &'static str, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let name = self.name.read(cx).value().trim().to_owned();
|
||||
let platform = PLATFORMS[self.platform].0;
|
||||
// Checked here first, for a message at once.
|
||||
if let Err(e) = edits::add_wl(&mut Value::Null, role, &name, platform) {
|
||||
window.push_notification(Notification::error(format!("{e:#}")), cx);
|
||||
return;
|
||||
}
|
||||
self.name.update(cx, |s, cx| s.set_value("", window, cx));
|
||||
let what = format!("{} '{name}' added", if role == "joiners" { "Joiner" } else { "Creator" });
|
||||
self.model.update(cx, |m, cx| m.edit(what, move |c| edits::add_wl(c, role, &name, platform), cx));
|
||||
}
|
||||
|
||||
fn join(&mut self, name: String, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let Some(input) = self.joins.get(&name) else { return };
|
||||
let link = input.read(cx).value().trim().to_owned();
|
||||
if link.is_empty() {
|
||||
window.push_notification(Notification::error("Paste the link the creator's side gave (its proxy-ctl wl link)"), cx);
|
||||
return;
|
||||
}
|
||||
input.update(cx, |s, cx| s.set_value("", window, cx));
|
||||
self.model.update(cx, |m, cx| m.request(format!("'{name}' joins the call"), Request::WlJoin { name, link }, cx));
|
||||
}
|
||||
|
||||
fn link(&mut self, name: String, cx: &mut Context<Self>) {
|
||||
let job = self.model.read(cx).bridge().call(Request::WlLink { name: name.clone() });
|
||||
cx.spawn(async move |this, cx| {
|
||||
let r = job.await.map(|v| v["link"].as_str().unwrap_or("").to_owned()).map_err(|e| format!("{e:#}"));
|
||||
this.update(cx, |this, cx| {
|
||||
this.links.insert(name, r);
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
/// A cookies export, chosen: read here, as the signed-in user, and handed to the service.
|
||||
fn cookies(&mut self, name: String, cx: &mut Context<Self>) {
|
||||
let paths = cx.prompt_for_paths(PathPromptOptions { files: true, directories: false, multiple: false, prompt: Some("Log in".into()) });
|
||||
let model = self.model.clone();
|
||||
cx.spawn(async move |_, cx| {
|
||||
let Ok(Ok(Some(paths))) = paths.await else { return };
|
||||
let Some(path) = paths.into_iter().next() else { return };
|
||||
let login = std::fs::read_to_string(&path);
|
||||
model.update(cx, |m, cx| match login {
|
||||
Ok(login) => m.request(format!("'{name}' has its login"), Request::WlAuth { name, login }, cx),
|
||||
Err(e) => m.track(format!("Reading {}", path.display()), async move { Err(e.into()) }, cx),
|
||||
});
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn password_login(&mut self, name: String, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let Some(l) = self.logins.get(&name) else { return };
|
||||
let mut login = serde_json::Map::new();
|
||||
login.insert("email".into(), l.email.read(cx).value().trim().into());
|
||||
login.insert("password".into(), l.password.read(cx).value().to_string().into());
|
||||
if let Some(p) = &l.portal {
|
||||
let portal = p.read(cx).value().trim().trim_end_matches('/').to_owned();
|
||||
login.insert("portal".into(), if portal.contains("://") { portal } else { format!("https://{portal}") }.into());
|
||||
}
|
||||
if login.values().any(|v| v.as_str().is_none_or(str::is_empty) || v == "https://") {
|
||||
window.push_notification(Notification::error("Fill in every field"), cx);
|
||||
return;
|
||||
}
|
||||
l.password.update(cx, |s, cx| s.set_value("", window, cx));
|
||||
let login = Value::Object(login).to_string();
|
||||
self.model.update(cx, |m, cx| m.request(format!("'{name}' has its login"), Request::WlAuth { name, login }, cx));
|
||||
}
|
||||
|
||||
fn remove(&mut self, role: &'static str, name: String, cx: &mut Context<Self>) {
|
||||
self.model.update(cx, |m, cx| m.edit(format!("'{name}' removed"), move |c| edits::remove_wl(c, role, &name), cx));
|
||||
}
|
||||
}
|
||||
|
||||
/// A unit's state from the service's status, "off" when whitelist-bypass is.
|
||||
fn unit_state(status: &Value, unit: &str, on: bool) -> String {
|
||||
if !on {
|
||||
return "off".into();
|
||||
}
|
||||
status["units"].as_array().into_iter().flatten().find(|u| u["name"] == unit).and_then(|u| u["state"].as_str()).unwrap_or("waiting").to_owned()
|
||||
}
|
||||
|
||||
fn platform_label(p: &str) -> &str {
|
||||
PLATFORMS.iter().find(|(id, _)| *id == p).map_or(p, |(_, label)| label.trim_end_matches(" (creators only)"))
|
||||
}
|
||||
|
||||
impl Render for WhitelistPage {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let m = self.model.read(cx);
|
||||
let w = m.config()["whitelistBypass"].clone();
|
||||
let status = m.status().clone();
|
||||
let body = page("Whitelist bypass", cx);
|
||||
if m.config().is_null() {
|
||||
return body.child(hint("Waiting for the service…", cx));
|
||||
}
|
||||
let on = w["enable"] == true;
|
||||
|
||||
let model = self.model.clone();
|
||||
let enable = Switch::new("wl-enable").checked(on).on_change(move |on, _, cx| {
|
||||
let on = *on;
|
||||
model.update(cx, |m, cx| {
|
||||
m.edit(
|
||||
if on { "Whitelist bypass is on" } else { "Whitelist bypass is off" },
|
||||
move |c| {
|
||||
edits::set_path(c, &["whitelistBypass", "enable"], on.into());
|
||||
Ok(())
|
||||
},
|
||||
cx,
|
||||
)
|
||||
})
|
||||
});
|
||||
let about = card("whitelist-bypass", Some(enable.into_any_element()), cx).child(hint(
|
||||
"For networks that let only a whitelist through, video calls among it: a joiner here tunnels the proxy's traffic through a call that a creator, on a machine with normal internet, holds open. Pin the joiner's outbound (Outbounds) to send traffic through it.",
|
||||
cx,
|
||||
));
|
||||
|
||||
let mut joiners = card("Joiners", None, cx).child(hint("Each is an outbound of the proxy, named as here. It joins the call whose link its creator gives.", cx));
|
||||
let joiner_list: Vec<(String, String)> =
|
||||
w["joiners"].as_object().map(|o| o.iter().map(|(n, j)| (n.clone(), j["platform"].as_str().unwrap_or("").to_owned())).collect()).unwrap_or_default();
|
||||
if joiner_list.is_empty() {
|
||||
joiners = joiners.child(hint("None yet: add one below.", cx));
|
||||
}
|
||||
for (i, (name, platform)) in joiner_list.into_iter().enumerate() {
|
||||
let Some(input) = self.joins.get(&name) else { continue };
|
||||
let state = unit_state(&status, &format!("proxy-suite-wb-joiner-{name}"), on);
|
||||
let (n1, n2) = (name.clone(), name.clone());
|
||||
joiners = joiners.child(
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_2()
|
||||
.py_2()
|
||||
.border_t_1()
|
||||
.border_color(cx.theme().border)
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_3()
|
||||
.items_center()
|
||||
.child(div().font_medium().child(name.clone()))
|
||||
.child(div().text_sm().text_color(cx.theme().muted_foreground).child(platform_label(&platform).to_owned()))
|
||||
.child(state_tag(&state))
|
||||
.child(div().flex_1())
|
||||
.child(Button::new(("wl-remove-joiner", i)).small().ghost().icon(IconName::Trash).on_click(cx.listener(move |this, _, _, cx| this.remove("joiners", n1.clone(), cx)))),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_2()
|
||||
.child(div().flex_1().min_w_0().child(Input::new(input)))
|
||||
.child(Button::new(("wl-join", i)).small().primary().label("Join").on_click(cx.listener(move |this, _, window, cx| this.join(n2.clone(), window, cx)))),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
let mut creators = card("Creators", None, cx).child(hint(
|
||||
"On the machine with normal internet. Each logs in to its platform (a cookies export from the desktop Creator app or a browser; DION and Bitrix take an email and password), starts a call and keeps it: give its link to the joiner.",
|
||||
cx,
|
||||
));
|
||||
let creator_list: Vec<(String, String)> =
|
||||
w["creators"].as_object().map(|o| o.iter().map(|(n, c)| (n.clone(), c["platform"].as_str().unwrap_or("").to_owned())).collect()).unwrap_or_default();
|
||||
if creator_list.is_empty() {
|
||||
creators = creators.child(hint("None here.", cx));
|
||||
}
|
||||
for (i, (name, platform)) in creator_list.into_iter().enumerate() {
|
||||
let state = unit_state(&status, &format!("proxy-suite-wb-creator-{name}"), on);
|
||||
let (n1, n2, n3, n4, n5) = (name.clone(), name.clone(), name.clone(), name.clone(), name.clone());
|
||||
let mut row = div()
|
||||
.v_flex()
|
||||
.gap_2()
|
||||
.py_2()
|
||||
.border_t_1()
|
||||
.border_color(cx.theme().border)
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_3()
|
||||
.items_center()
|
||||
.child(div().font_medium().child(name.clone()))
|
||||
.child(div().text_sm().text_color(cx.theme().muted_foreground).child(platform_label(&platform).to_owned()))
|
||||
.child(state_tag(&state))
|
||||
.child(div().flex_1())
|
||||
.child(Button::new(("wl-link", i)).small().icon(IconName::Link).label("Call link").on_click(cx.listener(move |this, _, _, cx| this.link(n1.clone(), cx))))
|
||||
.child(Button::new(("wl-new", i)).small().icon(IconName::RefreshCw).label("New call").on_click(cx.listener(move |this, _, _, cx| {
|
||||
this.links.remove(&n2);
|
||||
let name = n2.clone();
|
||||
this.model.update(cx, |m, cx| m.request(format!("'{name}' starts a new call"), Request::WlNew { name }, cx));
|
||||
})))
|
||||
.child(Button::new(("wl-cookies", i)).small().icon(IconName::FileUp).label("Cookies file…").on_click(cx.listener(move |this, _, _, cx| this.cookies(n3.clone(), cx))))
|
||||
.child(Button::new(("wl-remove-creator", i)).small().ghost().icon(IconName::Trash).on_click(cx.listener(move |this, _, _, cx| this.remove("creators", n4.clone(), cx)))),
|
||||
);
|
||||
match self.links.get(&name) {
|
||||
Some(Ok(link)) => {
|
||||
let copy = link.clone();
|
||||
row = row.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_2()
|
||||
.items_center()
|
||||
.child(div().flex_1().min_w_0().truncate().text_sm().font_family("monospace").child(link.clone()))
|
||||
.child(Button::new(("wl-copy", i)).small().icon(IconName::Copy).label("Copy").on_click(move |_, window, cx| {
|
||||
cx.write_to_clipboard(ClipboardItem::new_string(copy.clone()));
|
||||
window.push_notification(Notification::success("Copied"), cx);
|
||||
})),
|
||||
);
|
||||
}
|
||||
Some(Err(e)) => row = row.child(hint(e.clone(), cx)),
|
||||
None => {}
|
||||
}
|
||||
if let Some(l) = self.logins.get(&name) {
|
||||
let mut fields = div().h_flex().gap_2().child(div().flex_1().min_w_0().child(Input::new(&l.email))).child(div().flex_1().min_w_0().child(Input::new(&l.password)));
|
||||
if let Some(p) = &l.portal {
|
||||
fields = fields.child(div().flex_1().min_w_0().child(Input::new(p)));
|
||||
}
|
||||
row = row.child(fields.child(Button::new(("wl-login", i)).small().primary().label("Log in").on_click(cx.listener(move |this, _, window, cx| this.password_login(n5.clone(), window, cx)))));
|
||||
}
|
||||
creators = creators.child(row);
|
||||
}
|
||||
|
||||
let platforms = RadioGroup::horizontal("wl-platform")
|
||||
.children(PLATFORMS.map(|(_, label)| label))
|
||||
.selected_index(Some(self.platform))
|
||||
.on_change(cx.listener(|this, ix: &usize, _, cx| {
|
||||
this.platform = *ix;
|
||||
cx.notify();
|
||||
}));
|
||||
let add = card("Add", None, cx)
|
||||
.child(div().v_flex().gap_1().child(div().text_sm().child("Name (letters, digits, '.', '_', '-')")).child(Input::new(&self.name)))
|
||||
.child(platforms)
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_2()
|
||||
.child(Button::new("wl-add-joiner").small().icon(IconName::Plus).label("Add a joiner").on_click(cx.listener(|this, _, window, cx| this.add("joiners", window, cx))))
|
||||
.child(Button::new("wl-add-creator").small().icon(IconName::Plus).label("Add a creator").on_click(cx.listener(|this, _, window, cx| this.add("creators", window, cx)))),
|
||||
)
|
||||
.child(hint("Their other options (linkFile, cookiesFile, upstream, resources) are in Settings, under whitelistBypass.", cx));
|
||||
|
||||
body.child(about).child(joiners).child(creators).child(add)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
#
|
||||
# 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".
|
||||
# names, e.g. ctrl+a), "scroll:X,Y" (ten steps down, there), "wait:SECONDS".
|
||||
set -euo pipefail
|
||||
OUT=$(realpath -m "${1:?the screenshot, a .png}"); shift
|
||||
WAIT=6
|
||||
@@ -36,6 +36,7 @@ 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 ;;
|
||||
scroll:*) p=${step#scroll:}; x mousemove "${p%,*}" "${p#*,}" click --repeat 10 5 ;;
|
||||
type:*) x type --delay 40 "${step#type:}" ;;
|
||||
key:*) x key "${step#key:}" ;;
|
||||
wait:*) sleep "${step#wait:}" ;;
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env python3
|
||||
"""The app's icon, crates/ps-gui/assets/proxy-suite.ico: a shield with a check mark (the tray's
|
||||
shield, in the app's blue), drawn here at every size Windows asks for, antialiased, with no
|
||||
image library. The .ico it writes is committed; run this again only to change it.
|
||||
|
||||
python3 -I tools/make-icon.py
|
||||
"""
|
||||
|
||||
import math
|
||||
import pathlib
|
||||
import struct
|
||||
import zlib
|
||||
|
||||
BLUE = (37, 99, 235)
|
||||
WHITE = (255, 255, 255)
|
||||
SIZES = [16, 20, 24, 32, 40, 48, 64, 256]
|
||||
SAMPLES = 4 # per axis, per pixel
|
||||
|
||||
|
||||
def cubic(p0, p1, p2, p3, steps=24):
|
||||
out = []
|
||||
for i in range(1, steps + 1):
|
||||
t = i / steps
|
||||
u = 1 - t
|
||||
out.append(tuple(u**3 * a + 3 * u * u * t * b + 3 * u * t * t * c + t**3 * d for a, b, c, d in zip(p0, p1, p2, p3)))
|
||||
return out
|
||||
|
||||
|
||||
# Lucide's shield, on its 24-unit grid, as a polygon.
|
||||
SHIELD = [(12.0, 2.2)]
|
||||
SHIELD += cubic((12.0, 2.2), (14.6, 4.4), (17.2, 5.1), (19.8, 5.1))
|
||||
SHIELD += [(19.8, 13.0)]
|
||||
SHIELD += cubic((19.8, 13.0), (19.8, 18.2), (16.4, 20.6), (12.0, 22.0))
|
||||
SHIELD += cubic((12.0, 22.0), (7.6, 20.6), (4.2, 18.2), (4.2, 13.0))
|
||||
SHIELD += [(4.2, 5.1)]
|
||||
SHIELD += cubic((4.2, 5.1), (6.8, 5.1), (9.4, 4.4), (12.0, 2.2))
|
||||
CHECK = [(8.3, 12.3), (11.0, 15.0), (15.9, 9.6)]
|
||||
CHECK_HALF_WIDTH = 1.15
|
||||
|
||||
|
||||
def inside(poly, x, y):
|
||||
hit = False
|
||||
for (x1, y1), (x2, y2) in zip(poly, poly[1:] + poly[:1]):
|
||||
if (y1 > y) != (y2 > y) and x < x1 + (y - y1) * (x2 - x1) / (y2 - y1):
|
||||
hit = not hit
|
||||
return hit
|
||||
|
||||
|
||||
def near_check(x, y):
|
||||
for (x1, y1), (x2, y2) in zip(CHECK, CHECK[1:]):
|
||||
dx, dy = x2 - x1, y2 - y1
|
||||
t = max(0.0, min(1.0, ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy)))
|
||||
if math.hypot(x - (x1 + t * dx), y - (y1 + t * dy)) <= CHECK_HALF_WIDTH:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def render(size):
|
||||
"""RGBA rows, top first."""
|
||||
rows = []
|
||||
scale = 24 / size
|
||||
for py in range(size):
|
||||
row = bytearray()
|
||||
for px in range(size):
|
||||
shield = check = 0
|
||||
for sy in range(SAMPLES):
|
||||
for sx in range(SAMPLES):
|
||||
x = (px + (sx + 0.5) / SAMPLES) * scale
|
||||
y = (py + (sy + 0.5) / SAMPLES) * scale
|
||||
if inside(SHIELD, x, y):
|
||||
shield += 1
|
||||
check += near_check(x, y)
|
||||
n = SAMPLES * SAMPLES
|
||||
alpha = shield / n
|
||||
if shield:
|
||||
w = check / shield
|
||||
colour = [round(b * (1 - w) + f * w) for b, f in zip(BLUE, WHITE)]
|
||||
else:
|
||||
colour = [0, 0, 0]
|
||||
row += bytes(colour + [round(alpha * 255)])
|
||||
rows.append(bytes(row))
|
||||
return rows
|
||||
|
||||
|
||||
def png(size, rows):
|
||||
def chunk(kind, data):
|
||||
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data))
|
||||
|
||||
raw = b"".join(b"\x00" + r for r in rows)
|
||||
ihdr = struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0)
|
||||
return b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", ihdr) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
|
||||
|
||||
|
||||
def main():
|
||||
images = [png(s, render(s)) for s in SIZES]
|
||||
header = struct.pack("<HHH", 0, 1, len(images))
|
||||
offset = 6 + 16 * len(images)
|
||||
entries = b""
|
||||
for s, data in zip(SIZES, images):
|
||||
entries += struct.pack("<BBBBHHII", s % 256, s % 256, 0, 0, 1, 32, len(data), offset)
|
||||
offset += len(data)
|
||||
out = pathlib.Path(__file__).resolve().parent.parent / "crates/ps-gui/assets/proxy-suite.ico"
|
||||
out.parent.mkdir(exist_ok=True)
|
||||
out.write_bytes(header + entries + b"".join(images))
|
||||
print(f"{out}: {out.stat().st_size} bytes, sizes {SIZES}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user