M1.12: notifications as toasts

The host publishes picker, command-line and pump errors as notification
events (Engine::notify, same id sequence) instead of stderr, keeps
notifications and watchFailed published before engine_ready and replays
them after the state replay, so startup warnings (corrupt settings,
journal entries) reach the UI. ipc.ts announces engine_ready once all
subscriptions started together are registered.

Frontend: notifications store and NotificationStack (bottom right, info
auto-dismissed after 5 s, warnings/errors stay, close button and Escape,
at most 5 visible with "+n more", role status/alert); watchFailed maps to
a warning toast; failed commands without their own UI raise an error
toast. Catalog keys notification.settings.*, project.*, vfs.*, watch.*,
command.* plus the runtime allow-list. Docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-16 16:20:45 +02:00
parent 7b7273a947
commit f41df518b5
21 changed files with 1178 additions and 94 deletions

View file

@ -6,7 +6,7 @@
* resolves the theme from the OS preference that {@link startTheme} reports
* with `theme.systemPreference` whenever it changes.
*/
import { onEngineEvent, run } from "./ipc";
import { onEngineEvent, run, type EngineError } from "./ipc";
/** A resolved theme as the engine sends it. */
export interface ResolvedTheme {
@ -68,10 +68,15 @@ export function applyTheme(theme: ResolvedTheme, root: HTMLElement = document.do
* resolves. A failed call keeps the current theme.
*
* @param dark - whether the OS prefers a dark theme.
* @param onError - called with the error of a failed call.
*/
export async function reportSystemPreference(dark: boolean): Promise<void> {
export async function reportSystemPreference(
dark: boolean,
onError?: (error: EngineError) => void,
): Promise<void> {
const result = await run("theme.systemPreference", { dark });
if (!result.ok) {
onError?.(result.error);
return;
}
const theme = toResolvedTheme(result.value);
@ -85,9 +90,10 @@ export async function reportSystemPreference(dark: boolean): Promise<void> {
* reports the OS preference now and whenever it changes. Outside a browser
* with `matchMedia` the OS preference counts as dark.
*
* @param onError - called when reporting the OS preference fails.
* @returns a function that stops following.
*/
export function startTheme(): () => void {
export function startTheme(onError?: (error: EngineError) => void): () => void {
const unsubscribe = onEngineEvent((event) => {
if (event.kind === "themeChanged") {
const theme = toResolvedTheme(event);
@ -98,10 +104,10 @@ export function startTheme(): () => void {
});
const query = typeof window.matchMedia === "function" ? window.matchMedia(DARK_QUERY) : null;
const onChange = (event: MediaQueryListEvent): void => {
void reportSystemPreference(event.matches);
void reportSystemPreference(event.matches, onError);
};
query?.addEventListener("change", onChange);
void reportSystemPreference(query?.matches ?? true);
void reportSystemPreference(query?.matches ?? true, onError);
return () => {
unsubscribe();
query?.removeEventListener("change", onChange);