mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-06 00:14:54 +00:00
- Refresh icon: use single-arrow RotateCw instead of two-arrow RefreshCw - URL bar selects all text on focus - Cmd+R now reloads the active browser pane (tracked via IPC) when the URL bar has focus, instead of reloading the Electron window - Forward Paseo shortcut keys (b, e, w, t, k, /, \, comma, digits, enter, arrows) from the embedded webview to the main window so sidebar/tab/etc. shortcuts still fire when focus is inside the loaded page
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { webContents as allWebContents, type WebContents } from "electron";
|
|
|
|
const browserIdsByWebContentsId = new Map<number, string>();
|
|
let activeBrowserPaneId: string | null = null;
|
|
|
|
export function registerPaseoBrowserWebContents(contents: WebContents, browserId: string): void {
|
|
browserIdsByWebContentsId.set(contents.id, browserId);
|
|
contents.once("destroyed", () => {
|
|
browserIdsByWebContentsId.delete(contents.id);
|
|
if (activeBrowserPaneId === browserId) {
|
|
activeBrowserPaneId = null;
|
|
}
|
|
});
|
|
}
|
|
|
|
export function getPaseoBrowserIdForWebContents(contents: WebContents | null): string | null {
|
|
if (!contents || contents.isDestroyed()) {
|
|
return null;
|
|
}
|
|
return browserIdsByWebContentsId.get(contents.id) ?? null;
|
|
}
|
|
|
|
export function setActivePaseoBrowserPaneId(browserId: string | null): void {
|
|
activeBrowserPaneId = browserId;
|
|
}
|
|
|
|
export function getActivePaseoBrowserWebContents(): WebContents | null {
|
|
if (!activeBrowserPaneId) {
|
|
return null;
|
|
}
|
|
for (const [contentsId, browserId] of browserIdsByWebContentsId) {
|
|
if (browserId !== activeBrowserPaneId) continue;
|
|
const contents = allWebContents.fromId(contentsId);
|
|
if (contents && !contents.isDestroyed()) {
|
|
return contents;
|
|
}
|
|
}
|
|
return null;
|
|
}
|