-
Notifications
You must be signed in to change notification settings - Fork 966
feat(desktop): port browser pane to v2 workspaces with global persistence #3346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1842175
feat(desktop): port browser pane to v2 workspaces with global persist…
saddlepaddle 7ecb775
refactor(desktop): co-locate browser pane integration, remove keep-alive
saddlepaddle 504526c
refactor(desktop): simplify browser pane integration, add onRemoved hook
saddlepaddle 84a8f63
refactor(desktop): use native webview back/forward + tighten sanitizeUrl
saddlepaddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
...rd/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/BrowserPane.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import type { RendererContext, Tab } from "@superset/panes"; | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; | ||
| import { GlobeIcon } from "lucide-react"; | ||
| import { useCallback, useSyncExternalStore } from "react"; | ||
| import { TbDeviceDesktop } from "react-icons/tb"; | ||
| import { electronTrpcClient } from "renderer/lib/trpc-client"; | ||
| import type { BrowserPaneData, PaneViewerData } from "../../../../types"; | ||
|
|
||
| import { browserRuntimeRegistry } from "./browserRuntimeRegistry"; | ||
| import { BrowserErrorOverlay } from "./components/BrowserErrorOverlay"; | ||
| import { BrowserOverflowMenu } from "./components/BrowserOverflowMenu"; | ||
| import { BrowserToolbar } from "./components/BrowserToolbar"; | ||
| import { usePersistentWebview } from "./hooks/usePersistentWebview"; | ||
|
|
||
| function getSingleBrowserPane( | ||
| tab: Tab<PaneViewerData>, | ||
| ): { id: string; data: BrowserPaneData } | null { | ||
| const paneIds = Object.keys(tab.panes); | ||
| if (paneIds.length !== 1) return null; | ||
| const pane = tab.panes[paneIds[0]]; | ||
| if (pane.kind !== "browser") return null; | ||
| return { id: pane.id, data: pane.data as BrowserPaneData }; | ||
| } | ||
|
|
||
| export function getBrowserTabTitle( | ||
| tab: Tab<PaneViewerData>, | ||
| ): string | undefined { | ||
| const browser = getSingleBrowserPane(tab); | ||
| if (!browser) return undefined; | ||
| if (browser.data.pageTitle) return browser.data.pageTitle; | ||
| if (browser.data.url && browser.data.url !== "about:blank") { | ||
| try { | ||
| return new URL(browser.data.url).hostname; | ||
| } catch {} | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| export function renderBrowserTabIcon(tab: Tab<PaneViewerData>) { | ||
| const browser = getSingleBrowserPane(tab); | ||
| if (!browser?.data.faviconUrl) return null; | ||
| return ( | ||
| <img src={browser.data.faviconUrl} alt="" className="size-3.5 shrink-0" /> | ||
| ); | ||
| } | ||
|
|
||
| interface BrowserPaneProps { | ||
| ctx: RendererContext<PaneViewerData>; | ||
| } | ||
|
|
||
| function useBrowserState(paneId: string) { | ||
| return useSyncExternalStore( | ||
| useCallback( | ||
| (cb) => browserRuntimeRegistry.onStateChange(paneId, cb), | ||
| [paneId], | ||
| ), | ||
| useCallback(() => browserRuntimeRegistry.getState(paneId), [paneId]), | ||
| ); | ||
| } | ||
|
|
||
| export function BrowserPane({ ctx }: BrowserPaneProps) { | ||
| const paneId = ctx.pane.id; | ||
| const state = useBrowserState(paneId); | ||
| const { placeholderRef, reload } = usePersistentWebview({ paneId, ctx }); | ||
|
|
||
| const isBlankPage = !state.currentUrl || state.currentUrl === "about:blank"; | ||
|
|
||
| return ( | ||
| <div className="relative flex flex-1 h-full"> | ||
| <div ref={placeholderRef} className="w-full h-full" style={{ flex: 1 }} /> | ||
| {state.error && !state.isLoading && ( | ||
| <BrowserErrorOverlay error={state.error} onRetry={reload} /> | ||
| )} | ||
| {isBlankPage && !state.isLoading && !state.error && ( | ||
| <div className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-background pointer-events-none"> | ||
| <GlobeIcon className="size-10 text-muted-foreground/30" /> | ||
| <div className="text-center"> | ||
| <p className="text-sm font-medium text-muted-foreground/50"> | ||
| Browser | ||
| </p> | ||
| <p className="mt-1 text-xs text-muted-foreground/30"> | ||
| Enter a URL above, or instruct an agent to navigate | ||
| <br /> | ||
| and use the browser | ||
| </p> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| interface BrowserPaneToolbarProps { | ||
| ctx: RendererContext<PaneViewerData>; | ||
| } | ||
|
|
||
| export function BrowserPaneToolbar({ ctx }: BrowserPaneToolbarProps) { | ||
| const paneId = ctx.pane.id; | ||
| const state = useBrowserState(paneId); | ||
|
|
||
| const handleOpenDevTools = useCallback(() => { | ||
| electronTrpcClient.browser.openDevTools.mutate({ paneId }).catch(() => {}); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Do not silently swallow (Based on your team's feedback about handling async errors and avoiding empty catch blocks.) Prompt for AI agents |
||
| }, [paneId]); | ||
|
|
||
| const handleGoBack = useCallback(() => { | ||
| browserRuntimeRegistry.goBack(paneId); | ||
| }, [paneId]); | ||
|
|
||
| const handleGoForward = useCallback(() => { | ||
| browserRuntimeRegistry.goForward(paneId); | ||
| }, [paneId]); | ||
|
|
||
| const handleReload = useCallback(() => { | ||
| browserRuntimeRegistry.reload(paneId); | ||
| }, [paneId]); | ||
|
|
||
| const handleNavigate = useCallback( | ||
| (url: string) => { | ||
| browserRuntimeRegistry.navigate(paneId, url); | ||
| }, | ||
| [paneId], | ||
| ); | ||
|
|
||
| const isBlankPage = !state.currentUrl || state.currentUrl === "about:blank"; | ||
| const PaneHeaderActions = ctx.components.PaneHeaderActions; | ||
|
|
||
| return ( | ||
| <div className="flex h-full w-full items-center justify-between min-w-0"> | ||
| <BrowserToolbar | ||
| currentUrl={state.currentUrl} | ||
| pageTitle={state.pageTitle} | ||
| isLoading={state.isLoading} | ||
| canGoBack={state.canGoBack} | ||
| canGoForward={state.canGoForward} | ||
| onGoBack={handleGoBack} | ||
| onGoForward={handleGoForward} | ||
| onReload={handleReload} | ||
| onNavigate={handleNavigate} | ||
| /> | ||
| <div className="flex items-center shrink-0 pr-1"> | ||
| <div className="mx-1.5 h-3.5 w-px bg-muted-foreground/60" /> | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <button | ||
| type="button" | ||
| onClick={handleOpenDevTools} | ||
| className="rounded p-0.5 text-muted-foreground/60 transition-colors hover:text-muted-foreground" | ||
| > | ||
| <TbDeviceDesktop className="size-3.5" /> | ||
| </button> | ||
| </TooltipTrigger> | ||
| <TooltipContent side="bottom" showArrow={false}> | ||
| Open DevTools | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| <BrowserOverflowMenu | ||
| paneId={paneId} | ||
| currentUrl={state.currentUrl} | ||
| hasPage={!isBlankPage} | ||
| /> | ||
| <div className="mx-1 h-3.5 w-px bg-muted-foreground/60" /> | ||
| <PaneHeaderActions /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Active tab visibility is no longer synchronized for browser panes. Since the webviews are floated at the document root and only hidden on detach, removing the tab-activity effect leaves inactive tab webviews visible, so they can paint over the active tab after a tab switch.
Prompt for AI agents