Spaces:
Paused
Paused
icebear0828 Claude Opus 4.6 (1M context) commited on
Commit ·
ca241c4
1
Parent(s): afe61e7
fix: dark mode tabs, StableText bilingual width, self-update reliability
Browse files- CodeExamples: fix dark mode tab text invisible (text-dim alpha format
broken with CSS variables, use plain #8b949e; tab background use solid
#0d1117 instead of transparent bg-dark/30)
- StableText: use both en+zh invisible references so button width never
jumps on language switch (root cause of recurring i18n layout bug)
- Header: remove version/commit display (already shown in footer)
- self-update: git checkout -- . before pull to discard local drift;
restart via helper script that waits for port release before starting
new process (fixes EADDRINUSE on Windows)
- apply-update: SSE streaming progress (pull → install → build → restart)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Files changed (5)
1234280 unmodified lines285286287288289290291292import { Hono } from "hono";import { serveStatic } from "@hono/node-server/serve-static";import { getConnInfo } from "@hono/node-server/conninfo";import { readFileSync, existsSync } from "fs";280 unmodified linesc.status(400);return c.json({ started: false, error: "Self-update not available in this deploy mode" });}const result = await applyProxySelfUpdate();return c.json(result);});// --- Test connection endpoint ---12345280 unmodified lines286287288289290291292293294295296297298299300301302303304305306import { Hono } from "hono";import { stream } from "hono/streaming";import { serveStatic } from "@hono/node-server/serve-static";import { getConnInfo } from "@hono/node-server/conninfo";import { readFileSync, existsSync } from "fs";280 unmodified linesc.status(400);return c.json({ started: false, error: "Self-update not available in this deploy mode" });}// SSE stream for progress updatesc.header("Content-Type", "text/event-stream");c.header("Cache-Control", "no-cache");c.header("Connection", "keep-alive");return stream(c, async (s) => {const send = (data: Record<string, unknown>) => s.write(`data: ${JSON.stringify(data)}\n\n`);const result = await applyProxySelfUpdate((step, status, detail) => {void send({ step, status, detail });});await send({ ...result, done: true });});});// --- Test connection endpoint ---
9 unmodified lines1011121314154 unmodified lines20212223242526272829303132333435363718 unmodified lines565758596061235 unmodified lines2972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293309 unmodified linesimport { resolve } from "path";import { promisify } from "util";import { getRootDir, isEmbedded } from "./paths.js";// ── Restart ─────────────────────────────────────────────────────────let _closeHandler: (() => Promise<void>) | null = null;4 unmodified lines}/*** Restart the server: try graceful close (up to 3s), then spawn new process and exit.* Works even without a close handler — always spawns and exits.*/function hardRestart(cwd: string): void {const doRestart = () => {console.log("[SelfUpdate] Spawning new process and exiting...");const child = spawn(process.argv[0], process.argv.slice(1), {detached: true,stdio: "ignore",cwd,});child.unref();process.exit(0);};18 unmodified lines});}const execFileAsync = promisify(execFile);const GITHUB_REPO = "icebear0828/codex-proxy";235 unmodified linesreturn result;}/*** Apply proxy self-update: git pull + npm install + npm run build.* Only works in git (CLI) mode.*/export async function applyProxySelfUpdate(): Promise<{ started: boolean; restarting?: boolean; error?: string }> {if (_proxyUpdateInProgress) {return { started: false, error: "Update already in progress" };}_proxyUpdateInProgress = true;const cwd = process.cwd();try {console.log("[SelfUpdate] Pulling latest code...");// Discard local modifications (e.g. package-lock.json drift) that would block git pullawait execFileAsync("git", ["checkout", "--", "."], { cwd, timeout: 10000 }).catch(() => {});await execFileAsync("git", ["pull", "origin", "master"], { cwd, timeout: 60000 });console.log("[SelfUpdate] Installing dependencies...");await execFileAsync("npm", ["install"], { cwd, timeout: 120000, shell: true });console.log("[SelfUpdate] Building...");await execFileAsync("npm", ["run", "build"], { cwd, timeout: 120000, shell: true });console.log("[SelfUpdate] Update complete. Restarting in 500ms...");_proxyUpdateInProgress = false;// Delay 500ms to let HTTP response flush, then restartsetTimeout(() => hardRestart(cwd), 500);return { started: true, restarting: true };9 unmodified lines101112131415164 unmodified lines21222324252627282930313233343536373839404142434445464748495051525354555657585960616263646518 unmodified lines84858687888990919293949596979899235 unmodified lines3353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803819 unmodified linesimport { resolve } from "path";import { promisify } from "util";import { getRootDir, isEmbedded } from "./paths.js";import { getConfig } from "./config.js";// ── Restart ─────────────────────────────────────────────────────────let _closeHandler: (() => Promise<void>) | null = null;4 unmodified lines}/*** Restart the server: try graceful close (up to 3s), then spawn a helper* that waits for the port to be free before starting the new server process.*/function hardRestart(cwd: string): void {const nodeExe = process.argv[0];const serverArgs = process.argv.slice(1);// Inline script: wait for the port to be free, then start the real serverconst helperScript = `const net = require("net");const { spawn } = require("child_process");const args = ${JSON.stringify(serverArgs)};const cwd = ${JSON.stringify(cwd)};let attempts = 0;function tryStart() {attempts++;const s = net.createServer();s.once("error", () => {if (attempts >= 20) process.exit(1);setTimeout(tryStart, 500);});s.once("listening", () => {s.close(() => {spawn(${JSON.stringify(nodeExe)}, args, { detached: true, stdio: "ignore", cwd }).unref();process.exit(0);});});s.listen(${getPort()});}tryStart();`;const doRestart = () => {console.log("[SelfUpdate] Spawning restart helper and exiting...");spawn(nodeExe, ["-e", helperScript], {detached: true,stdio: "ignore",cwd,}).unref();process.exit(0);};18 unmodified lines});}/** Read the configured port for the restart helper. */function getPort(): number {try {const config = getConfig();return config.server.port ?? 8080;} catch {return 8080;}}const execFileAsync = promisify(execFile);const GITHUB_REPO = "icebear0828/codex-proxy";235 unmodified linesreturn result;}/** Progress callback for streaming update status. */export type UpdateProgressCallback = (step: string, status: "running" | "done" | "error", detail?: string) => void;/*** Apply proxy self-update: git pull + npm install + npm run build.* Only works in git (CLI) mode.* @param onProgress Optional callback to report step-by-step progress.*/export async function applyProxySelfUpdate(onProgress?: UpdateProgressCallback,): Promise<{ started: boolean; restarting?: boolean; error?: string }> {if (_proxyUpdateInProgress) {return { started: false, error: "Update already in progress" };}_proxyUpdateInProgress = true;const cwd = process.cwd();const report = onProgress ?? (() => {});try {report("pull", "running");console.log("[SelfUpdate] Pulling latest code...");await execFileAsync("git", ["checkout", "--", "."], { cwd, timeout: 10000 }).catch(() => {});await execFileAsync("git", ["pull", "origin", "master"], { cwd, timeout: 60000 });report("pull", "done");report("install", "running");console.log("[SelfUpdate] Installing dependencies...");await execFileAsync("npm", ["install"], { cwd, timeout: 120000, shell: true });report("install", "done");report("build", "running");console.log("[SelfUpdate] Building...");await execFileAsync("npm", ["run", "build"], { cwd, timeout: 120000, shell: true });report("build", "done");report("restart", "running");console.log("[SelfUpdate] Update complete. Restarting...");_proxyUpdateInProgress = false;// Delay 500ms to let SSE flush, then restartsetTimeout(() => hardRestart(cwd), 500);return { started: true, restarting: true };
189 unmodified lines190191192193194195196189 unmodified lines<h2 class="text-[0.95rem] font-bold">{t("integrationExamples")}</h2><div class="bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl overflow-hidden shadow-sm transition-colors">{/* Protocol Tabs */}<div class="flex border-b border-gray-200 dark:border-border-dark bg-slate-50/50 dark:bg-bg-dark/30">{protocols.map((p) => (<buttonkey={p.id}189 unmodified lines190191192193194195196189 unmodified lines<h2 class="text-[0.95rem] font-bold">{t("integrationExamples")}</h2><div class="bg-white dark:bg-card-dark border border-gray-200 dark:border-border-dark rounded-xl overflow-hidden shadow-sm transition-colors">{/* Protocol Tabs */}<div class="flex border-b border-gray-200 dark:border-border-dark bg-slate-50/50 dark:bg-[#0d1117]">{protocols.map((p) => (<buttonkey={p.id}
79 unmodified lines80818283848586878889909179 unmodified lines<span class="relative inline-flex rounded-full h-2.5 w-2.5 bg-primary" /></span><StableText tKey="serverOnline" class="text-xs font-semibold text-primary">{t("serverOnline")}</StableText>{version && (<span class="text-[0.65rem] font-mono text-primary/70 whitespace-nowrap">v{version}</span>)}{commit && (<span class="text-[0.6rem] font-mono text-primary/40">{commit.slice(0, 7)}</span>)}</div>{/* Star on GitHub */}<a79 unmodified lines80818283848579 unmodified lines<span class="relative inline-flex rounded-full h-2.5 w-2.5 bg-primary" /></span><StableText tKey="serverOnline" class="text-xs font-semibold text-primary">{t("serverOnline")}</StableText></div>{/* Star on GitHub */}<a
12 unmodified lines1314151617181912 unmodified lines"card-dark": "var(--card-dark, #161b22)","border-dark": "var(--border-dark, #30363d)","text-main": "#e6edf3","text-dim": "rgb(139 148 158 / <alpha-value>)",},fontFamily: {display: [12 unmodified lines1314151617181912 unmodified lines"card-dark": "var(--card-dark, #161b22)","border-dark": "var(--border-dark, #30363d)","text-main": "#e6edf3","text-dim": "#8b949e",},fontFamily: {display: [
src/routes/web.ts+16-2
src/self-update.ts+61-10
web/src/components/CodeExamples.tsx+1-1
web/src/components/Header.tsx-6
web/tailwind.config.ts+1-1