mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-18 13:23:33 +08:00
PR #428 added a General Settings zoom slider after the desktop shortcut work already introduced a native-first app zoom controller. Keeping both paths would create double scaling and stale UI state, so the slider now routes through the existing controller and store state while the app shell no longer applies a second CSS zoom. Constraint: UI zoom is device-local display state and should not be written into shared user settings. Rejected: Keep cc-haha-ui-zoom plus AppShell style.zoom | it conflicts with shortcut zoom and multiplies visual scale. Rejected: Persist zoom through /api/settings/user | it would sync display-specific state across machines. Confidence: high Scope-risk: moderate Directive: Keep app zoom behind desktop/src/lib/appZoom.ts; do not add another storage key or DOM zoom application point without migration and shortcut sync tests. Tested: cd desktop && bun run test -- --run src/lib/appZoom.test.ts src/hooks/useKeyboardShortcuts.test.tsx src/stores/settingsStore.test.ts src/__tests__/generalSettings.test.tsx src/lib/persistenceMigrations.test.ts src/lib/doctorRepair.test.ts Tested: bun run check:desktop Not-tested: Real Windows/Linux desktop runtime smoke.
86 lines
2.1 KiB
TypeScript
86 lines
2.1 KiB
TypeScript
import { doctorApi, type DoctorReportRepairResponse } from '../api/doctor'
|
|
import { APP_ZOOM_STORAGE_KEY, LEGACY_UI_ZOOM_STORAGE_KEY } from './appZoom'
|
|
import { DESKTOP_PERSISTENCE_VERSION_KEY } from './persistenceMigrations'
|
|
|
|
export const SAFE_DOCTOR_STORAGE_KEYS = [
|
|
'cc-haha-open-tabs',
|
|
'cc-haha-session-runtime',
|
|
'cc-haha-theme',
|
|
'cc-haha-locale',
|
|
APP_ZOOM_STORAGE_KEY,
|
|
LEGACY_UI_ZOOM_STORAGE_KEY,
|
|
DESKTOP_PERSISTENCE_VERSION_KEY,
|
|
] as const
|
|
|
|
type DoctorStorage = Pick<Storage, 'getItem' | 'removeItem'>
|
|
|
|
export type LocalDoctorRepairResult = {
|
|
removedKeys: string[]
|
|
missingKeys: string[]
|
|
failedKeys: string[]
|
|
}
|
|
|
|
export type DoctorRepairResult = {
|
|
local: LocalDoctorRepairResult
|
|
server: DoctorReportRepairResponse | null
|
|
serverError: string | null
|
|
}
|
|
|
|
function getDefaultDoctorStorage(): DoctorStorage | null {
|
|
try {
|
|
return globalThis.localStorage ?? null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function runLocalDoctorRepair(storage: DoctorStorage | null = getDefaultDoctorStorage()): LocalDoctorRepairResult {
|
|
if (!storage) {
|
|
return {
|
|
removedKeys: [],
|
|
missingKeys: [...SAFE_DOCTOR_STORAGE_KEYS],
|
|
failedKeys: [],
|
|
}
|
|
}
|
|
|
|
const removedKeys: string[] = []
|
|
const missingKeys: string[] = []
|
|
const failedKeys: string[] = []
|
|
|
|
for (const key of SAFE_DOCTOR_STORAGE_KEYS) {
|
|
try {
|
|
if (storage.getItem(key) === null) {
|
|
missingKeys.push(key)
|
|
continue
|
|
}
|
|
storage.removeItem(key)
|
|
removedKeys.push(key)
|
|
} catch {
|
|
failedKeys.push(key)
|
|
}
|
|
}
|
|
|
|
return { removedKeys, missingKeys, failedKeys }
|
|
}
|
|
|
|
export async function runDoctorRepair(options?: {
|
|
includeServer?: boolean
|
|
storage?: DoctorStorage | null
|
|
}): Promise<DoctorRepairResult> {
|
|
const local = runLocalDoctorRepair(options?.storage)
|
|
if (options?.includeServer === false) {
|
|
return { local, server: null, serverError: null }
|
|
}
|
|
|
|
try {
|
|
const server = await doctorApi.reportAndRepair()
|
|
return { local, server, serverError: null }
|
|
} catch (error) {
|
|
return {
|
|
local,
|
|
server: null,
|
|
serverError: error instanceof Error ? error.message : String(error),
|
|
}
|
|
}
|
|
}
|