mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 03:50:52 +00:00
* perf: add opt-in startup timeline and real-app startup harness - electron/perfTrace.cjs records first-occurrence startup marks in the main process when NETCATTY_PERF_TRACE=1 (a no-op otherwise), then writes the main-window renderer timeline (navigation, paint, netcatty:* marks, JS heap) and app.getAppMetrics() to JSON after the first renderer-ready signal. - Marks: main.cjs entry / modules loaded / whenReady, main window creation, registerBridges and plugin-host start/end, loadURL, did-finish-load, renderer ready, window shown. The renderer adds three performance.mark() calls (entry evaluated, App mounted, renderer ready), also visible in DevTools. - scripts/perf-startup.live.cjs (npm run perf:startup) launches the built app N times against a throwaway --user-data-dir profile with ssh:// deep-link registration disabled, optionally seeds synthetic hosts over CDP, and reports cold plus warm p50/p90. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(harness): add --profile option to reuse a startup profile Lets the harness keep one profile across invocations, e.g. to compare warm V8 code caches across builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: retrigger CI after flaky monitorRuntimeIsolation failure Previous lint-and-test failed on known-preexisting `useEffect is not defined` in monitorRuntimeIsolation.test.ts. * chore: retrigger CI after monitorRuntimeIsolation useEffect flake Known pre-existing flake: monitor controls test fails with `useEffect is not defined`. Empty commit to re-run once. * test(app): bind React hooks in monitorRuntimeIsolation VM sandbox Extracting component declarations drops their React imports, leaving bare hooks such as useEffect undefined in the VM. Inject common React hooks and APIs while preserving explicit binding overrides to prevent intermittent monitor isolation failures in CI. Stub the startup performance mark through App test bindings so the mount effect can execute without browser globals. Production components remain unchanged. Validation: monitorRuntimeIsolation passed five consecutive runs. Plain npm run lint found 17 existing errors in git-ignored scratch files; excluding only _t.mjs and sim-4107.mjs passed with zero errors and eight existing warnings. * chore: retrigger CI after plugin-contract runner cancel Lint/schema passed; plugin-contract step cancelled by the runner (not a test failure). Empty commit to re-queue. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: binaricat <binaricat@users.noreply.github.com>
188 lines
6.7 KiB
TypeScript
188 lines
6.7 KiB
TypeScript
import React, { useEffect, useRef, useState } from 'react';
|
|
|
|
import { I18nProvider } from '../application/i18n/I18nProvider';
|
|
import { useAppLockBridge } from '../application/state/useAppLockBridge';
|
|
import { type AppLockReason, useAppLockState } from '../application/state/useAppLockState';
|
|
import { useSettingsState } from '../application/state/useSettingsState';
|
|
import { ToastProvider } from './ui/toast';
|
|
import { TooltipProvider } from './ui/tooltip';
|
|
import { AppLockOverlay } from './AppLockOverlay';
|
|
|
|
type SettingsState = ReturnType<typeof useSettingsState>;
|
|
type AppLockState = ReturnType<typeof useAppLockState>;
|
|
|
|
export interface AppLockGateRenderContext {
|
|
settings: SettingsState;
|
|
appLock: AppLockState;
|
|
}
|
|
|
|
interface AppLockGateProps {
|
|
children: (ctx: AppLockGateRenderContext) => React.ReactNode;
|
|
notifyRendererReady?: boolean;
|
|
/**
|
|
* Mount route children immediately (even before app-lock init / while locked).
|
|
* Terminal popups need this so their one-shot config IPC listeners register
|
|
* before main's post-loadURL send is only held in preload pending state —
|
|
* AppLockGate otherwise withholds children until async lock state resolves.
|
|
*/
|
|
forceRenderChildren?: boolean;
|
|
settingsOptions?: Parameters<typeof useSettingsState>[0];
|
|
}
|
|
|
|
interface AppLockGateDeps {
|
|
useSettingsState: typeof useSettingsState;
|
|
useAppLockState: typeof useAppLockState;
|
|
useAppLockBridge: typeof useAppLockBridge;
|
|
}
|
|
|
|
/**
|
|
* Withhold first content mount while the gate is locked for any reason
|
|
* (startup / idle / background / manual). A new renderer that reports ready
|
|
* before unlock would let main deliver ssh:// deep links into App handlers and
|
|
* start connections behind the lock overlay. Once children have mounted (e.g.
|
|
* idle re-lock after use), keep them mounted under the overlay.
|
|
*/
|
|
export function shouldRenderAppLockGateChildren(input: {
|
|
initialized: boolean;
|
|
locked: boolean;
|
|
lockReason: AppLockReason | null;
|
|
hasRenderedChildren: boolean;
|
|
forceRenderChildren?: boolean;
|
|
}): boolean {
|
|
if (input.forceRenderChildren) return true;
|
|
if (!input.initialized && !input.hasRenderedChildren) return false;
|
|
if (input.locked && !input.hasRenderedChildren) return false;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Deep-link delivery waits on rendererReady. Only mark the renderer ready once
|
|
* app children are allowed to mount, so unlock (not the 15s readiness timeout)
|
|
* is what unblocks pending ssh:// links after a locked first paint.
|
|
*/
|
|
export function shouldNotifyAppLockGateRendererReady(input: {
|
|
notifyRendererReady: boolean;
|
|
renderChildren: boolean;
|
|
}): boolean {
|
|
return input.notifyRendererReady && input.renderChildren;
|
|
}
|
|
|
|
/** Queue external actions (e.g. ssh:// deep links) while the app lock is held. */
|
|
export function shouldDeferExternalActionWhileAppLocked(input: {
|
|
locked: boolean;
|
|
}): boolean {
|
|
return input.locked === true;
|
|
}
|
|
|
|
export function createAppLockGate(deps: AppLockGateDeps): React.FC<AppLockGateProps> {
|
|
const AppLockGateImpl: React.FC<AppLockGateProps> = ({
|
|
children,
|
|
notifyRendererReady = true,
|
|
forceRenderChildren = false,
|
|
settingsOptions,
|
|
}) => {
|
|
const settings = deps.useSettingsState(settingsOptions);
|
|
const appLock = deps.useAppLockState(settings.appLockSettings);
|
|
const {
|
|
notifyRendererReady: notifyAppLockRendererReady,
|
|
onAppLockReopen,
|
|
} = deps.useAppLockBridge();
|
|
const hasRenderedChildrenRef = useRef(false);
|
|
const [reopenSignal, setReopenSignal] = useState(0);
|
|
const renderChildren = shouldRenderAppLockGateChildren({
|
|
initialized: appLock.initialized,
|
|
locked: appLock.locked,
|
|
lockReason: appLock.lockReason,
|
|
hasRenderedChildren: hasRenderedChildrenRef.current,
|
|
forceRenderChildren,
|
|
});
|
|
if (renderChildren) {
|
|
hasRenderedChildrenRef.current = true;
|
|
}
|
|
const shouldNotifyRendererReady = shouldNotifyAppLockGateRendererReady({
|
|
notifyRendererReady,
|
|
renderChildren,
|
|
});
|
|
|
|
useEffect(() => {
|
|
try {
|
|
const splash = document.getElementById('splash');
|
|
if (splash) {
|
|
splash.classList.add('fade-out');
|
|
setTimeout(() => splash.remove(), 200);
|
|
}
|
|
if (shouldNotifyRendererReady) {
|
|
performance.mark('netcatty:renderer:ready');
|
|
notifyAppLockRendererReady();
|
|
}
|
|
} catch {
|
|
// ignore
|
|
}
|
|
}, [notifyAppLockRendererReady, shouldNotifyRendererReady]);
|
|
|
|
useEffect(() => {
|
|
const unsubscribe = onAppLockReopen(() => {
|
|
setReopenSignal((current) => current + 1);
|
|
void appLock.resync?.();
|
|
});
|
|
return () => unsubscribe?.();
|
|
}, [appLock, onAppLockReopen]);
|
|
|
|
useEffect(() => {
|
|
const handleVisibilityOrFocus = () => {
|
|
void appLock.resync?.();
|
|
};
|
|
window.addEventListener('focus', handleVisibilityOrFocus);
|
|
document.addEventListener('visibilitychange', handleVisibilityOrFocus);
|
|
return () => {
|
|
window.removeEventListener('focus', handleVisibilityOrFocus);
|
|
document.removeEventListener('visibilitychange', handleVisibilityOrFocus);
|
|
};
|
|
}, [appLock]);
|
|
|
|
// When re-locked after first mount, children stay mounted under the overlay.
|
|
// Mark them inert so pointer/keyboard/AT cannot reach underlying controls
|
|
// (sessions, editors, side panels) while the lock screen is up.
|
|
const lockedBackground = appLock.locked === true;
|
|
|
|
return (
|
|
<I18nProvider locale={settings.uiLanguage}>
|
|
<ToastProvider>
|
|
<TooltipProvider delayDuration={300}>
|
|
{renderChildren ? (
|
|
<div
|
|
// React 19 supports the HTML inert attribute; when true, the
|
|
// subtree is non-interactive and removed from sequential focus.
|
|
inert={lockedBackground ? true : undefined}
|
|
aria-hidden={lockedBackground || undefined}
|
|
className={lockedBackground ? 'h-full pointer-events-none' : 'h-full'}
|
|
data-app-lock-background={lockedBackground ? 'locked' : 'unlocked'}
|
|
>
|
|
{children({ settings, appLock })}
|
|
</div>
|
|
) : null}
|
|
<AppLockOverlay
|
|
locked={appLock.locked}
|
|
reason={appLock.lockReason}
|
|
onUnlock={appLock.unlock}
|
|
systemUnlockStatus={appLock.systemUnlockStatus}
|
|
onSystemUnlock={appLock.unlockWithSystemAuth}
|
|
onResetAppLock={appLock.reset}
|
|
autoPromptSystemUnlock={settings.appLockSettings.systemUnlockAutoPromptEnabled}
|
|
reopenSignal={reopenSignal}
|
|
/>
|
|
</TooltipProvider>
|
|
</ToastProvider>
|
|
</I18nProvider>
|
|
);
|
|
};
|
|
|
|
return AppLockGateImpl;
|
|
}
|
|
|
|
export const AppLockGate = createAppLockGate({
|
|
useSettingsState,
|
|
useAppLockState,
|
|
useAppLockBridge,
|
|
});
|