diff --git a/AGENTS.md b/AGENTS.md index 31ff137..d19a473 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,6 +66,7 @@ build/ ← generated by switch-icon.js (gitignored) - `electron/config.ts`: YAML config management (sparse save) - `electron/auth.ts`: Auth data persistence (JSON file) - `electron/core/`: @xmcl/* integrations (auth, installer, launcher, modrinth, instance) +- `electron/core/background-image.ts`: 背景图处理服务(自选背景降采样/重编码,程序本体资源管理) - `electron/handlers/`: IPC handlers (config, auth, install, launch, mods, instance, background, task, system, window) ## Frontend notes @@ -73,6 +74,12 @@ build/ ← generated by switch-icon.js (gitignored) - `src/api/ipc.ts`: Core IPC utilities (invoke, onIpcEvent) - `src/api/*.ts`: API modules wrapping IPC calls - `src/stores/`: Zustand state management +- `src/resources/`: 启动器程序本体「资源管理」子系统(与游戏无关): + - `registry.ts` 资源注册表服务(acquire/release、引用计数、预算 + LRU 逐出、onRelease 释放回调) + - `store.ts` 注册表 → zustand 镜像(调试面板消费) + - `image.ts` 图片解码管线(按显示尺寸降采样)、`hooks.ts`/`ManagedImage.tsx` 复用组件(供列表缩略图) + - 当前接线点:`BackgroundLayer` 把当前背景登记为 `background` 类资源;主进程 `background:prepare` 在进渲染端前压小大图 + - 监控入口:debug 页「资源与内存」(`debug-resource`) - `src/hooks/useTheme.ts`: Dark mode sync with Electron theme - `src/components/system/WindowControls.tsx`: Custom window controls (min/max/close), uses ` + + + + + {snapshot.entries.length === 0 ? ( +

暂无缓存条目(自定义背景图生效后此处可见 background:current:*)

+ ) : ( +
+ + + + + + + + + + + {snapshot.entries.slice(0, 40).map((e) => ( + + + + + + + ))} + +
Key类型估算引用
+ {e.key} + {KIND_LABELS[e.kind] ?? e.kind}{fmtMB(e.bytes)}{e.refs}
+
+ )} + + + + + + + + + + + ); +} diff --git a/src/resources/registry.ts b/src/resources/registry.ts index 38f9c1d..eb023f5 100644 --- a/src/resources/registry.ts +++ b/src/resources/registry.ts @@ -99,9 +99,10 @@ class ResourceRegistry { payload: null, inFlight: null, cache: opts.cache ?? true, - onRelease: opts.onRelease, }; this.entries.set(key, entry); + // 用桥接闭包把调用方的 (payload: T) => void 适配为内部 (payload: unknown) => void + entry.onRelease = opts.onRelease ? (payload: unknown): void => opts.onRelease?.(payload as T) : undefined; const run = async (): Promise => { let value: T | null = null; diff --git a/src/stores/routeStore.ts b/src/stores/routeStore.ts index 63e8654..08d1939 100644 --- a/src/stores/routeStore.ts +++ b/src/stores/routeStore.ts @@ -32,8 +32,8 @@ export type RouteKey = | "debug-version-card" | "debug-update" | "debug-task" + | "debug-resource" | "debug-crash"; - export type TitleBarMode = "default" | "sub" | "window" | "oobe"; export type TransitionDirection = "forward" | "backward"; @@ -82,6 +82,7 @@ export const allRoutes: RouteItem[] = [ { key: "debug-version-card", label: "版本卡片调试", path: "/debug/version-card", hidden: true }, { key: "debug-update", label: "更新功能测试", path: "/debug/update", hidden: true }, { key: "debug-task", label: "任务队列调试", path: "/debug/task", hidden: true }, + { key: "debug-resource", label: "资源与内存", path: "/debug/resource", hidden: true }, ]; const topLevelKeys = new Set(routes.map((r) => r.key));