mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 15:19:16 +00:00
* fix(browser): keep the page live beside overlay side panels The embedded host browser is a native WebContentsView that draws above the renderer, and its occlusion check only yielded to dialogs, menus and poppers. Opening New host / Edit host from the terminal host tree left the page drawn over the overlay host editor panel. Overlay-layout aside panels now carry data-native-view-occluder. Native views cannot be clipped by a parent View on macOS, so the pane shrinks the live page to the rectangle left beside a panel that covers a full-height or full-width edge strip; the page stays interactive while the editor is open. Poppers are checked against that live rectangle, so selects inside the panel no longer freeze the page, and pictures for poppers over the page are offset to where it sits. A panel over the middle of the pane, or one leaving less than 160px, falls back to a picture. * test(browser): provide the pane geometry helper to the first-link harness The first-link acceptance loads useHostBrowserPanel through a VM that strips imports and injects dependencies by name, so it threw "resolveHostBrowserPaneBesidePanels is not defined" once the hook started using the domain helper. Load domain/hostBrowser.ts and pass the helper in.
102 lines
3.7 KiB
TypeScript
102 lines
3.7 KiB
TypeScript
import type { BrowserBookmark } from './browserBookmark';
|
|
|
|
export class HostBrowserIconError extends Error {
|
|
constructor(public readonly reason: 'file-type' | 'file-size' | 'decode') {
|
|
super(reason);
|
|
this.name = 'HostBrowserIconError';
|
|
}
|
|
}
|
|
|
|
export interface HostBrowserTab {
|
|
id: string;
|
|
url: string;
|
|
title: string;
|
|
loading: boolean;
|
|
canGoBack: boolean;
|
|
canGoForward: boolean;
|
|
iconDataUrl: string | null;
|
|
iconGlyph: string | null;
|
|
iconColor: string | null;
|
|
}
|
|
|
|
export interface HostBrowserState {
|
|
hostId: string;
|
|
label: string;
|
|
route: 'connecting' | 'connected' | 'disconnected';
|
|
error: string | null;
|
|
activeTabId: string | null;
|
|
tabs: HostBrowserTab[];
|
|
}
|
|
|
|
export interface HostBrowserDownload {
|
|
id: string;
|
|
hostId: string;
|
|
filename: string;
|
|
url: string;
|
|
savePath: string;
|
|
status: 'waiting' | 'progressing' | 'completed' | 'cancelled' | 'interrupted';
|
|
received: number;
|
|
total: number;
|
|
startedAt: number;
|
|
endedAt: number | null;
|
|
missing: boolean;
|
|
}
|
|
|
|
export type HostBrowserBookmark = BrowserBookmark & {
|
|
siteIconDataUrl?: string | null;
|
|
siteIconGlyph?: string | null;
|
|
siteIconColor?: string | null;
|
|
};
|
|
|
|
export type HostBrowserCommand =
|
|
| { type: 'new-tab'; url?: string }
|
|
| { type: 'navigate'; url: string; tabId?: string }
|
|
| { type: 'activate' | 'close-tab' | 'back' | 'forward' | 'reload' | 'stop' | 'reset-icon'; tabId?: string }
|
|
| { type: 'reorder'; tabId: string; beforeTabId: string }
|
|
| { type: 'set-icon'; tabId: string; dataUrl?: string | null; glyph: string; color: string }
|
|
| { type: 'retry' };
|
|
|
|
export type HostBrowserShortcut = { type: 'focus-address' | 'new-tab' | 'close-tab' | 'reload'; tabId: string };
|
|
export type HostBrowserPanelEvent = { browserId: string } & (
|
|
| { type: 'state'; state: HostBrowserState }
|
|
| { type: 'downloads'; downloads: HostBrowserDownload[]; startedId?: string }
|
|
| { type: 'bookmarks' }
|
|
| { type: 'shortcut'; shortcut: HostBrowserShortcut }
|
|
);
|
|
|
|
export interface HostBrowserPaneRect { x: number; y: number; width: number; height: number }
|
|
|
|
/** Below this extent a page beside an overlay panel is too cramped to keep live. */
|
|
export const HOST_BROWSER_MIN_LIVE_EXTENT = 160;
|
|
|
|
/**
|
|
* Native browser views draw above the renderer and cannot be clipped, so a
|
|
* panel covering a full-height or full-width edge strip of the pane is avoided
|
|
* by shrinking the page to the remaining rectangle. Returns null when a panel
|
|
* covers the middle or leaves too little room; the pane then shows a picture.
|
|
*/
|
|
export function resolveHostBrowserPaneBesidePanels(
|
|
pane: HostBrowserPaneRect,
|
|
panels: readonly HostBrowserPaneRect[],
|
|
): HostBrowserPaneRect | null {
|
|
let left = pane.x;
|
|
let top = pane.y;
|
|
let right = pane.x + pane.width;
|
|
let bottom = pane.y + pane.height;
|
|
for (const panel of panels) {
|
|
const panelRight = panel.x + panel.width;
|
|
const panelBottom = panel.y + panel.height;
|
|
if (panel.x >= right || panelRight <= left || panel.y >= bottom || panelBottom <= top) continue;
|
|
const spansHeight = panel.y <= top && panelBottom >= bottom;
|
|
const spansWidth = panel.x <= left && panelRight >= right;
|
|
if (spansHeight && panel.x > left && panelRight >= right) right = panel.x;
|
|
else if (spansHeight && panel.x <= left && panelRight < right) left = panelRight;
|
|
else if (spansWidth && panel.y > top && panelBottom >= bottom) bottom = panel.y;
|
|
else if (spansWidth && panel.y <= top && panelBottom < bottom) top = panelBottom;
|
|
else return null;
|
|
}
|
|
if (left === pane.x && top === pane.y && right === pane.x + pane.width && bottom === pane.y + pane.height) return pane;
|
|
if (right - left < HOST_BROWSER_MIN_LIVE_EXTENT || bottom - top < HOST_BROWSER_MIN_LIVE_EXTENT) return null;
|
|
return { x: left, y: top, width: right - left, height: bottom - top };
|
|
}
|