feat(desktop): snapshot and restore the OS proxy around system/pac - #218
Merged
Conversation
The system/pac proxy modes overwrote the OS proxy with a blanket disable on clear, wiping any proxy the user had configured by hand, and a hard GUI crash left the OS proxy untouched until the next start. Record the pre-existing per-layer OS proxy state in a versioned ownership file (os-proxy-backup.json, in the datadir so it survives a reboot) on the first apply. Clearing restores every layer from that snapshot and drops the record; with no record the current proxy isn't ours and is left alone. A corrupt or unknown-version record falls back to the old blanket disable. At GUI start a surviving record is an orphan from an unclean exit, so the setup path restores the user's proxy before bringing the data-path up.
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Close the two OS-proxy gaps documented in #65's reviewer notes:
clearblanked whatever proxy the OS had (wiping one the user configured by hand), and a hard GUI crash left the OS pointing at a dead local port until the next start. Neither is matched by v2rayN — its clear is an unconditional disable on all three OSes and it has no crash recovery — so this is a step past parity, not catch-up.Ownership record. The first apply in
system/pacmode snapshots the current per-layer OS proxy state into a versionedos-proxy-backup.jsonin the user datadir (survives a reboot); its presence marks the OS proxy as ours. From there:Service,clear_os_proxy()runs once: the helper has already reaped the data-path when the GUI died, so a surviving record is by definition an orphan and the user's proxy is restored before anything else happens.Per layer: Windows snapshots/restores the four WinINET values (
ProxyEnable,ProxyServer,ProxyOverride,AutoConfigURL) viaRegGetValueW; Linux snapshots the gsettings proxy keys (quote-stripped), the sixkioslaverckeys viakreadconfig6/5, and the live-session values of the 8 proxy env vars fromsystemctl --user show-environment(ourenvironment.dfile is ours by name — just removed). The decision logic (snapshot-vs-apply, restore-vs-blank-vs-noop) is pure and unit-tested; theRunEvent::ExitandServicelifecycle call sites are untouched — they route through the same two functions and inherit the semantics.Affected layer
frontend/— React Web UIcrates/·src-tauri/— Rust core / backend / Tauri desktopmodule/— Android installable zip (thin launcher over the Rust daemon)scripts/— build / release helpers.github/Verification
Rust (
crates/·src-tauri/):cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspace— one failure:net::tests::tcp_ping_fails_on_unreachable_host, the known environment flake (an active VPN tun on the dev machine captures the TEST-NET-1 connect); fails identically onmainfrontend/src/generateduntouched)New tests (9): record round-trip incl. the version field, absent→noop / corrupt→blank / wrong-version→blank, snapshot-only-when-no-record; gsettings quote-stripping,
show-environmentfiltering incl. values containing=.Windows
#[cfg(windows)](RegGetValueWreads) compiles only under the Windows CI job — every windows-sys 0.59 signature and constant was checked against the vendored crate source.Checklist
module/bin/<abi>/,geoip/geosite, builtmodule/webroot/,src-tauri/gen/— all gitignored on purpose)frontend/src/generated/was regenerated from Rust, not hand-edited (untouched)i18n/en.tsand every locale file updated (no user-visible strings changed)kasumi-proxy,Kasumi Proxy, camelCase)Notes for reviewers
clear_os_proxy()— the record's absence after a clean exit makes it a natural no-op, so there is no separate "recovery" code path to reason about.ProxyEnable=0, empty strings) rather than being deleted withRegDeleteKeyValueW— behaviourally identical for proxy-off, smaller diff.getfails at snapshot time is skipped and therefore not restored (that one key keeps our value). Schema-present-but-get-failing is another effectively-unreachable corner; noted for completeness.