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

49
ui/src/App.vue Normal file
View file

@ -0,0 +1,49 @@
<script setup lang="ts">
/**
* Root component: the empty workbench of milestone M0, a main area and the
* status bar. Loads product information from the engine on mount.
*/
import { onMounted } from "vue";
import StatusBar from "./components/StatusBar.vue";
import { useAppStore } from "./stores/app";
const app = useAppStore();
onMounted(() => {
void app.loadAbout();
});
</script>
<template>
<div class="workbench">
<main
class="workbench__main"
data-test="main"
>
<p class="workbench__hint">
{{ app.about?.slogan ?? "" }}
</p>
</main>
<StatusBar />
</div>
</template>
<style scoped>
.workbench {
display: flex;
flex-direction: column;
height: 100%;
}
.workbench__main {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
background: var(--lt-editor-bg);
}
.workbench__hint {
color: var(--lt-fg-muted);
}
</style>

View file

@ -0,0 +1,45 @@
<script setup lang="ts">
/**
* Status bar along the bottom of the main window. Shows the product name and
* version, or the last engine error.
*/
import { computed } from "vue";
import { useAppStore } from "../stores/app";
const app = useAppStore();
/** Text on the left side of the bar. */
const label = computed(() => {
if (app.lastError) {
return app.lastError.message;
}
return app.about ? `${app.about.name} ${app.about.version}` : "";
});
</script>
<template>
<footer
class="status-bar"
:class="{ 'status-bar--error': app.lastError }"
data-test="status-bar"
>
<span>{{ label }}</span>
</footer>
</template>
<style scoped>
.status-bar {
display: flex;
align-items: center;
height: 24px;
padding: 0 8px;
background: var(--lt-statusbar-bg);
color: var(--lt-statusbar-fg);
border-top: 1px solid var(--lt-border);
font-size: var(--lt-font-size-small);
}
.status-bar--error {
color: var(--lt-error);
}
</style>

10
ui/src/env.d.ts vendored Normal file
View file

@ -0,0 +1,10 @@
/**
* Module declaration for single-file components, so that tools without Vue
* support (the ESLint type checker) see `.vue` imports as components.
* `vue-tsc` resolves the real component types.
*/
declare module "*.vue" {
import type { DefineComponent } from "vue";
const component: DefineComponent;
export default component;
}

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) };
}
}

10
ui/src/main.ts Normal file
View file

@ -0,0 +1,10 @@
/**
* Entry point of the Lutra frontend: creates the Vue app with Pinia and
* mounts it on `#app`.
*/
import { createPinia } from "pinia";
import { createApp } from "vue";
import App from "./App.vue";
import "./styles/base.css";
createApp(App).use(createPinia()).mount("#app");

38
ui/src/stores/app.ts Normal file
View file

@ -0,0 +1,38 @@
/**
* Application-wide state: product information from `app.about` and the
* last error the shell reported.
*/
import { defineStore } from "pinia";
import { ref } from "vue";
import { run, type EngineError } from "../ipc";
/** Result of the `app.about` command. */
export interface AboutInfo {
/** Product name. */
name: string;
/** Version of the running build. */
version: string;
/** Slogan shown in the About window. */
slogan: string;
}
/** Store holding product information and the last engine error. */
export const useAppStore = defineStore("app", () => {
/** Product information, null until loaded. */
const about = ref<AboutInfo | null>(null);
/** Last error from the engine, null if none. */
const lastError = ref<EngineError | null>(null);
/** Loads product information from the engine; on failure records the error. */
async function loadAbout(): Promise<void> {
const result = await run<AboutInfo>("app.about");
if (result.ok) {
about.value = result.value;
lastError.value = null;
} else {
lastError.value = result.error;
}
}
return { about, lastError, loadAbout };
});

19
ui/src/styles/base.css Normal file
View file

@ -0,0 +1,19 @@
/**
* Base layout of the Lutra window. Colours and fonts come only from the
* theme tokens (`--lt-*`) that the desktop shell injects before first paint.
*/
html,
body,
#app {
height: 100%;
margin: 0;
}
body {
background: var(--lt-bg);
color: var(--lt-fg);
font-family: var(--lt-font-ui);
font-size: var(--lt-font-size-ui);
overflow: hidden;
user-select: none;
}