perf: optimize app startup and background lifecycles

This commit is contained in:
inman
2026-08-19 00:56:15 +08:00
parent 31332f6d76
commit 927e13349b
121 changed files with 4359 additions and 1400 deletions

View File

@@ -1,6 +1,8 @@
import { ipcMain } from 'electron';
import { getPort } from '../../utils/config';
import { getHostApiToken } from '../../api/server';
import type { HostApiContext } from '../../api/context';
import { shouldUseLoopbackHostApi } from '../../api/host-api-transport';
import {
getRendererCapability,
RENDERER_CAPABILITY_HEADER,
@@ -13,7 +15,7 @@ type HostApiFetchRequest = {
body?: unknown;
};
export function registerHostApiProxyHandlers(): void {
export function registerHostApiProxyHandlers(hostApiContext?: HostApiContext): void {
const hostApiPort = getPort('NIANCODE_HOST_API');
// Expose the per-session auth token to the renderer so the browser-fallback
@@ -56,6 +58,17 @@ export function registerHostApiProxyHandlers(): void {
}
}
if (hostApiContext && !shouldUseLoopbackHostApi(path, method)) {
const { dispatchHostApiRequest } = await import('../../api/host-api-dispatcher');
const data = await dispatchHostApiRequest(hostApiContext, {
path,
method,
headers,
...(body === undefined ? {} : { body }),
});
return { ok: true, data: { ...data, transport: 'dispatcher' as const } };
}
// The Host API is an in-process loopback server. Using Electron's
// proxy-aware network stack here can incorrectly send 127.0.0.1 through
// a configured system proxy and surface a generic `fetch failed` before