Compare commits

...
Author SHA1 Message Date
BarreiroT 4478a3dac4 Fix error logging 2025-11-12 23:58:10 -03:00
BarreiroT 3fdaa1bace Use asExternalURI and add logs 2025-11-12 19:22:15 -03:00
BarreiroT a051c88110 Open URLs using the VSCode API instead of open 2025-11-12 03:23:12 -03:00
4 changed files with 59 additions and 3 deletions
+33
View File
@@ -2,8 +2,11 @@ package hostbridge
import (
"context"
"errors"
"log"
"os"
"os/exec"
"runtime"
"github.com/atotto/clipboard"
"github.com/cline/cli/pkg/cli/global"
@@ -164,3 +167,33 @@ func (s *EnvService) SubscribeToTelemetrySettings(req *cline.EmptyRequest, strea
return nil
}
func openBrowser(url string) error {
var cmd *exec.Cmd
switch runtime.GOOS {
case "windows":
cmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", url)
case "darwin":
cmd = exec.Command("open", url)
case "linux":
cmd = exec.Command("xdg-open", url)
default:
return errors.New("unsupported platform")
}
return cmd.Start()
}
func (s *EnvService) OpenExternal(ctx context.Context, req *cline.StringRequest) (*cline.Empty, error) {
if s.verbose {
log.Printf("OpenExternal called with URL: %s", req.GetValue())
}
err := openBrowser(req.GetValue())
if err != nil {
log.Printf("Failed to open browser: %v\n", err)
}
return &cline.Empty{}, nil
}
+3
View File
@@ -33,6 +33,9 @@ service EnvService {
// Initiates a graceful shutdown of the host bridge service.
rpc shutdown(cline.EmptyRequest) returns (cline.Empty);
// Opens an external URL in the user's browser.
rpc openExternal(cline.StringRequest) returns (cline.Empty);
}
message GetHostVersionResponse {
+15
View File
@@ -0,0 +1,15 @@
import { Empty, StringRequest } from "@shared/proto/cline/common"
import * as vscode from "vscode"
export async function openExternal(request: StringRequest): Promise<Empty> {
try {
const authUrl = await vscode.env.asExternalUri(vscode.Uri.parse(request.value))
console.error("Opening external URL via VSCode:", authUrl.toString())
await vscode.env.openExternal(vscode.Uri.parse(authUrl.toString()))
} catch (err) {
console.error("Failed to open external URL via VSCode:", err)
throw err
}
return Empty.create({})
}
+8 -3
View File
@@ -1,5 +1,4 @@
import { EmptyRequest, StringRequest } from "@shared/proto/cline/common"
import open from "open"
import { HostProvider } from "@/hosts/host-provider"
/**
@@ -39,6 +38,12 @@ export async function readTextFromClipboard(): Promise<string> {
* @throws Error if the operation fails
*/
export async function openExternal(url: string): Promise<void> {
console.log("Opening browser:", url)
await open(url)
try {
console.log("Opening browser:", url)
await HostProvider.env.openExternal(StringRequest.create({ value: url }))
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
throw new Error(`Failed to write to clipboard: ${errorMessage}`)
}
}