Add browser toolbar to auth windows

This commit is contained in:
2026-05-21 23:57:20 +08:00
parent 49b1ccc961
commit 53ba8ff4cf
2 changed files with 201 additions and 48 deletions
@@ -521,7 +521,7 @@ function workbenchErrorDataURL(title: string, targetURL: string, message: string
<body>
<main>
<h1>${escapeHtml(title)}加载失败</h1>
<p>远程工作台暂时无法打开。可以使用窗口左上方的刷新按钮重试。</p>
<p>远程页面暂时无法打开。可以使用窗口左上方的刷新按钮重试。</p>
<code>${escapeHtml(host || targetURL)}
${escapeHtml(message)}</code>
@@ -563,6 +563,19 @@ function getRecordForSender(sender: WebContents): WorkbenchWindowRecord | null {
return record
}
function getRecordForWindow(window: BrowserWindow): WorkbenchWindowRecord | null {
const record = workbenchWindows.get(window.webContents.id)
if (
!record ||
record.window !== window ||
record.window.isDestroyed() ||
record.view.webContents.isDestroyed()
) {
return null
}
return record
}
function defaultNavigationState(): WorkbenchNavigationState {
return {
canGoBack: false,
@@ -740,6 +753,38 @@ async function navigateWorkbenchRemote(
}
}
export function getWorkbenchWindowWebContents(window: BrowserWindow): WebContents | null {
return getRecordForWindow(window)?.view.webContents ?? null
}
export function isWorkbenchWindowReadyForDetection(window: BrowserWindow): boolean {
const record = getRecordForWindow(window)
if (!record) {
return false
}
const currentURL = record.view.webContents.getURL()
return (
isRemoteHTTPURL(currentURL) &&
!isLocalWorkbenchPage(currentURL) &&
!record.loading &&
!record.view.webContents.isLoading()
)
}
export async function loadWorkbenchWindowURL(
window: BrowserWindow,
targetURL: string,
): Promise<boolean> {
const record = getRecordForWindow(window)
if (!record) {
return false
}
await navigateWorkbenchRemote(record, targetURL)
return true
}
export async function openWorkbenchWindow(options: WorkbenchWindowOptions): Promise<BrowserWindow> {
registerWorkbenchNavigationHandlers()