host bridge migration - openExternal (#4502)

This commit is contained in:
canvrno authored and GitHub committed 2025-07-08 10:47:12 -07:00
1 parent bc468707a6
commit ff4bab22fb
9 files changed
+46 -15

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
host bridge migration - openExternal
+3
View File
@@ -13,4 +13,7 @@ service EnvService {
// Reads text from the system clipboard.
rpc clipboardReadText(cline.EmptyRequest) returns (cline.String);
// Opens a URL in the user's default browser or application.
rpc openExternal(cline.StringRequest) returns (cline.Empty);
}
@@ -3,6 +3,7 @@ import crypto from "crypto"
import { Controller } from "../index"
import { storeSecret } from "../../storage/state"
import { EmptyRequest, String } from "../../../shared/proto/common"
import { openExternal } from "@utils/env"
/**
* Handles the user clicking the login link in the UI.
@@ -26,7 +27,7 @@ export async function accountLoginClicked(controller: Controller, _: EmptyReques
const authUrl = vscode.Uri.parse(
`https://app.cline.bot/auth?state=${encodeURIComponent(nonce)}&callback_url=${encodeURIComponent(`${uriScheme || "vscode"}://saoudrizwan.claude-dev/auth`)}`,
)
await vscode.env.openExternal(authUrl)
await openExternal(authUrl.toString())
return String.create({
value: authUrl.toString(),
})
+2 -2
View File
@@ -1,6 +1,6 @@
import * as vscode from "vscode"
import { Controller } from ".."
import { Empty, StringRequest } from "../../../shared/proto/common"
import { openExternal } from "@utils/env"
/**
* Opens a URL in the user's default browser
@@ -11,7 +11,7 @@ import { Empty, StringRequest } from "../../../shared/proto/common"
export async function openInBrowser(controller: Controller, request: StringRequest): Promise<Empty> {
try {
if (request.value) {
await vscode.env.openExternal(vscode.Uri.parse(request.value))
await openExternal(request.value)
}
return Empty.create()
} catch (error) {
+2 -1
View File
@@ -12,6 +12,7 @@ import { getCommitInfo } from "@utils/git"
import { getWorkingState } from "@utils/git"
import { FileContextTracker } from "../context/context-tracking/FileContextTracker"
import { getCwd } from "@/utils/path"
import { openExternal } from "@utils/env"
export async function openMention(mention?: string): Promise<void> {
if (!mention) {
@@ -36,7 +37,7 @@ export async function openMention(mention?: string): Promise<void> {
} else if (mention === "terminal") {
vscode.commands.executeCommand("workbench.action.terminal.focus")
} else if (mention.startsWith("http")) {
vscode.env.openExternal(vscode.Uri.parse(mention))
await openExternal(mention)
}
}
+8
View File
@@ -0,0 +1,8 @@
import { Empty, StringRequest } from "@/shared/proto/common"
import * as vscode from "vscode"
export async function openExternal(request: StringRequest): Promise<Empty> {
console.log("openExternal called with request:", request)
await vscode.env.openExternal(vscode.Uri.parse(request.value))
return Empty.create()
}
+3 -4
View File
@@ -1,4 +1,5 @@
import * as vscode from "vscode"
import { openExternal } from "@utils/env"
/**
* Detects potential AI-generated code omissions in the given file content.
@@ -47,10 +48,8 @@ export function showOmissionWarning(originalFileContent: string, newFileContent:
)
.then((selection) => {
if (selection === "Follow this guide to fix the issue") {
vscode.env.openExternal(
vscode.Uri.parse(
"https://github.com/cline/cline/wiki/Troubleshooting-%E2%80%90-Cline-Deleting-Code-with-%22Rest-of-Code-Here%22-Comments",
),
openExternal(
"https://github.com/cline/cline/wiki/Troubleshooting-%E2%80%90-Cline-Deleting-Code-with-%22Rest-of-Code-Here%22-Comments",
)
}
})
+15
View File
@@ -30,3 +30,18 @@ export async function readTextFromClipboard(): Promise<string> {
throw new Error(`Failed to read from clipboard: ${errorMessage}`)
}
}
/**
* Opens an external URL in the default browser
* @param url The URL to open
* @returns Promise that resolves when the operation is complete
* @throws Error if the operation fails
*/
export async function openExternal(url: string): Promise<void> {
try {
await getHostBridgeProvider().envClient.openExternal(StringRequest.create({ value: url }))
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
throw new Error(`Failed to open external URL: ${errorMessage}`)
}
}
+6 -7
View File
@@ -17,7 +17,7 @@ import * as vscode from "vscode"
import * as cp from "child_process"
import * as os from "os"
import * as util from "util"
import { writeTextToClipboard } from "@/utils/env"
import { writeTextToClipboard, openExternal } from "@/utils/env"
/**
* Creates a properly encoded GitHub issue URL.
@@ -141,16 +141,15 @@ export async function openUrlInBrowser(url: string): Promise<void> {
} catch (error) {
console.error(`OS commands failed: ${error}`)
// First fallback: Try VS Code's openExternal
// First fallback: Try openExternal utility
// Note: This will likely have encoding issues per https://github.com/microsoft/vscode/issues/85930
// but we include it as a fallback in case OS commands completely fail
try {
// The 'true' parameter might help preserve some encodings, but this is not guaranteed
await vscode.env.openExternal(vscode.Uri.parse(url, true))
console.log("Opened URL with vscode.env.openExternal (note: URL encoding may be affected)")
await openExternal(url)
console.log("Opened URL with openExternal utility (note: URL encoding may be affected)")
return
} catch (vscodeError) {
console.error(`Error with vscode.env.openExternal: ${vscodeError}`)
} catch (openExternalError) {
console.error(`Error with openExternal utility: ${openExternalError}`)
// Last fallback: Show a message with instructions
vscode.window