Storage (desktop): - The webview can no longer name a path. Five commands that read, wrote, listed and deleted any path the frontend sent are replaced by name-only commands (backups, logs) that resolve under the app data folder, and by export/import commands that open the native dialog from Rust, so the only file touched is the one the user picked (json/jsonl/txt/csv/md, 20 MB). The fs and shell plugins are removed (Rust, npm, capabilities). - The settings "mirror" file is gone: it was written next to the data folder (a missing path separator) and never read back. On first start the file becomes a restorable backup — never applied on its own — and the stray log folder is merged into the right one. - Automatic backups on desktop: after library changes (quiet 30 s, at most every 10 min, skipped when unchanged or empty), newest ten kept, plus one before every restore. Settings lists them with Restore. - One tray icon, built in code with the app icon (the config entry that could add a second, iconless one is removed). Backup & restore (every platform): - Format 2 files carry each section's store version; imports run the stores' own migrations (now exported functions), then a whitelist sanitizer: known fields and values only, editor limits, safe unique ids. - Reads every earlier export: v0.15-v0.38 envelopes (log exports were labelled "history"), pre-v0.15 bare arrays, the old desktop data file. - Restore dialog: new / already here / different per item, merge (keep the newer one, or both) or replace, section and item selection, one step, Undo. Newer-version sections are shown, not restored. - Settings: Back up (choose sections) / Restore / drop a file. Consent and panel state are never exported or overwritten. - History export as CSV (spreadsheet-safe) or JSON; logs export as "logs"; dated file names; no more 250 ms timer guessing that a picker was cancelled. Library: - Templates save every editor field; presets save store link types and the other per-game fields; profiles save donate, community links and the custom graphics preset. Edit forms can update from the current editor, start fresh each time they open, and save on Enter. Toasts translated. Dev: Vite no longer watches src-tauri (cargo's locked .dll crashed `tauri dev` on Windows). Verified in `tauri dev` on Windows under a test identifier: legacy file recovered, old logs merged, auto backup, restore from the legacy backup with a backup before it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
3.7 KiB
TypeScript
96 lines
3.7 KiB
TypeScript
import { Component, type ErrorInfo, type ReactNode } from "react";
|
|
import { ErrorPage } from "@components/errors/ErrorPage";
|
|
|
|
interface ErrorBoundaryProps {
|
|
/** Children to render normally. The boundary only kicks in on render
|
|
* errors thrown inside this subtree. */
|
|
children: ReactNode;
|
|
/** Human label that appears in the fallback UI to tell the user
|
|
* *what* crashed (e.g. "Profiles tab", "Editor"). Defaults to a
|
|
* generic "this section" copy so the boundary still degrades nicely
|
|
* if a caller forgets the prop. */
|
|
label?: string;
|
|
/** Optional callback fired on every catch — useful in tests, or to
|
|
* funnel boundary errors into a centralised reporter. The component
|
|
* also logs to `useLogStore` directly so the in-app Log tab gets a
|
|
* copy regardless. */
|
|
onError?: (error: Error, info: ErrorInfo) => void;
|
|
}
|
|
|
|
interface ErrorBoundaryState {
|
|
error: Error | null;
|
|
}
|
|
|
|
/**
|
|
* Class-based React error boundary — there is still no hook equivalent
|
|
* in React 18 (and as of React 19 only `useErrorBoundary` from external
|
|
* libraries cover the gap). Catches *render-time* exceptions from any
|
|
* descendant component and swaps in a fallback UI so the rest of the
|
|
* app keeps working.
|
|
*
|
|
* Motivation: v0.13.x had no boundary anywhere, so any render error —
|
|
* most commonly `Cannot convert undefined or null to object` when a
|
|
* malformed profile / template was loaded via Object spread — escalated
|
|
* into a black-screen crash. The boundary nets those errors at the
|
|
* route level, surfaces a recovery affordance, and writes a structured
|
|
* entry to the in-app log tab so the user can copy it into a bug
|
|
* report.
|
|
*
|
|
* Per-route boundaries (one per `<Route>`) mean a crash on the Profiles
|
|
* tab does not take down the Editor — the user can navigate away,
|
|
* adjust state, and click "Try again" to remount the broken subtree.
|
|
*
|
|
* Does NOT catch: async errors (Promise rejections), event-handler
|
|
* errors, SSR errors. For those use try/catch + the in-app logger
|
|
* directly (see `utils/backup/restore-flow.ts`).
|
|
*/
|
|
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
state: ErrorBoundaryState = { error: null };
|
|
|
|
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
|
return { error };
|
|
}
|
|
|
|
componentDidCatch(error: Error, info: ErrorInfo): void {
|
|
// Best-effort: pull the in-app logger lazily so the boundary stays
|
|
// importable from non-React entry points. We never let the logger
|
|
// itself throw a secondary error — if the log store is missing we
|
|
// fall back to the browser console.
|
|
try {
|
|
// Dynamic import dodges a circular dep with files that themselves
|
|
// import ErrorBoundary, e.g. when the boundary is mounted in
|
|
// main.tsx before the store has registered.
|
|
void import("@utils/logger").then(({ logger }) => {
|
|
logger.error(
|
|
"errorBoundary",
|
|
`[${this.props.label ?? "app"}] ${error.message}`,
|
|
info.componentStack ?? error.stack ?? "",
|
|
);
|
|
});
|
|
} catch {
|
|
console.error("ErrorBoundary caught:", error, info);
|
|
}
|
|
this.props.onError?.(error, info);
|
|
}
|
|
|
|
private handleReset = (): void => {
|
|
this.setState({ error: null });
|
|
};
|
|
|
|
render(): ReactNode {
|
|
if (!this.state.error) return this.props.children;
|
|
|
|
// The visible copy is now generic + localized via the shared ErrorPage
|
|
// (contained variant). The `label` is still logged in componentDidCatch
|
|
// so bug reports keep the "which subtree crashed" context.
|
|
return (
|
|
<ErrorPage
|
|
kind="runtime"
|
|
variant="contained"
|
|
onReset={this.handleReset}
|
|
detail={this.state.error.message}
|
|
/>
|
|
);
|
|
}
|
|
}
|