windows: the app sets the system proxy; ps-core lint fixes

- The app points the signed-in user's system proxy (WinINet: browsers
  and most programs follow it) at the local proxy while it runs and
  proxy.systemProxy.enable asks; the user's own settings are kept and put
  back when the proxy stops, the service goes, the option is turned off
  or the app quits; one left behind by a killed app is cleared. A switch
  for it on the overview. Elsewhere than Windows it does nothing.
- ps-core: clippy's collapsible ifs, comparisons without owned values, a
  range loop without indexing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 02:07:02 +03:00
1 parent 77becc235c
commit 7565e62571
9 files changed
+248 -17

No files matched your search

+29 -1
View File
@@ -8,6 +8,7 @@ use ps_client::edits;
use serde_json::Value;
use crate::model::{Connection, Model};
use crate::sysproxy::SystemProxy;
use crate::ui::AppView;
actions!(proxy_suite, [OpenWindow, ToggleProxy, ToggleDpi, ToggleTelegram, Quit]);
@@ -18,13 +19,16 @@ struct Shell {
tray: Option<Tray>,
/// The icon's colour now, so it is only replaced when that changes.
colour: &'static str,
system_proxy: SystemProxy,
/// The system proxy's last failure, said once.
system_proxy_error: Option<String>,
}
impl Global for Shell {}
pub fn start(model: Entity<Model>, open: bool, cx: &mut App) {
cx.on_action(open_window).on_action(toggle_proxy).on_action(toggle_dpi).on_action(toggle_telegram).on_action(quit);
cx.set_global(Shell { model: model.clone(), window: None, tray: None, colour: "" });
cx.set_global(Shell { model: model.clone(), window: None, tray: None, colour: "", system_proxy: SystemProxy::default(), system_proxy_error: None });
let mut builder = Tray::builder().tooltip("Proxy Suite").on_activate(OpenWindow).menu(menu);
if let Some(icon) = icon("#6b7280", cx) {
@@ -78,7 +82,30 @@ fn icon(fill: &str, cx: &App) -> Option<Icon> {
Icon::from_gpui(&Image::from_bytes(ImageFormat::Svg, svg.into_bytes()), cx).build().inspect_err(|e| eprintln!("proxy-suite: the tray icon: {e}")).ok()
}
/// The system proxy, as the configuration and the local proxy's state say.
fn system_proxy(cx: &mut App) {
let m = cx.global::<Shell>().model.read(cx);
let (s, c) = (m.status(), m.config());
let up = *m.connection() == Connection::Up;
let want = up && c["proxy"]["systemProxy"]["enable"] == true && s["proxy"]["on"] == true && s["proxy"]["state"] == "active";
let listener = s["proxy"]["listener"].as_str().unwrap_or("").replace("0.0.0.0:", "127.0.0.1:");
let bypass: Vec<String> = c["proxy"]["systemProxy"]["bypass"].as_array().into_iter().flatten().filter_map(|v| v.as_str().map(str::to_owned)).collect();
if listener.is_empty() || c.is_null() {
return;
}
let shell = cx.global_mut::<Shell>();
match shell.system_proxy.update(want, &listener, &bypass) {
Ok(()) => shell.system_proxy_error = None,
Err(e) if shell.system_proxy_error.as_ref() != Some(&e) => {
eprintln!("proxy-suite: the system proxy: {e}");
shell.system_proxy_error = Some(e);
}
Err(_) => {}
}
}
fn refresh(cx: &mut App) {
system_proxy(cx);
let Some(tray) = cx.global::<Shell>().tray.clone() else { return };
let fill = colour(cx);
if fill != cx.global::<Shell>().colour {
@@ -170,6 +197,7 @@ fn toggle_telegram(_: &ToggleTelegram, cx: &mut App) {
}
fn quit(_: &Quit, cx: &mut App) {
cx.global_mut::<Shell>().system_proxy.restore();
if let Some(tray) = cx.global::<Shell>().tray.clone() {
let _ = tray.close(cx);
}