Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ require (
github.com/opencontainers/runtime-spec v1.2.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
github.com/pires/go-proxyproto v0.8.1 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus-community/pro-bing v0.4.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pires/go-proxyproto v0.8.1 h1:9KEixbdJfhrbtjpz/ZwCdWDD2Xem0NZ38qMYaASJgp0=
github.com/pires/go-proxyproto v0.8.1/go.mod h1:ZKAAyp3cgy5Y5Mo4n9AlScrkCZwUy0g3Jf+slqQVcuU=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.10 h1:+5FbKNTe5Z9aspU88DPIKJ9z2KZoaGCu6Sr6kKR/5mU=
Expand Down
42 changes: 37 additions & 5 deletions pkg/ide/jetbrains/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import (
"net/http"
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"

"github.com/loft-sh/log"
"github.com/pkg/browser"
"github.com/skevetter/devpod/pkg/command"
"github.com/skevetter/devpod/pkg/config"
copy2 "github.com/skevetter/devpod/pkg/copy"
"github.com/skevetter/devpod/pkg/extract"
devpodhttp "github.com/skevetter/devpod/pkg/http"
"github.com/skevetter/devpod/pkg/ide"
"github.com/skevetter/devpod/pkg/util"
"github.com/skratchdot/open-golang/open"
)

const (
Expand Down Expand Up @@ -74,11 +75,42 @@ type GenericJetBrainsServer struct {
}

func (o *GenericJetBrainsServer) OpenGateway(workspaceFolder, workspaceID string) error {
o.log.Infof("Starting %s through JetBrains Gateway...", o.options.DisplayName)
err := open.Run(`jetbrains-gateway://connect#idePath=` + url.QueryEscape(o.getDirectory(path.Join("/", "home", o.userName))) + `&projectPath=` + url.QueryEscape(workspaceFolder) + `&host=` + workspaceID + `.devpod&port=22&user=` + url.QueryEscape(o.userName) + `&type=ssh&deploy=false`)
o.log.Infof("starting %s through JetBrains Gateway", o.options.DisplayName)

// Build JetBrains Gateway URL
// Reference: https://www.jetbrains.com/help/idea/remote-development-a.html#use_idea
// Format: jetbrains-gateway://connect#idePath=<path>&projectPath=<path>&host=<host>&port=<port>&user=<user>&type=ssh&deploy=false
params := url.Values{}
params.Set("idePath", o.getDirectory(path.Join("/", "home", o.userName)))
params.Set("projectPath", workspaceFolder)
params.Set("host", workspaceID+".devpod")
params.Set("port", "22") // Standard SSH port - TODO: make configurable
params.Set("user", o.userName)
params.Set("type", "ssh")
params.Set("deploy", "false") // Do not auto-deploy IDE backend

gatewayURL := "jetbrains-gateway://connect#" + params.Encode()
o.log.Infof("opening gateway URL %s", gatewayURL)

err := browser.OpenURL(gatewayURL)
if err != nil {
o.log.Debugf("Error opening jetbrains-gateway: %v", err)
o.log.Errorf("Seems like you don't have JetBrains Gateway installed on your computer. Please install JetBrains Gateway via https://www.jetbrains.com/remote-development/gateway/")
o.log.Errorf("error opening jetbrains-gateway with browser %v", err)

if runtime.GOOS == "linux" {
o.log.Debugf("falling back to xdg-open on Linux")
out, execErr := exec.Command("xdg-open", gatewayURL).CombinedOutput()
if execErr != nil {
o.log.Errorf("error opening jetbrains-gateway with xdg-open %v", execErr)
o.log.Errorf("xdg-open output %s", string(out))
err = execErr
} else {
err = nil // xdg-open succeeded
}
}
}

if err != nil {
o.log.Errorf("Failed to open JetBrains Gateway. Ensure JetBrains Gateway is installed. Download from https://www.jetbrains.com/remote-development/gateway/")
return err
}
return nil
Expand Down
Loading