close sh;able to save/load projects
This commit is contained in:
25
frontend/src/lib/dev-logger.ts
Normal file
25
frontend/src/lib/dev-logger.ts
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
if (import.meta.env.DEV) {
|
||||
const BACKEND = 'http://127.0.0.1:8000';
|
||||
|
||||
type ConsoleFn = (...args: unknown[]) => void;
|
||||
|
||||
const forward = (level: string, orig: ConsoleFn): ConsoleFn =>
|
||||
(...args: unknown[]) => {
|
||||
orig(...args);
|
||||
const [first, ...rest] = args;
|
||||
fetch(`${BACKEND}/dev/log`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ level, message: String(first ?? ''), args: rest.map(String) }),
|
||||
}).catch(() => {/* backend not running yet */});
|
||||
};
|
||||
|
||||
console.error = forward('error', console.error.bind(console));
|
||||
console.warn = forward('warn', console.warn.bind(console));
|
||||
console.log = forward('log', console.log.bind(console));
|
||||
}
|
||||
@ -47,8 +47,14 @@ window.electronAPI = {
|
||||
return typeof result === 'string' ? result : null;
|
||||
},
|
||||
|
||||
saveProject: async (): Promise<string | null> => {
|
||||
const result = await save({ filters: PROJECT_FILTERS });
|
||||
return result ?? null;
|
||||
},
|
||||
|
||||
getBackendUrl: (): Promise<string> => {
|
||||
return invoke<string>('get_backend_url');
|
||||
// Backend URL is fixed; avoid invoke() which triggers ipc:// CSP errors on Linux/WebKit2GTK
|
||||
return Promise.resolve('http://127.0.0.1:8000');
|
||||
},
|
||||
|
||||
encryptString: (data: string): Promise<string> => {
|
||||
|
||||
Reference in New Issue
Block a user