Remove Electron file-backed debug surface
This commit is contained in:
parent
0aafef3b22
commit
dc2159867c
6 changed files with 11 additions and 252 deletions
|
|
@ -417,8 +417,6 @@ export type AetheriaRtsApi = {
|
|||
surfaceCatalogIndex(): Promise<CultMeshSurfaceCatalogIndexDiagnostic>;
|
||||
eveSurface(request: AetheriaEveSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
|
||||
submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
debugSurface(): Promise<AetheriaMenuSurfaceDocument>;
|
||||
watchDebugSurface(callback: (surface: AetheriaMenuSurfaceDocument) => void): () => void;
|
||||
windowControl(action: "minimize" | "maximize" | "close"): Promise<void>;
|
||||
health(): Promise<unknown>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -130,10 +130,6 @@ export const AetheriaRtsIpcChannels = {
|
|||
surfaceCatalogIndex: "aetheria-rts:surface-catalog-index",
|
||||
eveSurface: "aetheria-rts:eve-surface",
|
||||
submitEveCommand: "aetheria-rts:submit-eve-command",
|
||||
debugSurface: "aetheria-rts:debug-surface",
|
||||
debugSurfaceWatch: "aetheria-rts:debug-surface-watch",
|
||||
debugSurfaceWatchStop: "aetheria-rts:debug-surface-watch-stop",
|
||||
debugSurfaceChanged: "aetheria-rts:debug-surface-changed",
|
||||
windowControl: "aetheria-rts:window-control",
|
||||
health: "aetheria-rts:health",
|
||||
} as const;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
import { app, BrowserWindow, ipcMain, shell, type WebContents } from "electron";
|
||||
import { app, BrowserWindow, ipcMain, shell } from "electron";
|
||||
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
||||
import { createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, statSync, watch, writeFileSync, type FSWatcher } from "node:fs";
|
||||
import { createWriteStream, existsSync, mkdirSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import {
|
||||
AetheriaCultMeshClient,
|
||||
} from "./aetheria-cultmesh.js";
|
||||
import type {
|
||||
AetheriaMenuSurfaceComponent,
|
||||
AetheriaMenuSurfaceDocument,
|
||||
} from "./aetheria-cultmesh.js";
|
||||
import { registerAetheriaRtsIpcHandlers } from "./aetheria-rts-generated-bindings.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
|
@ -19,7 +15,6 @@ const repoRoot = resolve(projectRoot, "..");
|
|||
const logsRoot = resolve(projectRoot, "logs");
|
||||
const runtimeRoot = resolve(process.env.AETHERIA_RUNTIME_ROOT ?? resolve(projectRoot, "runtime"));
|
||||
const runtimeStatePath = resolve(runtimeRoot, "aetheria.cc");
|
||||
const debugSurfacePath = resolve(process.env.AETHERIA_CULTUI_DEBUG_SURFACE_PATH ?? resolve(repoRoot, "GameData", "cultui-debug-surface.cultui"));
|
||||
const daemonDll = resolve(repoRoot, "Aetheria.State.Daemon", "bin", "Debug", "net10.0", "Aetheria.State.Daemon.dll");
|
||||
const rendererIndex = resolve(projectRoot, "wwwroot", "index.html");
|
||||
const clientCultMeshPort = Number.parseInt(process.env.AETHERIA_CLIENT_CULTMESH_PORT ?? "3076", 10);
|
||||
|
|
@ -37,44 +32,6 @@ let daemonProcess: ChildProcessWithoutNullStreams | null = null;
|
|||
let mainWindow: BrowserWindow | null = null;
|
||||
let aetheriaClient: AetheriaCultMeshClient | null = null;
|
||||
let isQuitting = false;
|
||||
let debugSurfaceWatcher: FSWatcher | null = null;
|
||||
let debugSurfaceWatchTimer: NodeJS.Timeout | null = null;
|
||||
const debugSurfaceSubscriptions = new Map<string, WebContents>();
|
||||
|
||||
type AetheriaFileSurfaceDocument = {
|
||||
readonly schema?: string;
|
||||
readonly providerId?: string;
|
||||
readonly providerKind?: string;
|
||||
readonly title?: string;
|
||||
readonly version?: number;
|
||||
readonly updatedAtUtc?: string;
|
||||
readonly surface?: AetheriaFileSurfaceTree;
|
||||
readonly commands?: readonly AetheriaFileCommand[];
|
||||
};
|
||||
|
||||
type AetheriaFileSurfaceTree = {
|
||||
readonly id?: string;
|
||||
readonly root?: AetheriaFileSurfaceComponent;
|
||||
readonly styles?: readonly AetheriaFileStyleToken[];
|
||||
};
|
||||
|
||||
type AetheriaFileSurfaceComponent = {
|
||||
readonly id?: string;
|
||||
readonly kind?: string;
|
||||
readonly props?: unknown;
|
||||
readonly children?: readonly AetheriaFileSurfaceComponent[];
|
||||
};
|
||||
|
||||
type AetheriaFileStyleToken = {
|
||||
readonly name?: string;
|
||||
readonly value?: string;
|
||||
};
|
||||
|
||||
type AetheriaFileCommand = {
|
||||
readonly command?: string;
|
||||
readonly label?: string;
|
||||
readonly transport?: string;
|
||||
};
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
mainWindow = createWindow();
|
||||
|
|
@ -152,7 +109,6 @@ app.on("before-quit", () => {
|
|||
isQuitting = true;
|
||||
void aetheriaClient?.close();
|
||||
stopChild(daemonProcess);
|
||||
closeDebugSurfaceWatcher();
|
||||
});
|
||||
|
||||
function createWindow(): BrowserWindow {
|
||||
|
|
@ -356,26 +312,6 @@ function registerIpc(): void {
|
|||
daemonRunning: daemonProcess != null && !daemonProcess.killed,
|
||||
daemonMode: launchLocalDaemon ? "local" : "remote",
|
||||
}));
|
||||
ipcMain.handle("aetheria-rts:debug-surface", () => readDebugSurface());
|
||||
ipcMain.handle("aetheria-rts:debug-surface-watch", (event, subscriptionId: string) => {
|
||||
if (!subscriptionId)
|
||||
throw new Error("Debug surface subscription id is required.");
|
||||
|
||||
debugSurfaceSubscriptions.set(subscriptionId, event.sender);
|
||||
event.sender.once("destroyed", () => {
|
||||
debugSurfaceSubscriptions.delete(subscriptionId);
|
||||
stopDebugSurfaceWatcherIfIdle();
|
||||
});
|
||||
ensureDebugSurfaceWatcher();
|
||||
event.sender.send("aetheria-rts:debug-surface-changed", {
|
||||
subscriptionId,
|
||||
surface: readDebugSurface(),
|
||||
});
|
||||
});
|
||||
ipcMain.handle("aetheria-rts:debug-surface-watch-stop", (_event, subscriptionId: string) => {
|
||||
debugSurfaceSubscriptions.delete(subscriptionId);
|
||||
stopDebugSurfaceWatcherIfIdle();
|
||||
});
|
||||
ipcMain.handle("aetheria-rts:window-control", (event, action: string) => {
|
||||
const window = BrowserWindow.fromWebContents(event.sender);
|
||||
if (!window)
|
||||
|
|
@ -400,140 +336,6 @@ function registerIpc(): void {
|
|||
});
|
||||
}
|
||||
|
||||
function readDebugSurface(): AetheriaMenuSurfaceDocument {
|
||||
if (!existsSync(debugSurfacePath)) {
|
||||
throw new Error(`CultUI debug surface file not found: ${debugSurfacePath}`);
|
||||
}
|
||||
|
||||
const document = JSON.parse(readFileSync(debugSurfacePath, "utf8")) as AetheriaFileSurfaceDocument;
|
||||
return normalizeDebugSurface(document);
|
||||
}
|
||||
|
||||
function ensureDebugSurfaceWatcher(): void {
|
||||
if (debugSurfaceWatcher)
|
||||
return;
|
||||
|
||||
debugSurfaceWatcher = watch(debugSurfacePath, { persistent: false }, () => {
|
||||
if (debugSurfaceWatchTimer)
|
||||
clearTimeout(debugSurfaceWatchTimer);
|
||||
debugSurfaceWatchTimer = setTimeout(publishDebugSurfaceChange, 50);
|
||||
});
|
||||
debugSurfaceWatcher.once("error", error => {
|
||||
console.warn(`CultUI debug surface watcher failed for ${debugSurfacePath}:`, error);
|
||||
closeDebugSurfaceWatcher();
|
||||
});
|
||||
}
|
||||
|
||||
function publishDebugSurfaceChange(): void {
|
||||
debugSurfaceWatchTimer = null;
|
||||
let surface: AetheriaMenuSurfaceDocument;
|
||||
try {
|
||||
surface = readDebugSurface();
|
||||
} catch (error) {
|
||||
console.warn(error instanceof Error ? error.message : String(error));
|
||||
return;
|
||||
}
|
||||
|
||||
for (const [subscriptionId, webContents] of debugSurfaceSubscriptions) {
|
||||
if (webContents.isDestroyed()) {
|
||||
debugSurfaceSubscriptions.delete(subscriptionId);
|
||||
continue;
|
||||
}
|
||||
|
||||
webContents.send("aetheria-rts:debug-surface-changed", { subscriptionId, surface });
|
||||
}
|
||||
stopDebugSurfaceWatcherIfIdle();
|
||||
}
|
||||
|
||||
function stopDebugSurfaceWatcherIfIdle(): void {
|
||||
if (debugSurfaceSubscriptions.size === 0)
|
||||
closeDebugSurfaceWatcher();
|
||||
}
|
||||
|
||||
function closeDebugSurfaceWatcher(): void {
|
||||
if (debugSurfaceWatchTimer) {
|
||||
clearTimeout(debugSurfaceWatchTimer);
|
||||
debugSurfaceWatchTimer = null;
|
||||
}
|
||||
debugSurfaceWatcher?.close();
|
||||
debugSurfaceWatcher = null;
|
||||
}
|
||||
|
||||
function normalizeDebugSurface(document: AetheriaFileSurfaceDocument): AetheriaMenuSurfaceDocument {
|
||||
const surfaceId = stringOr(document.surface?.id, "aetheria.debug.file_surface");
|
||||
return {
|
||||
providerId: stringOr(document.providerId, "aetheria.debug"),
|
||||
providerKind: stringOr(document.providerKind, "debug.file_surface"),
|
||||
title: stringOr(document.title, "Aetheria Debug Surface"),
|
||||
version: typeof document.version === "number" && Number.isFinite(document.version)
|
||||
? document.version
|
||||
: Date.now(),
|
||||
updatedAtUtc: stringOr(document.updatedAtUtc, new Date().toISOString()),
|
||||
surface: {
|
||||
id: surfaceId,
|
||||
root: normalizeDebugComponent(document.surface?.root, `${surfaceId}.root`),
|
||||
styles: Array.isArray(document.surface?.styles)
|
||||
? document.surface.styles.map(token => ({
|
||||
name: stringOr(token.name, ""),
|
||||
value: stringOr(token.value, ""),
|
||||
}))
|
||||
: [],
|
||||
},
|
||||
commands: Array.isArray(document.commands)
|
||||
? document.commands.map(command => ({
|
||||
command: stringOr(command.command, ""),
|
||||
label: stringOr(command.label, command.command ?? ""),
|
||||
transport: stringOr(command.transport, "debug-log"),
|
||||
}))
|
||||
: [],
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeDebugComponent(
|
||||
component: AetheriaFileSurfaceComponent | undefined,
|
||||
fallbackId: string,
|
||||
): AetheriaMenuSurfaceComponent {
|
||||
if (!component) {
|
||||
return {
|
||||
id: fallbackId,
|
||||
kind: "surface",
|
||||
props: {},
|
||||
children: [],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
id: stringOr(component.id, fallbackId),
|
||||
kind: stringOr(component.kind, "surface"),
|
||||
props: normalizeDebugProps(component.props),
|
||||
children: Array.isArray(component.children)
|
||||
? component.children.map((child, index) => normalizeDebugComponent(child, `${fallbackId}.${index}`))
|
||||
: [],
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeDebugProps(props: unknown): Record<string, string> {
|
||||
if (Array.isArray(props)) {
|
||||
return Object.fromEntries(
|
||||
props
|
||||
.map(prop => objectValue(prop))
|
||||
.filter(prop => prop && typeof prop.key === "string")
|
||||
.map(prop => [String(prop!.key), stringOr(prop!.value, "")]));
|
||||
}
|
||||
|
||||
if (props != null && typeof props === "object") {
|
||||
return Object.fromEntries(
|
||||
Object.entries(props as Record<string, unknown>)
|
||||
.map(([key, value]) => [key, stringOr(value, "")]));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
function stringOr(value: unknown, fallback: string): string {
|
||||
return typeof value === "string" ? value : fallback;
|
||||
}
|
||||
|
||||
function requireClient(): AetheriaCultMeshClient {
|
||||
if (!aetheriaClient)
|
||||
throw new Error("Aetheria CultMesh client is not initialized.");
|
||||
|
|
|
|||
|
|
@ -23,10 +23,6 @@ const channels = {
|
|||
surfaceCatalogIndex: "aetheria-rts:surface-catalog-index",
|
||||
eveSurface: "aetheria-rts:eve-surface",
|
||||
submitEveCommand: "aetheria-rts:submit-eve-command",
|
||||
debugSurface: "aetheria-rts:debug-surface",
|
||||
debugSurfaceWatch: "aetheria-rts:debug-surface-watch",
|
||||
debugSurfaceWatchStop: "aetheria-rts:debug-surface-watch-stop",
|
||||
debugSurfaceChanged: "aetheria-rts:debug-surface-changed",
|
||||
windowControl: "aetheria-rts:window-control",
|
||||
health: "aetheria-rts:health",
|
||||
};
|
||||
|
|
@ -62,21 +58,6 @@ contextBridge.exposeInMainWorld("aetheriaRts", {
|
|||
surfaceCatalogIndex: () => ipcRenderer.invoke(channels.surfaceCatalogIndex),
|
||||
eveSurface: request => ipcRenderer.invoke(channels.eveSurface, request),
|
||||
submitEveCommand: request => ipcRenderer.invoke(channels.submitEveCommand, request),
|
||||
debugSurface: () => ipcRenderer.invoke(channels.debugSurface),
|
||||
watchDebugSurface: callback => {
|
||||
const subscriptionId = `debug-surface-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
||||
const listener = (_event, message) => {
|
||||
if (message?.subscriptionId === subscriptionId) {
|
||||
callback(message.surface);
|
||||
}
|
||||
};
|
||||
ipcRenderer.on(channels.debugSurfaceChanged, listener);
|
||||
void ipcRenderer.invoke(channels.debugSurfaceWatch, subscriptionId);
|
||||
return () => {
|
||||
ipcRenderer.off(channels.debugSurfaceChanged, listener);
|
||||
void ipcRenderer.invoke(channels.debugSurfaceWatchStop, subscriptionId);
|
||||
};
|
||||
},
|
||||
windowControl: request => ipcRenderer.invoke(channels.windowControl, request),
|
||||
health: () => ipcRenderer.invoke(channels.health),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,10 +43,6 @@ const ipcChannels = [
|
|||
["surfaceCatalogIndex", "aetheria-rts:surface-catalog-index"],
|
||||
["eveSurface", "aetheria-rts:eve-surface"],
|
||||
["submitEveCommand", "aetheria-rts:submit-eve-command"],
|
||||
["debugSurface", "aetheria-rts:debug-surface"],
|
||||
["debugSurfaceWatch", "aetheria-rts:debug-surface-watch"],
|
||||
["debugSurfaceWatchStop", "aetheria-rts:debug-surface-watch-stop"],
|
||||
["debugSurfaceChanged", "aetheria-rts:debug-surface-changed"],
|
||||
["windowControl", "aetheria-rts:window-control"],
|
||||
["health", "aetheria-rts:health"],
|
||||
];
|
||||
|
|
@ -1221,8 +1217,6 @@ export type AetheriaRtsApi = {
|
|||
surfaceCatalogIndex(): Promise<CultMeshSurfaceCatalogIndexDiagnostic>;
|
||||
eveSurface(request: AetheriaEveSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
|
||||
submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
debugSurface(): Promise<AetheriaMenuSurfaceDocument>;
|
||||
watchDebugSurface(callback: (surface: AetheriaMenuSurfaceDocument) => void): () => void;
|
||||
windowControl(action: "minimize" | "maximize" | "close"): Promise<void>;
|
||||
health(): Promise<unknown>;
|
||||
};
|
||||
|
|
@ -1535,10 +1529,7 @@ function renderPreload() {
|
|||
const channelLines = renderIpcChannelLines();
|
||||
const apiLines = ipcChannels
|
||||
.filter(([name]) => name !== "viewportFeedUpdate" &&
|
||||
name !== "viewportFeedStop" &&
|
||||
name !== "debugSurfaceWatch" &&
|
||||
name !== "debugSurfaceWatchStop" &&
|
||||
name !== "debugSurfaceChanged")
|
||||
name !== "viewportFeedStop")
|
||||
.map(([name]) => {
|
||||
if (name === "viewportFeed") {
|
||||
return ` watchViewportFeed: (request, callback) => {
|
||||
|
|
@ -1554,23 +1545,6 @@ function renderPreload() {
|
|||
ipcRenderer.off(channels.viewportFeedUpdate, listener);
|
||||
void ipcRenderer.invoke(channels.viewportFeedStop, subscriptionId);
|
||||
};
|
||||
},`;
|
||||
}
|
||||
if (name === "debugSurface") {
|
||||
return ` debugSurface: () => ipcRenderer.invoke(channels.debugSurface),
|
||||
watchDebugSurface: callback => {
|
||||
const subscriptionId = \`debug-surface-\${Date.now().toString(36)}-\${Math.random().toString(36).slice(2)}\`;
|
||||
const listener = (_event, message) => {
|
||||
if (message?.subscriptionId === subscriptionId) {
|
||||
callback(message.surface);
|
||||
}
|
||||
};
|
||||
ipcRenderer.on(channels.debugSurfaceChanged, listener);
|
||||
void ipcRenderer.invoke(channels.debugSurfaceWatch, subscriptionId);
|
||||
return () => {
|
||||
ipcRenderer.off(channels.debugSurfaceChanged, listener);
|
||||
void ipcRenderer.invoke(channels.debugSurfaceWatchStop, subscriptionId);
|
||||
};
|
||||
},`;
|
||||
}
|
||||
const hasNoArguments = name === "health" ||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@ if ($LASTEXITCODE -gt 1) {
|
|||
Write-Error "Stage 7B verifier could not run rg for forbidden public surfaces."
|
||||
}
|
||||
|
||||
$forbiddenFileBackedDebugSurfaceHits = & rg -n 'debugSurface|debug-surface|watchDebugSurface|AETHERIA_CULTUI_DEBUG_SURFACE_PATH|cultui-debug-surface|file_surface|debug-log' Client Electron scripts/generate-rts-bindings.mjs 2>$null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Error "Stage 7B verifier failed: Electron must consume daemon Eve surfaces, not file-backed CultUI debug surfaces.`n$forbiddenFileBackedDebugSurfaceHits"
|
||||
}
|
||||
if ($LASTEXITCODE -gt 1) {
|
||||
Write-Error "Stage 7B verifier could not run rg for file-backed debug surface checks."
|
||||
}
|
||||
|
||||
$required = @(
|
||||
'mapViewport',
|
||||
'objectsViewport',
|
||||
|
|
|
|||
Loading…
Reference in a new issue