M0.4: frontend with Vue 3, Pinia, ESLint, vue-tsc and Vitest

Empty workbench (main area and status bar) themed only through --lt-*
tokens. ipc.ts wraps Tauri invoke so engine calls never reject; the app
store loads app.about. Type-aware ESLint bans floating promises, any and
inline comments. Requires Node 22.12+ for Vite 8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-14 06:37:41 +02:00
parent acc055c063
commit 50bcc95006
15 changed files with 456 additions and 2 deletions

95
ui/src/ipc.ts Normal file
View file

@ -0,0 +1,95 @@
/**
* Bridge from the frontend to the engine.
*
* Every user-visible action runs as an engine command through {@link run}.
* Calls never reject: failures come back as `{ ok: false, error }` so that
* every caller has to handle them.
*/
import { invoke } from "@tauri-apps/api/core";
/** A JSON value as exchanged with the engine. */
export type JsonValue =
| null
| boolean
| number
| string
| JsonValue[]
| { [key: string]: JsonValue };
/** An error reported by the engine, with a stable machine-readable code. */
export interface EngineError {
/** Stable code such as `unknown_command`, `invalid_params` or `internal`. */
code: string;
/** Message for the user. */
message: string;
}
/** Outcome of an engine call. */
export type RunResult<T> = { ok: true; value: T } | { ok: false; error: EngineError };
/** Static description of a command, as listed by the engine. */
export interface CommandInfo {
/** Command id, e.g. `app.about`. */
id: string;
/** Label shown in menus and the command palette. */
label: string;
/** Menu path such as `Help/About Lutra`, or null if not in a menu. */
menuPath: string | null;
/** Default shortcut in Lutra notation (`Mod+Q`), or null. */
defaultShortcut: string | null;
/** Documentation of the params object. */
params: string;
/** Whether the command can run in the current state. */
enabled: boolean;
}
/**
* Turns whatever a failed `invoke` rejected with into an {@link EngineError}.
*
* @param reason - the rejection value; the shell sends `{ code, message }`.
* @returns the engine error, or an `ipc` error for anything else (for example
* when the page runs outside the Tauri shell).
*/
export function toEngineError(reason: unknown): EngineError {
if (typeof reason === "object" && reason !== null && "code" in reason && "message" in reason) {
const { code, message } = reason;
if (typeof code === "string" && typeof message === "string") {
return { code, message };
}
}
const message = reason instanceof Error ? reason.message : String(reason);
return { code: "ipc", message };
}
/**
* Runs an engine command.
*
* @param commandId - the command id, e.g. `app.about`.
* @param params - the command's params object.
* @returns the command's result, or the error it failed with.
*/
export async function run<T = JsonValue>(
commandId: string,
params: JsonValue = {},
): Promise<RunResult<T>> {
try {
const value = await invoke<T>("engine_execute", { command: commandId, params });
return { ok: true, value };
} catch (reason: unknown) {
return { ok: false, error: toEngineError(reason) };
}
}
/**
* Lists every command the engine knows, with its current enabled state.
*
* @returns the commands, or the error the call failed with.
*/
export async function listCommands(): Promise<RunResult<CommandInfo[]>> {
try {
const value = await invoke<CommandInfo[]>("engine_list_commands");
return { ok: true, value };
} catch (reason: unknown) {
return { ok: false, error: toEngineError(reason) };
}
}