[PROTOBUS] Move openInBrowser to protobus (#3691)

* openInBrowser_protobus_migration
This commit is contained in:
canvrno 2025-05-26 11:20:37 -07:00 committed by GitHub
parent 10239f0616
commit ffeee7e48d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 60 additions and 28 deletions

View File

@ -0,0 +1,5 @@
---
"claude-dev": patch
---
openInBrowser protobus migration

View File

@ -9,6 +9,7 @@ import "common.proto";
service WebService {
rpc checkIsImageUrl(StringRequest) returns (IsImageUrl);
rpc fetchOpenGraphData(StringRequest) returns (OpenGraphData);
rpc openInBrowser(StringRequest) returns (Empty);
}
message IsImageUrl {

View File

@ -303,11 +303,6 @@ export class Controller {
text: message.text,
})
break
case "openInBrowser":
if (message.url) {
vscode.env.openExternal(vscode.Uri.parse(message.url))
}
break
case "fetchUserCreditsData": {
await this.fetchUserCreditsData()
break

View File

@ -0,0 +1,21 @@
import * as vscode from "vscode"
import { Controller } from ".."
import { Empty, StringRequest } from "../../../shared/proto/common"
/**
* Opens a URL in the user's default browser
* @param controller The controller instance
* @param request The URL to open
* @returns Empty response since the client doesn't need a return value
*/
export async function openInBrowser(controller: Controller, request: StringRequest): Promise<Empty> {
try {
if (request.value) {
await vscode.env.openExternal(vscode.Uri.parse(request.value))
}
return Empty.create()
} catch (error) {
console.error("Error opening URL in browser:", error)
return Empty.create()
}
}

View File

@ -13,7 +13,6 @@ export interface WebviewMessage {
| "newTask"
| "condense"
| "reportBug"
| "openInBrowser"
| "showChatView"
| "requestVsCodeLmModels"
| "authStateChanged"
@ -54,8 +53,6 @@ export interface WebviewMessage {
// For auth
user?: UserInfo | null
customToken?: string
// For openInBrowser
url?: string
planActSeparateModelsSetting?: boolean
enableCheckpointsSetting?: boolean
mcpMarketplaceEnabled?: boolean

View File

@ -1,5 +1,6 @@
import React from "react"
import { vscode } from "@/utils/vscode"
import { WebServiceClient } from "@/services/grpc-client"
import DOMPurify from "dompurify"
import { getSafeHostname, formatUrlForOpening, checkIfImageUrl } from "./utils/mcpRichUtil"
import ChatErrorBoundary from "@/components/chat/ChatErrorBoundary"
@ -232,11 +233,14 @@ class ImagePreview extends React.Component<
borderRadius: "4px",
color: "var(--vscode-errorForeground)",
}}
onClick={() => {
vscode.postMessage({
type: "openInBrowser",
url: DOMPurify.sanitize(url),
})
onClick={async () => {
try {
await WebServiceClient.openInBrowser({
value: DOMPurify.sanitize(url),
})
} catch (err) {
console.error("Error opening URL in browser:", err)
}
}}>
<div style={{ fontWeight: "bold" }}>Failed to load image</div>
<div style={{ fontSize: "12px", marginTop: "4px" }}>{getSafeHostname(url)}</div>
@ -256,11 +260,14 @@ class ImagePreview extends React.Component<
maxWidth: "100%",
cursor: "pointer",
}}
onClick={() => {
vscode.postMessage({
type: "openInBrowser",
url: DOMPurify.sanitize(formatUrlForOpening(url)),
})
onClick={async () => {
try {
await WebServiceClient.openInBrowser({
value: DOMPurify.sanitize(formatUrlForOpening(url)),
})
} catch (err) {
console.error("Error opening URL in browser:", err)
}
}}>
{/\.svg(\?.*)?$/i.test(url) ? (
// Special handling for SVG images

View File

@ -238,11 +238,14 @@ class LinkPreview extends React.Component<LinkPreviewProps, LinkPreviewState> {
maxWidth: "512px",
overflow: "auto",
}}
onClick={() => {
vscode.postMessage({
type: "openInBrowser",
url: DOMPurify.sanitize(url),
})
onClick={async () => {
try {
await WebServiceClient.openInBrowser({
value: DOMPurify.sanitize(url),
})
} catch (err) {
console.error("Error opening URL in browser:", err)
}
}}>
<div style={{ fontWeight: "bold" }}>{errorDisplay}</div>
<div style={{ fontSize: "12px", marginTop: "4px" }}>{getSafeHostname(url)}</div>
@ -275,11 +278,14 @@ class LinkPreview extends React.Component<LinkPreviewProps, LinkPreviewState> {
height: "128px",
maxWidth: "512px",
}}
onClick={() => {
vscode.postMessage({
type: "openInBrowser",
url: DOMPurify.sanitize(url),
})
onClick={async () => {
try {
await WebServiceClient.openInBrowser({
value: DOMPurify.sanitize(url),
})
} catch (err) {
console.error("Error opening URL in browser:", err)
}
}}>
{data.image && (
<div className="link-preview-image" style={{ width: "128px", height: "128px", flexShrink: 0 }}>