Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

settings: Custom proxy brings back the last address and login (Zane)

yetone7faea508f680
diff --git a/internal/gui/api.go b/internal/gui/api.go
index 7809cecae..59b867a37 100644
--- a/internal/gui/api.go
+++ b/internal/gui/api.go
@@ -1216,6 +1216,7 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
in.AllowIPs = cur.AllowIPs // set on its own (allowips below)
in.FetchPrivate = cur.FetchPrivate // in settings.json only
in.GitHubToken = cur.GitHubToken // set on its own (github-token below), never sent to the page
+ in.ProxyCustom = cur.ProxyCustom // set by settings.Save from the proxy, never by the page
in.RequestArchive = cur.RequestArchive // the Gateway page's, set on its own
in.RequestArchiveMaxMB = cur.RequestArchiveMaxMB // in settings.json only
in.ClaudeRunsMost = cur.ClaudeRunsMost // magpie claude-code runs, or settings.json (#2956)
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 991647420..b7b9d5789 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -20374,7 +20374,7 @@ const UPDATE_EVERY = [30, 60, 360, 1440];
// their own; this row says which one, and lets it be turned off or set. A provider, account or key
// that names a proxy of its own (or Direct) keeps it whatever this says (netproxy.With), so the
// line says it holds for those without one (#1832).
-let proxyCustom = false; // Custom picked, nothing typed yet
+let proxyCustom = false; // Custom picked, not saved yet
// Keep SOCKS credentials in their own fields; URL userinfo is the existing
// saved format, with reserved characters escaped before it reaches Go/Bun.
function proxyFields(value) {
@@ -20419,7 +20419,9 @@ function renderProxy(s, keep) {
else renderProxy(s, keep);
};
if (mode === "custom") {
- let fields = proxyFields(cur === "custom" ? s.proxy : "");
+ // Custom picked again after Off or Auto: the last one saved, login and
+ // all, which settings.Save keeps as proxyCustom (Zane on Discord)
+ let fields = proxyFields(cur === "custom" ? s.proxy : s.proxyCustom || "");
const i = input(fields.address, "http://127.0.0.1:7890");
i.className = "proxy";
i.setAttribute("aria-label", t("Proxy address"));
diff --git a/internal/gui/proxy_custom_test.go b/internal/gui/proxy_custom_test.go
new file mode 100644
index 000000000..656e30c9b
--- /dev/null
+++ b/internal/gui/proxy_custom_test.go
@@ -0,0 +1,57 @@
+package gui
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/yetone/magpie/internal/settings"
+)
+
+// Custom proxy remembered (Zane on Discord): a proxy of the user's own,
+// login and all, is kept as proxyCustom when Off ("direct") or Auto ("")
+// is chosen after it, so Settings' Custom can bring it back, and the page
+// is told it. Only the proxy sets it: a proxyCustom the page sends is not
+// taken, and neither Off nor Auto changes what the gateway's requests go
+// through.
+func TestProxyCustomRemembered(t *testing.T) {
+ h := t.TempDir()
+ t.Setenv("HOME", h)
+ t.Setenv("USERPROFILE", h)
+ t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
+ t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
+ srv := Handler(nil, nil)
+ post := func(body string) map[string]any {
+ t.Helper()
+ rec := httptest.NewRecorder()
+ r := httptest.NewRequest("POST", "/api/settings", strings.NewReader(body))
+ r.RemoteAddr = "127.0.0.1:50000"
+ srv.ServeHTTP(rec, r)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("%s: %d %s", body, rec.Code, rec.Body)
+ }
+ var out map[string]any
+ if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
+ t.Fatal(err)
+ }
+ return out
+ }
+ own := "socks5://n%40me:p%[email protected]:1080"
+ if out := post(`{"theme":"dark","lang":"en","proxy":"` + own + `"}`); out["proxyCustom"] != own {
+ t.Fatalf("custom saved, page told %v", out["proxyCustom"])
+ }
+ for _, other := range []string{"direct", ""} {
+ out := post(`{"theme":"dark","lang":"en","proxy":"` + other + `","proxyCustom":"http://page.example:1"}`)
+ if s := settings.Load(); s.Proxy != other || s.ProxyCustom != own || out["proxyCustom"] != own {
+ t.Fatalf("proxy %q: saved %q, remembered %q, page told %v", other, s.Proxy, s.ProxyCustom, out["proxyCustom"])
+ }
+ }
+ next := "http://127.0.0.1:7890"
+ post(`{"theme":"dark","lang":"en","proxy":"` + next + `"}`)
+ if s := settings.Load(); s.Proxy != next || s.ProxyCustom != next {
+ t.Fatalf("a new custom proxy: saved %q, remembered %q", s.Proxy, s.ProxyCustom)
+ }
+}
diff --git a/internal/gui/settings_keep_test.go b/internal/gui/settings_keep_test.go
index a6921252d..35cf41e83 100644
--- a/internal/gui/settings_keep_test.go
+++ b/internal/gui/settings_keep_test.go
@@ -184,6 +184,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
was.DesktopSubagentEffort = "high"
was.CodexAsyncCompact, was.CodexAsyncCompactPercent = true, 70
was.ClaudeRunsMost = 3
+ was.ProxyCustom = "http://me:[email protected]:8080"
if err := settings.Save(was); err != nil {
t.Fatal(err)
}
diff --git a/internal/gui/tests/settings-proxy-remember.test.cjs b/internal/gui/tests/settings-proxy-remember.test.cjs
new file mode 100644
index 000000000..091f9f355
--- /dev/null
+++ b/internal/gui/tests/settings-proxy-remember.test.cjs
@@ -0,0 +1,121 @@
+// Run with Node's test runner and Playwright on the module path; see README.md.
+// Custom proxy remembered (Zane on Discord): a SOCKS address with a login,
+// then Off or Auto, then Custom again shows the same address and login,
+// after a restart too. The page never sends the remembered copy itself:
+// settings.Save keeps it from the proxy, which the fixture does as Go does.
+const assert = require("node:assert/strict");
+const fs = require("node:fs/promises");
+const path = require("node:path");
+const { test } = require("node:test");
+const { chromium, webkit } = require("playwright");
+
+const assets = path.resolve(__dirname, "../assets");
+function server(lang, posts) {
+ let cur = {
+ theme: "light", lang, tray: "panel", currency: "usd", textSize: 100,
+ proxy: "", proxyNow: "", proxySource: "none",
+ trayUsageEvery: 3, version: "test", dir: "/test", lanURLs: [],
+ visionModels: [], imageGenModels: [], workbuddyCheckins: [],
+ fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
+ };
+ return async (route) => {
+ const req = route.request(), url = new URL(req.url());
+ const json = (data) => route.fulfill({ json: data });
+ if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang, theme: "light", web: true })};` });
+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
+ if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" }, fx: cur.fx });
+ if (url.pathname === "/api/settings") {
+ if (req.method() === "POST") {
+ const body = req.postDataJSON();
+ posts.push(body);
+ // as the settings API: proxyCustom is the server's, set from proxy
+ const own = body.proxy && body.proxy !== "direct";
+ cur = { ...cur, ...body, proxyCustom: own ? body.proxy : cur.proxyCustom, proxyNow: body.proxy, proxySource: body.proxy === "direct" ? "off" : body.proxy ? "settings" : "none" };
+ }
+ return json(cur);
+ }
+ if (url.pathname === "/api/plugins") return json({ plugins: [] });
+ if (url.pathname === "/api/usage/quotas") return json([]);
+ if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
+ if (url.pathname.startsWith("/api/")) return json({});
+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
+ return route.fulfill({ body: await fs.readFile(file), contentType });
+ };
+}
+
+const labels = {
+ en: { user: "Username (optional)", pass: "Password (optional)", custom: "Custom", off: "Off", auto: "Auto", saved: "Saved" },
+ zh: { user: "用户名(可选)", pass: "密码(可选)", custom: "自定义", off: "关闭", auto: "自动", saved: "已保存" },
+ "zh-TW": { user: "使用者名稱(選填)", pass: "密碼(選填)", custom: "自定義", off: "關閉", auto: "自動", saved: "已儲存" },
+ ja: { user: "ユーザー名(任意)", pass: "パスワード(任意)", custom: "カスタム", off: "オフ", auto: "自動", saved: "保存しました" },
+ de: { user: "Benutzername (optional)", pass: "Passwort (optional)", custom: "Benutzerdefiniert", off: "Aus", auto: "Automatisch", saved: "Gespeichert" },
+};
+
+for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
+ for (const lang of Object.keys(labels)) {
+ const l = labels[lang];
+ test(`${engine} ${lang}: Custom brings back the proxy and login after Off and Auto`, async (t) => {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ const context = await browser.newContext({ viewport: { width: 1100, height: 760 }, reducedMotion: "reduce" });
+ const page = await context.newPage();
+ page.setDefaultTimeout(4000);
+ const posts = [], errors = [];
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", server(lang, posts));
+ await page.goto("http://magpie.test/?view=settings&tab=network");
+ const box = page.locator("#proxySegs");
+ const address = box.locator("input.proxy");
+ const user = box.getByRole("textbox", { name: l.user, exact: true });
+ const pass = box.getByLabel(l.pass, { exact: true });
+ const mode = (name) => box.getByRole("button", { name, exact: true });
+ const saved = async (action, want) => {
+ const count = posts.length;
+ const response = page.waitForResponse((r) => r.url().endsWith("/api/settings") && r.request().method() === "POST");
+ await action();
+ await response;
+ await page.waitForFunction((word) => document.querySelector("#status")?.textContent.includes(word), l.saved);
+ assert.equal(posts.length, count + 1, "save once");
+ assert.equal(posts.at(-1).proxy, want);
+ assert(!("proxyCustom" in posts.at(-1)), "the page sends the remembered proxy");
+ };
+ const restored = async (why) => {
+ await mode(l.custom).click();
+ assert.equal(await address.inputValue(), "socks5://127.0.0.1:1080", why);
+ assert.equal(await user.inputValue(), "名 a@b", why);
+ assert.equal(await pass.inputValue(), "p@ss 密", why);
+ };
+
+ const login = "socks5://%E5%90%8D%20a%40b:p%40ss%20%E5%AF%[email protected]:1080";
+ await mode(l.custom).click();
+ await address.fill("socks5://127.0.0.1:1080");
+ await user.fill("名 a@b");
+ await pass.fill("p@ss 密");
+ await saved(() => pass.press("Enter"), login);
+
+ await saved(() => mode(l.off).click(), "direct");
+ const offSaves = posts.length;
+ await restored("after Off");
+ assert.equal(posts.length, offSaves, "picking Custom saves nothing by itself");
+ await pass.press("Escape");
+ assert.equal(posts.length, offSaves, "Escape keeps Off");
+
+ await page.reload(); // a restart: the copy is the server's, not the page's
+ await restored("after Off and a restart");
+ await pass.press("Escape");
+
+ await saved(() => mode(l.auto).click(), "");
+ await restored("after Auto");
+ // leaving the restored fields puts the proxy back in force
+ await saved(() => pass.press("Enter"), login);
+
+ // a draft never saved is not what Custom brings back
+ await address.fill("socks5://127.0.0.1:2080");
+ await user.fill("unsaved");
+ await saved(() => mode(l.off).click(), "direct");
+ await restored("after an unsaved draft");
+ assert.deepEqual(errors, []);
+ });
+ }
+}
diff --git a/internal/settings/proxy_custom_test.go b/internal/settings/proxy_custom_test.go
new file mode 100644
index 000000000..ad6eec4a6
--- /dev/null
+++ b/internal/settings/proxy_custom_test.go
@@ -0,0 +1,18 @@
+package settings
+
+import "testing"
+
+// The remembered custom proxy holds the proxy's login, so it is this
+// computer's own as the proxy is: a sync or a restored backup keeps the
+// one here and never brings another computer's.
+func TestProxyCustomOwn(t *testing.T) {
+ from := Settings{Theme: "dark", Proxy: "direct", ProxyCustom: "socks5://a:b@there:1080"}
+ from.KeepOwn(Settings{ProxyCustom: "socks5://c:d@here:1080"})
+ if from.ProxyCustom != "socks5://c:d@here:1080" || from.Theme != "dark" {
+ t.Fatalf("KeepOwn: %+v", from)
+ }
+ from.KeepOwn(Settings{})
+ if from.ProxyCustom != "" {
+ t.Fatal("another computer's proxy login taken here")
+ }
+}
diff --git a/internal/settings/settings.go b/internal/settings/settings.go
index 9175cb5ed..c0a716840 100644
--- a/internal/settings/settings.go
+++ b/internal/settings/settings.go
@@ -71,7 +71,13 @@ type Settings struct {
// environment and then the system, "direct" uses none, anything else
// is the proxy (http://, https:// or socks5://; host:port means http).
Proxy string `json:"proxy,omitempty"`
- OTel OTel `json:"otel,omitempty"`
+ // ProxyCustom is the last proxy of the user's own Proxy held, kept
+ // while Proxy is "" or "direct" so that choosing Custom again in
+ // Settings brings back the address and login typed (Zane on Discord).
+ // Save sets it from Proxy, and it is stored as Proxy is. This
+ // computer's own (KeepOwn), as Proxy is.
+ ProxyCustom string `json:"proxyCustom,omitempty"`
+ OTel OTel `json:"otel,omitempty"`
// GitHubToken is a GitHub token the library's requests to GitHub's
// API carry, raising its rate limit from 60 requests an hour to 5,000.
// It is a secret: the Settings page is told only a masked one, and a
@@ -1023,6 +1029,7 @@ func (s *Settings) KeepOwn(cur Settings) {
s.GatewayConversations = cur.GatewayConversations
s.UIFont, s.CodeFont = cur.UIFont, cur.CodeFont
s.Window, s.Proxy, s.Port, s.Dock, s.DockWindow, s.Lightweight = cur.Window, cur.Proxy, cur.Port, cur.Dock, cur.DockWindow, cur.Lightweight
+ s.ProxyCustom = cur.ProxyCustom
s.WindowMaximised, s.KeepAwake, s.KeepAwakeDisplay = cur.WindowMaximised, cur.KeepAwake, cur.KeepAwakeDisplay
s.TrayUsages, s.TrayUsage, s.TrayUsageEvery, s.TrayNoLogos, s.TrayNoBird, s.TrayPace, s.TrayNoCost = cur.TrayUsages, cur.TrayUsage, cur.TrayUsageEvery, cur.TrayNoLogos, cur.TrayNoBird, cur.TrayPace, cur.TrayNoCost
s.GatewayMode = cur.GatewayMode
@@ -1414,6 +1421,9 @@ func save(s Settings, recording bool) error {
if err := CheckProxy(s.Proxy); err != nil {
return err
}
+ if s.Proxy != "" && s.Proxy != "direct" {
+ s.ProxyCustom = s.Proxy
+ }
s.Vision = strings.TrimSpace(s.Vision)
if s.Vision != "" && s.Vision != "off" && !strings.Contains(s.Vision, "/") {
return fmt.Errorf("the vision model must be a model's id such as openai/gpt-5-mini, or off, not %q", s.Vision)