From 9a19c0a8611458031ba875f2cde840bf53e60cb1 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Thu, 19 Mar 2026 11:21:50 -0700 Subject: [PATCH] Consolidate perfTiming state into a single `perf` object Removes the separate variable and setter in favor of a plain object, making the mutable state easier to track and eliminating a needless abstraction. --- src/server/api/system.ts | 22 +++++++++++----------- src/server/proxy.ts | 6 ++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/server/api/system.ts b/src/server/api/system.ts index 80db653..ba0844e 100644 --- a/src/server/api/system.ts +++ b/src/server/api/system.ts @@ -1,5 +1,5 @@ import { allApps, APPS_DIR, onChange } from '$apps' -import { perfTiming, setPerfTiming } from '../proxy' +import { perf } from '../proxy' import { onHostLog } from '../tui' import { Hype } from '@because/hype' import { cpus, freemem, platform, totalmem } from 'os' @@ -278,22 +278,22 @@ function pushHostLog(text: string) { for (const listener of unifiedLogListeners) listener(line) } +// Perf timing toggle +router.get('/perf', c => c.json({ perfTiming: perf.timing })) +router.post('/perf', async c => { + const body = await c.req.json<{ on?: boolean }>().catch(() => ({})) + const on = body.on ?? !perf.timing + perf.timing = on + console.log(`[perf] timing ${on ? 'enabled' : 'disabled'}`) + return c.json({ perfTiming: on }) +}) + // Subscribe to app changes to collect logs onChange(collectLogs) // Subscribe to host-level log messages onHostLog(pushHostLog) -// Perf timing toggle -router.get('/perf', c => c.json({ perfTiming })) -router.post('/perf', async c => { - const body = await c.req.json<{ on?: boolean }>().catch(() => ({})) - const on = body.on ?? !perfTiming - setPerfTiming(on) - console.log(`[perf] timing ${on ? 'enabled' : 'disabled'}`) - return c.json({ perfTiming: on }) -}) - // Restart server (systemd brings it back) router.post('/restart', c => { setTimeout(() => process.exit(0), 100) diff --git a/src/server/proxy.ts b/src/server/proxy.ts index b2dd7f0..1c373a7 100644 --- a/src/server/proxy.ts +++ b/src/server/proxy.ts @@ -3,9 +3,7 @@ import { getAppBySubdomain } from '$apps' export type { WsData } -export let perfTiming = false - -export const setPerfTiming = (on: boolean) => { perfTiming = on } +export const perf = { timing: false } const pendingMessages = new Map, (string | ArrayBuffer | Uint8Array)[]>() const upstreams = new Map, WebSocket>() @@ -64,7 +62,7 @@ export async function proxySubdomain(subdomain: string, req: Request): Promise