diff --git a/windows/crates/ps-gui/src/main.rs b/windows/crates/ps-gui/src/main.rs index 0d53dc9..9562e11 100644 --- a/windows/crates/ps-gui/src/main.rs +++ b/windows/crates/ps-gui/src/main.rs @@ -48,6 +48,7 @@ fn main() { gpui_kit::application().with_assets(assets::AppAssets).with_quit_mode(QuitMode::Explicit).run(move |cx| { gpui_kit::init(cx); cx.set_global(prefs::load()); + prefs::tune_dark(cx); prefs::apply_theme(None, cx); let model = cx.new(|cx| model::Model::new(bridge, cx)); shell::start(model, !args.hidden, cx); diff --git a/windows/crates/ps-gui/src/prefs.rs b/windows/crates/ps-gui/src/prefs.rs index b7f2a37..00d63fd 100644 --- a/windows/crates/ps-gui/src/prefs.rs +++ b/windows/crates/ps-gui/src/prefs.rs @@ -4,6 +4,7 @@ //! In `%APPDATA%\ProxySuite\app.json` (elsewhere `$XDG_CONFIG_HOME/proxy-suite/app.json`). use std::path::PathBuf; +use std::rc::Rc; use gpui_kit::component::{Theme, ThemeMode}; use gpui_kit::*; @@ -76,6 +77,18 @@ pub fn change(cx: &mut App, edit: impl FnOnce(&mut Prefs)) { cx.refresh_windows(); } +/// Controls that are off all but vanish on the dark theme's near-black page: its switch, a +/// near-black thumb on a #404040 track, gets a lighter track (the thumb stays dark: it is the +/// on switch's too, on a white track); unchecked radio buttons and checkboxes, and text +/// fields, a lighter edge than #2f2f2f. +pub fn tune_dark(cx: &mut App) { + let theme = Theme::global_mut(cx); + let mut dark = (*theme.dark_theme).clone(); + dark.colors.switch = Some("#737373".into()); + dark.colors.input = Some("#525252".into()); + theme.dark_theme = Rc::new(dark); +} + /// The theme the preference picks: Windows' appearance (the window's, when there is one), or /// the one chosen. pub fn apply_theme(window: Option<&mut Window>, cx: &mut App) { diff --git a/windows/crates/ps-gui/src/ui/autoproxy.rs b/windows/crates/ps-gui/src/ui/autoproxy.rs index 0a0b130..61809d8 100644 --- a/windows/crates/ps-gui/src/ui/autoproxy.rs +++ b/windows/crates/ps-gui/src/ui/autoproxy.rs @@ -16,7 +16,7 @@ use ps_client::edits; use ps_ipc::Request; use serde_json::{Value, json}; -use super::widgets::{card, hint, page}; +use super::widgets::{card, hint, page, Inactive as _}; use crate::model::Model; pub struct AutoProxyPage { @@ -218,10 +218,10 @@ impl Render for AutoProxyPage { .small() .icon(IconName::Gauge) .label(if probing { "Probing…" } else { "Probe" }) - .disabled(probing || !running) + .inactive(probing || !running, cx) .on_click(cx.listener(|this, _, window, cx| this.probe(window, cx))), ) - .child(Button::new("ap-learn").small().primary().icon(IconName::Plus).label("Learn").disabled(!running).on_click(cx.listener(|this, _, window, cx| this.learn(window, cx)))), + .child(Button::new("ap-learn").small().primary().icon(IconName::Plus).label("Learn").inactive(!running, cx).on_click(cx.listener(|this, _, window, cx| this.learn(window, cx)))), ); match &self.probe { Some(Ok(p)) => { diff --git a/windows/crates/ps-gui/src/ui/components.rs b/windows/crates/ps-gui/src/ui/components.rs index 94a6f8e..0292d0c 100644 --- a/windows/crates/ps-gui/src/ui/components.rs +++ b/windows/crates/ps-gui/src/ui/components.rs @@ -9,7 +9,7 @@ use gpui_kit::*; use ps_ipc::Request; use serde_json::Value; -use super::widgets::{card, hint, page}; +use super::widgets::{card, hint, page, Inactive as _}; use crate::model::Model; pub struct ComponentsPage { @@ -72,7 +72,7 @@ impl Render for ComponentsPage { .small() .icon(IconName::Download) .label(if self.installing { "Installing…" } else { "Fetch all again" }) - .disabled(self.installing) + .inactive(self.installing, cx) .on_click(cx.listener(|this, _, _, cx| this.install(Vec::new(), cx))), ); let mut list = card("Programs", Some(actions.into_any_element()), cx).child(hint( diff --git a/windows/crates/ps-gui/src/ui/mod.rs b/windows/crates/ps-gui/src/ui/mod.rs index 72b74c5..a399388 100644 --- a/windows/crates/ps-gui/src/ui/mod.rs +++ b/windows/crates/ps-gui/src/ui/mod.rs @@ -103,11 +103,15 @@ impl AppView { pub fn new(model: Entity, window: &mut Window, cx: &mut Context) -> Self { let subscriptions = vec![ cx.observe(&model, |_, _, cx| cx.notify()), - // As Windows' appearance changes, when the theme follows it. + // As Windows' appearance changes: the theme, when it follows it; the title bar, which + // GPUI sets to Windows' own just after this, a moment later. cx.observe_window_appearance(window, |_, window, cx| { - if cx.global::().theme == crate::prefs::ThemeChoice::System { - crate::prefs::apply_theme(Some(window), cx); - } + crate::prefs::apply_theme(Some(window), cx); + cx.spawn_in(window, async move |_, cx| { + cx.background_executor().timer(std::time::Duration::from_millis(300)).await; + cx.update(|window, cx| crate::prefs::apply_theme(Some(window), cx)).ok(); + }) + .detach(); }), cx.subscribe_in(&model, window, |_, _, outcome: &Outcome, window, cx| { let note = match outcome { diff --git a/windows/crates/ps-gui/src/ui/outbounds.rs b/windows/crates/ps-gui/src/ui/outbounds.rs index 4f33954..e5951fd 100644 --- a/windows/crates/ps-gui/src/ui/outbounds.rs +++ b/windows/crates/ps-gui/src/ui/outbounds.rs @@ -16,7 +16,7 @@ use ps_client::edits::{self, OutboundSource}; use ps_ipc::Request; use serde_json::Value; -use super::widgets::{card, hint, page}; +use super::widgets::{card, hint, page, Inactive as _}; use crate::model::Model; const MODES: [(&str, &str); 5] = [ @@ -175,7 +175,7 @@ impl Render for OutboundsPage { let mut list = card( format!("Outbounds ({})", tags.len()), - Some(Button::new("test-all").small().icon(IconName::Gauge).label(if self.testing { "Testing…" } else { "Test all" }).disabled(self.testing || tags.is_empty()).on_click(cx.listener(|this, _, _, cx| this.test(Vec::new(), cx))).into_any_element()), + Some(Button::new("test-all").small().icon(IconName::Gauge).label(if self.testing { "Testing…" } else { "Test all" }).inactive(self.testing || tags.is_empty(), cx).on_click(cx.listener(|this, _, _, cx| this.test(Vec::new(), cx))).into_any_element()), cx, ); if let Some(Err(e)) = self.delays.get("") { @@ -205,7 +205,7 @@ impl Render for OutboundsPage { .small() .icon(IconName::RefreshCw) .label("Update all") - .disabled(subs.is_empty()) + .inactive(subs.is_empty(), cx) .on_click(move |_, _, cx| model.update(cx, |m, cx| m.request("Subscriptions updated", Request::SubsUpdate { tag: None }, cx))) .into_any_element(), ), diff --git a/windows/crates/ps-gui/src/ui/overview.rs b/windows/crates/ps-gui/src/ui/overview.rs index f7dfe05..ba3815f 100644 --- a/windows/crates/ps-gui/src/ui/overview.rs +++ b/windows/crates/ps-gui/src/ui/overview.rs @@ -12,7 +12,7 @@ use ps_client::edits; use serde_json::Value; use super::AppView; -use super::widgets::{card, fact, hint, page, state_tag}; +use super::widgets::{card, fact, hint, page, state_tag, Inactive as _}; use crate::model::{Connection, Model, Update}; fn text(v: &Value) -> SharedString { @@ -155,7 +155,7 @@ fn updates(model: &Entity, cx: &mut Context) -> Div { .ghost() .icon(IconName::RefreshCw) .label("Check for updates") - .disabled(busy) + .inactive(busy, cx) .on_click(move |_, _, cx| model.update(cx, |m, cx| m.check_update(cx))) }; let card = card(format!("Proxy Suite {}", m.version()), Some(check.into_any_element()), cx); diff --git a/windows/crates/ps-gui/src/ui/settings.rs b/windows/crates/ps-gui/src/ui/settings.rs index 3493303..eb7b794 100644 --- a/windows/crates/ps-gui/src/ui/settings.rs +++ b/windows/crates/ps-gui/src/ui/settings.rs @@ -14,7 +14,7 @@ use ps_client::Issue; use ps_ipc::Request; use serde_json::Value; -use super::widgets::{card, hint, page}; +use super::widgets::{card, hint, page, Inactive as _}; use crate::model::Model; use crate::prefs::{self, Prefs, ThemeChoice}; @@ -189,7 +189,7 @@ impl Render for SettingsPage { .gap_2() .child(Button::new("cfg-reload").small().ghost().icon(IconName::RefreshCw).label("Reload").on_click(cx.listener(|this, _, window, cx| this.reload(window, cx)))) .child(Button::new("cfg-validate").small().label("Check").on_click(cx.listener(|this, _, _, cx| this.validate(cx)))) - .child(Button::new("cfg-save").small().primary().icon(IconName::Save).label("Save").disabled(!changed).on_click(cx.listener(|this, _, _, cx| this.save(cx)))); + .child(Button::new("cfg-save").small().primary().icon(IconName::Save).label("Save").inactive(!changed, cx).on_click(cx.listener(|this, _, _, cx| this.save(cx)))); let verdict = match &self.verdict { Verdict::None => div(), diff --git a/windows/crates/ps-gui/src/ui/widgets.rs b/windows/crates/ps-gui/src/ui/widgets.rs index 7d39927..c70a765 100644 --- a/windows/crates/ps-gui/src/ui/widgets.rs +++ b/windows/crates/ps-gui/src/ui/widgets.rs @@ -1,6 +1,8 @@ //! Pieces the pages share: the page frame, cards, a unit's state as a tag. +use gpui_kit::component::button::Button; use gpui_kit::component::tag::Tag; +use gpui_kit::prelude::FluentBuilder as _; use gpui_kit::assets::IconName; use gpui_kit::component::*; use gpui_kit::*; @@ -48,3 +50,17 @@ pub fn hint(text: impl Into, cx: &App) -> Div { pub fn fact(label: &'static str, value: impl Into, 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()) } + +/// A button that cannot be pressed now. gpui-component draws a disabled button's text at half +/// the muted colour, which the dark theme all but hides: here at the muted colour itself (a +/// button's own style is laid over its disabled state's), still plainly dimmer than an active +/// button's. +pub trait Inactive: Sized { + fn inactive(self, disabled: bool, cx: &App) -> Self; +} + +impl Inactive for Button { + fn inactive(self, disabled: bool, cx: &App) -> Self { + self.disabled(disabled).when(disabled, |b| b.text_color(cx.theme().muted_foreground)) + } +} diff --git a/windows/crates/ps-service/src/awgvpn.rs b/windows/crates/ps-service/src/awgvpn.rs index b815a4a..7bd2eae 100644 --- a/windows/crates/ps-service/src/awgvpn.rs +++ b/windows/crates/ps-service/src/awgvpn.rs @@ -293,6 +293,21 @@ pub fn state(_iface: &str) -> String { "windows-only".into() } +/// The tunnels this suite registered that run, stopped: their interface names. +pub fn stop_running(paths: &Paths) -> Vec { + registered(paths) + .into_iter() + .filter(|iface| state(iface) == "active") + .filter(|iface| match stop(iface) { + Ok(()) => true, + Err(e) => { + tracing::warn!("stopping the AmneziaWG tunnel {iface}: {e:#}"); + false + } + }) + .collect() +} + /// Every tunnel this suite registered, stopped and deleted: on uninstall. #[cfg_attr(not(windows), allow(dead_code))] pub fn remove_all(paths: &Paths) { diff --git a/windows/crates/ps-service/src/install.rs b/windows/crates/ps-service/src/install.rs index edc8f5b..05e9355 100644 --- a/windows/crates/ps-service/src/install.rs +++ b/windows/crates/ps-service/src/install.rs @@ -256,15 +256,20 @@ fn verify_all(dir: &Path) -> Result<()> { /// Copies each component of `from` (the release's) into `bin` when `bin` lacks it or holds /// another version: staged, verified file by file, swapped in. What it did, as lines. +/// Whether `seed` replaces `name` in `bin`: the release has the version the manifest wants, +/// and `bin` another (or none). +pub fn seeds(from: &Path, bin: &Path, name: &str) -> bool { + let manifest = ps_core::components::manifest(); + let Some(comp) = manifest.components.get(name) else { return false }; + installed_version(from, name).as_deref() == Some(comp.version.as_str()) && installed_version(bin, name).as_deref() != Some(comp.version.as_str()) +} + pub fn seed(from: &Path, bin: &Path) -> Vec { let manifest = ps_core::components::manifest(); let mut notes = Vec::new(); for (name, comp) in &manifest.components { let src = from.join(name); - if installed_version(from, name).as_deref() != Some(comp.version.as_str()) { - continue; - } - if installed_version(bin, name).as_deref() == Some(comp.version.as_str()) { + if !seeds(from, bin, name) { continue; } let staging = bin.join(format!("{name}.staging")); diff --git a/windows/crates/ps-service/src/main.rs b/windows/crates/ps-service/src/main.rs index f38396e..24dc95b 100644 --- a/windows/crates/ps-service/src/main.rs +++ b/windows/crates/ps-service/src/main.rs @@ -89,9 +89,22 @@ pub async fn run( paths.create_all().with_context(|| format!("creating {}", paths.root.display()))?; // The components the release carries, next to the program, into bin\ when they are newer. if let Some(dir) = install::bundled_components_dir() { + // What runs from bin\ outside this service holds its files: a system-wide AmneziaWG + // tunnel (stopped while its program is replaced, started again after), WinDivert's + // driver (left loaded by a zapret stopped hard). + let tunnels = if install::seeds(&dir, &paths.bin(), "amneziawg") { awgvpn::stop_running(&paths) } else { Vec::new() }; + #[cfg(windows)] + if ["zapret", "zapret2"].iter().any(|n| install::seeds(&dir, &paths.bin(), n)) { + winsvc::release_windivert(); + } for note in install::seed(&dir, &paths.bin()) { tracing::info!("{note}"); } + for iface in tunnels { + if let Err(e) = awgvpn::start(&iface) { + tracing::warn!("the AmneziaWG tunnel {iface} did not start again: {e:#}"); + } + } } let svc = service::Service::new(paths.clone()).with_context(|| format!("opening {}", paths.root.display()))?; let interactive = svc.cfg().user_control.enable; diff --git a/windows/crates/ps-service/src/update.rs b/windows/crates/ps-service/src/update.rs index 228bb6f..c261bc0 100644 --- a/windows/crates/ps-service/src/update.rs +++ b/windows/crates/ps-service/src/update.rs @@ -194,7 +194,9 @@ fn published_sum(text: &[u8]) -> Result { } } -/// The release's setup program in `dir` (older ones gone), once its SHA-256 matches. +/// The release's setup program in `dir` (older ones gone), once its SHA-256 matches. `dir` is +/// under the state root, whose protected DACL (SYSTEM and Administrators only, inherited) +/// keeps anyone else from replacing the file between this check and its run as SYSTEM. async fn download(release: &Release, routes: &[Route], dir: &Path) -> Result { let sum = first(routes, |r| { let url = release.checksum.clone(); @@ -295,6 +297,10 @@ pub fn report(dir: &Path) { let _ = std::fs::remove_file(&path); if wanted.trim() == env!("CARGO_PKG_VERSION") { tracing::info!("updated to {}", env!("CARGO_PKG_VERSION")); + // Done with: ~80 MB. + for e in std::fs::read_dir(dir).into_iter().flatten().flatten() { + let _ = std::fs::remove_file(e.path()); + } } else { tracing::warn!("the update to {} did not finish; this is still {}", wanted.trim(), env!("CARGO_PKG_VERSION")); } diff --git a/windows/crates/ps-service/src/winsvc.rs b/windows/crates/ps-service/src/winsvc.rs index c9484f7..e074849 100644 --- a/windows/crates/ps-service/src/winsvc.rs +++ b/windows/crates/ps-service/src/winsvc.rs @@ -196,6 +196,13 @@ pub fn uninstall() -> Result<()> { Ok(()) } +/// WinDivert's driver, if this suite's is still loaded: its files are about to be replaced. +pub fn release_windivert() { + if let Ok(manager) = ServiceManager::local_computer(None::<&str>, ServiceManagerAccess::CONNECT) { + remove_windivert(&manager); + } +} + /// The WinDivert driver zapret loaded from this suite's components, if it is still registered /// (WinDivert removes its own service as it loads, but one stopped hard can stay): stopped and /// deleted, as Flowseal's service.bat removes it. One from elsewhere is left alone. diff --git a/windows/docs/screenshots/logs.png b/windows/docs/screenshots/logs.png index f0388ce..430b458 100644 Binary files a/windows/docs/screenshots/logs.png and b/windows/docs/screenshots/logs.png differ diff --git a/windows/docs/screenshots/overview-dark.png b/windows/docs/screenshots/overview-dark.png index 0099f9e..da37e8b 100644 Binary files a/windows/docs/screenshots/overview-dark.png and b/windows/docs/screenshots/overview-dark.png differ diff --git a/windows/docs/screenshots/overview.png b/windows/docs/screenshots/overview.png index 6583a7d..b6f4f92 100644 Binary files a/windows/docs/screenshots/overview.png and b/windows/docs/screenshots/overview.png differ diff --git a/windows/docs/screenshots/settings.png b/windows/docs/screenshots/settings.png index 2ac248e..bf4ec71 100644 Binary files a/windows/docs/screenshots/settings.png and b/windows/docs/screenshots/settings.png differ diff --git a/windows/docs/screenshots/telegram.png b/windows/docs/screenshots/telegram.png index 247e379..4108ae7 100644 Binary files a/windows/docs/screenshots/telegram.png and b/windows/docs/screenshots/telegram.png differ