mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-30 12:03:59 +01:00
Clear Yaak Proxy traffic at launch and follow the real system proxy
Captured traffic is now cleared as the app launches by default, with a "Keep between launches" choice that brings the size limit with it. An install that had a size limit set keeps its traffic. The Proxy settings tab is regrouped into Proxy, Decryption, Traffic and Terminal, and the per-body limit row is gone. The app now watches macOS proxy settings and follows them: when another app or the user points the system proxy elsewhere, the override shows as off and the settings saved for restoring are dropped, so quitting puts back nothing the app didn't set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13ef9c60f1
commit
4fc95d264c
15 files changed
+726
-76
No files matched your search
@@ -1,6 +1,10 @@
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { formatSize } from "@yaakapp-internal/lib/formatSize";
|
||||
import type { HttpVersion, SystemProxyStatus } from "@yaakapp-internal/proxy-lib";
|
||||
import type {
|
||||
HttpVersion,
|
||||
SystemProxyStatus,
|
||||
TrafficRetention,
|
||||
} from "@yaakapp-internal/proxy-lib";
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
@@ -31,7 +35,6 @@ import {
|
||||
type TerminalShell,
|
||||
} from "../lib/env";
|
||||
import {
|
||||
CAPTURE_LIMIT_OPTIONS,
|
||||
KEEP_TRAFFIC_OPTIONS,
|
||||
sizeFromOptionValue,
|
||||
sizeOptionsFor,
|
||||
@@ -44,16 +47,15 @@ import { useShowToast } from "../lib/toast";
|
||||
import { DecryptListEditor } from "./DecryptListEditor";
|
||||
|
||||
/**
|
||||
* The proxy's own settings tab: how it listens, what it decrypts, the system proxy and its
|
||||
* helper, how much traffic it keeps, and the environment for one terminal. Everything set once
|
||||
* and left alone, which is what left the state pill's menu.
|
||||
* The proxy's own settings tab: how it listens and the system proxy, what it decrypts, what
|
||||
* happens to captured traffic, and the environment for one terminal. Everything set once and
|
||||
* left alone, which is what left the state pill's menu.
|
||||
*/
|
||||
export function SettingsProxy() {
|
||||
const proxyState = useAtomValue(proxyStateAtom);
|
||||
const store = useStore();
|
||||
const refresh = { onSettled: () => void refreshProxyState(store) };
|
||||
const setHttpVersion = useRpcMutation("set_http_version", refresh);
|
||||
const setCaptureLimit = useRpcMutation("set_capture_body_limit", refresh);
|
||||
const setAtLaunch = useRpcMutation("set_system_proxy_at_launch", refresh);
|
||||
const systemProxy = useRpcQuery("system_proxy_status", {});
|
||||
// Another process owning the engine wouldn't see changes until it restarts
|
||||
@@ -63,10 +65,10 @@ export function SettingsProxy() {
|
||||
<VStack space={1.5} className="mb-4">
|
||||
<div className="mb-3">
|
||||
<Heading>Proxy</Heading>
|
||||
<p className="text-text-subtle">Listening, decryption, storage and terminals</p>
|
||||
<p className="text-text-subtle">Listening, decryption, traffic and terminals</p>
|
||||
</div>
|
||||
<SettingsList className="space-y-8">
|
||||
<SettingsSection title="Listening">
|
||||
<SettingsSection title="Proxy">
|
||||
<PortRow disabled={elsewhere} />
|
||||
<SettingRowSelect<HttpVersion>
|
||||
name="httpVersion"
|
||||
@@ -80,40 +82,27 @@ export function SettingsProxy() {
|
||||
{ label: "HTTP/1.1 only", value: "http1Only" },
|
||||
]}
|
||||
/>
|
||||
<SettingRowSelect
|
||||
name="captureBodyLimit"
|
||||
title="Body limit"
|
||||
description="Stored per body"
|
||||
value={sizeOptionValue(proxyState?.captureBodyLimit ?? null)}
|
||||
disabled={elsewhere}
|
||||
onChange={(v) => {
|
||||
const bytes = sizeFromOptionValue(v);
|
||||
if (bytes != null) setCaptureLimit.mutate({ bytes });
|
||||
}}
|
||||
options={sizeOptionsFor(CAPTURE_LIMIT_OPTIONS, proxyState?.captureBodyLimit ?? null)
|
||||
.filter((o) => o.bytes != null)
|
||||
.map(({ label, value }) => ({ label, value }))}
|
||||
/>
|
||||
{systemProxy.data?.supported === true && (
|
||||
<>
|
||||
<SettingRowBoolean
|
||||
title="Override system proxy"
|
||||
description="At launch"
|
||||
checked={proxyState?.systemProxyAtLaunch ?? true}
|
||||
disabled={setAtLaunch.isPending}
|
||||
onChange={(enabled) => setAtLaunch.mutate({ enabled })}
|
||||
/>
|
||||
<HelperRow status={systemProxy.data} />
|
||||
</>
|
||||
)}
|
||||
</SettingsSection>
|
||||
|
||||
<SettingsSection title="Decrypt">
|
||||
<SettingsSection title="Decryption">
|
||||
<DecryptListEditor className="py-4" />
|
||||
</SettingsSection>
|
||||
|
||||
{systemProxy.data?.supported === true && (
|
||||
<SettingsSection title="System proxy">
|
||||
<SettingRowBoolean
|
||||
title="Override at launch"
|
||||
checked={proxyState?.systemProxyAtLaunch ?? true}
|
||||
disabled={setAtLaunch.isPending}
|
||||
onChange={(enabled) => setAtLaunch.mutate({ enabled })}
|
||||
/>
|
||||
<HelperRow status={systemProxy.data} />
|
||||
</SettingsSection>
|
||||
)}
|
||||
|
||||
<SettingsSection title="Storage">
|
||||
<KeepTrafficRow />
|
||||
<SettingsSection title="Traffic">
|
||||
<TrafficRow />
|
||||
{proxyState?.traffic === "keep" && <KeepTrafficRow />}
|
||||
<ResetRow />
|
||||
</SettingsSection>
|
||||
|
||||
@@ -225,6 +214,30 @@ function HelperRow({ status }: { status: SystemProxyStatus }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Whether captured traffic is cleared as the app launches or kept between launches */
|
||||
function TrafficRow() {
|
||||
const proxyState = useAtomValue(proxyStateAtom);
|
||||
const store = useStore();
|
||||
const setTraffic = useRpcMutation("set_traffic", {
|
||||
onSettled: () => void refreshProxyState(store),
|
||||
});
|
||||
return (
|
||||
<SettingRowSelect<TrafficRetention>
|
||||
name="traffic"
|
||||
title="Captured traffic"
|
||||
selectClassName="w-56!"
|
||||
value={proxyState?.traffic ?? "clearOnLaunch"}
|
||||
disabled={proxyState?.otherOwner != null}
|
||||
onChange={(traffic) => setTraffic.mutate({ traffic })}
|
||||
options={[
|
||||
{ label: "Clear on launch", value: "clearOnLaunch" },
|
||||
{ label: "Keep between launches", value: "keep" },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/** The most traffic kept between launches, beside what is stored now */
|
||||
function KeepTrafficRow() {
|
||||
const proxyState = useAtomValue(proxyStateAtom);
|
||||
const store = useStore();
|
||||
@@ -234,7 +247,7 @@ function KeepTrafficRow() {
|
||||
});
|
||||
const keep = proxyState?.keepTrafficBytes ?? null;
|
||||
return (
|
||||
<SettingRow title="Keep traffic" description="Oldest flows dropped past the limit">
|
||||
<SettingRow title="Size limit" description="Oldest flows dropped past it">
|
||||
<div className="flex items-center gap-3">
|
||||
{size.data != null && (
|
||||
<span className="text-sm text-text-subtle tabular-nums whitespace-nowrap">
|
||||
@@ -243,7 +256,7 @@ function KeepTrafficRow() {
|
||||
)}
|
||||
<SettingSelectControl
|
||||
name="keepTraffic"
|
||||
label="Keep traffic"
|
||||
label="Size limit"
|
||||
value={sizeOptionValue(keep)}
|
||||
disabled={proxyState?.otherOwner != null}
|
||||
onChange={(v) => setKeep.mutate({ bytes: sizeFromOptionValue(v) })}
|
||||
|
||||
@@ -23,6 +23,7 @@ const STATE: GetProxyStateResponse = {
|
||||
locked: { message: LOCKED, keychain: true },
|
||||
otherOwner: null,
|
||||
captureBodyLimit: 10 * 1024 * 1024,
|
||||
traffic: "clearOnLaunch",
|
||||
keepTrafficBytes: null,
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ export const HARNESS_STATE: GetProxyStateResponse = {
|
||||
systemProxyAtLaunch: true,
|
||||
httpVersion: "auto",
|
||||
captureBodyLimit: 10 * 1024 * 1024,
|
||||
traffic: "keep",
|
||||
keepTrafficBytes: 2 * 1024 * 1024 * 1024,
|
||||
startError: null,
|
||||
encrypting: null,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import {
|
||||
CAPTURE_LIMIT_OPTIONS,
|
||||
DEFAULT_SETTINGS_VALUES,
|
||||
KEEP_TRAFFIC_OPTIONS,
|
||||
proxySettingsView,
|
||||
@@ -78,13 +77,6 @@ describe("size options", () => {
|
||||
});
|
||||
|
||||
test("labels in the units the limits are set in", () => {
|
||||
expect(CAPTURE_LIMIT_OPTIONS.map((o) => o.label)).toEqual([
|
||||
"1 MB",
|
||||
"5 MB",
|
||||
"10 MB",
|
||||
"50 MB",
|
||||
"100 MB",
|
||||
]);
|
||||
expect(KEEP_TRAFFIC_OPTIONS.map((o) => o.label)).toEqual([
|
||||
"Unlimited",
|
||||
"500 MB",
|
||||
@@ -97,22 +89,25 @@ describe("size options", () => {
|
||||
});
|
||||
|
||||
test("values round trip", () => {
|
||||
for (const o of [...KEEP_TRAFFIC_OPTIONS, ...CAPTURE_LIMIT_OPTIONS]) {
|
||||
for (const o of KEEP_TRAFFIC_OPTIONS) {
|
||||
expect(sizeFromOptionValue(sizeOptionValue(o.bytes))).toBe(o.bytes);
|
||||
}
|
||||
expect(sizeFromOptionValue("abc")).toBeNull();
|
||||
});
|
||||
|
||||
test("a size set elsewhere gets its own option, in order", () => {
|
||||
const options = sizeOptionsFor(CAPTURE_LIMIT_OPTIONS, 3 * 1024 * 1024);
|
||||
const MB = 1024 * 1024;
|
||||
const options = sizeOptionsFor(KEEP_TRAFFIC_OPTIONS, 750 * MB);
|
||||
expect(options.map((o) => o.bytes)).toEqual([
|
||||
1024 * 1024,
|
||||
3 * 1024 * 1024,
|
||||
5 * 1024 * 1024,
|
||||
10 * 1024 * 1024,
|
||||
50 * 1024 * 1024,
|
||||
100 * 1024 * 1024,
|
||||
500 * MB,
|
||||
750 * MB,
|
||||
1024 * MB,
|
||||
2048 * MB,
|
||||
5120 * MB,
|
||||
10240 * MB,
|
||||
20480 * MB,
|
||||
null,
|
||||
]);
|
||||
expect(sizeOptionsFor(CAPTURE_LIMIT_OPTIONS, 10 * 1024 * 1024)).toBe(CAPTURE_LIMIT_OPTIONS);
|
||||
expect(sizeOptionsFor(KEEP_TRAFFIC_OPTIONS, 1024 * MB)).toBe(KEEP_TRAFFIC_OPTIONS);
|
||||
});
|
||||
});
|
||||
@@ -141,12 +141,6 @@ export const KEEP_TRAFFIC_OPTIONS = sizeOptions(
|
||||
"Unlimited",
|
||||
);
|
||||
|
||||
/** How much of each body is stored */
|
||||
export const CAPTURE_LIMIT_OPTIONS = sizeOptions(
|
||||
[MB, 5 * MB, 10 * MB, 50 * MB, 100 * MB],
|
||||
"Unlimited",
|
||||
);
|
||||
|
||||
/**
|
||||
* The option a stored size selects. A size set elsewhere (the CLI or `settings.json`) that no
|
||||
* option has is added as its own, so the select still shows it.
|
||||
|
||||
Reference in new issue
Block a user