still working on crashes

This commit is contained in:
2026-04-08 01:42:00 -06:00
parent 2406b0a2e7
commit 1e02bf32d9
8 changed files with 203 additions and 30 deletions

View File

@ -1,13 +1,29 @@
/**
* Dev-only console interceptor.
* Forwards console.error / console.warn to the backend /dev/log endpoint,
* which appends them to webview.log so the agent can read it.
* which appends them to a backend-managed dev log file.
*/
if (import.meta.env.DEV) {
const BACKEND = 'http://127.0.0.1:8000';
type ConsoleFn = (...args: unknown[]) => void;
const serialize = (value: unknown): string => {
if (typeof value === 'string') return value;
if (value instanceof Error) {
return JSON.stringify({
name: value.name,
message: value.message,
stack: value.stack,
});
}
try {
return JSON.stringify(value);
} catch {
return String(value);
}
};
const forward = (level: string, orig: ConsoleFn): ConsoleFn =>
(...args: unknown[]) => {
orig(...args);
@ -15,7 +31,7 @@ if (import.meta.env.DEV) {
fetch(`${BACKEND}/dev/log`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ level, message: String(first ?? ''), args: rest.map(String) }),
body: JSON.stringify({ level, message: serialize(first ?? ''), args: rest.map(serialize) }),
}).catch(() => {/* backend not running yet */});
};

View File

@ -28,31 +28,48 @@ const EXPORT_FILTERS = [
const BACKEND_PORT = import.meta.env.VITE_BACKEND_PORT || '8000';
const BACKEND_URL = `http://127.0.0.1:${BACKEND_PORT}`;
const debugBridge = (event: string, details?: Record<string, unknown>) => {
if (!import.meta.env.DEV) return;
console.log('[tauri-bridge]', event, details ?? {});
};
window.desktopAPI = {
openFile: async (_options?: Record<string, unknown>): Promise<string | null> => {
debugBridge('openFile:dialogOpen');
const result = await open({
multiple: false,
filters: VIDEO_FILTERS,
});
return typeof result === 'string' ? result : null;
const path = typeof result === 'string' ? result : null;
debugBridge('openFile:dialogResult', { path });
return path;
},
saveFile: async (_options?: Record<string, unknown>): Promise<string | null> => {
debugBridge('saveFile:dialogOpen');
const result = await save({ filters: EXPORT_FILTERS });
return result ?? null;
const path = result ?? null;
debugBridge('saveFile:dialogResult', { path });
return path;
},
openProject: async (): Promise<string | null> => {
debugBridge('openProject:dialogOpen');
const result = await open({
multiple: false,
filters: PROJECT_FILTERS,
});
return typeof result === 'string' ? result : null;
const path = typeof result === 'string' ? result : null;
debugBridge('openProject:dialogResult', { path });
return path;
},
saveProject: async (): Promise<string | null> => {
debugBridge('saveProject:dialogOpen');
const result = await save({ filters: PROJECT_FILTERS });
return result ?? null;
const path = result ?? null;
debugBridge('saveProject:dialogResult', { path });
return path;
},
getBackendUrl: (): Promise<string> => {
@ -77,10 +94,12 @@ window.desktopAPI = {
},
readFile: (path: string): Promise<string> => {
debugBridge('readFile', { path });
return readTextFile(path);
},
writeFile: async (path: string, content: string): Promise<boolean> => {
debugBridge('writeFile', { path, size: content.length });
await writeTextFile(path, content);
return true;
},