Skip to content

Commit 3f513bb

Browse files
committed
[supervisor] active client notifications
1 parent 4d053ed commit 3f513bb

File tree

13 files changed

+573
-210
lines changed

13 files changed

+573
-210
lines changed

components/gitpod-cli/cmd/docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var docsCmd = &cobra.Command{
1515
Use: "docs",
1616
Short: "Open Gitpod Documentation in default browser",
1717
RunE: func(cmd *cobra.Command, args []string) error {
18-
return openPreview("GP_EXTERNAL_BROWSER", DocsUrl)
18+
return openPreview(cmd.Context(), DocsUrl, true)
1919
},
2020
}
2121

components/gitpod-cli/cmd/open.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ package cmd
77
import (
88
"os"
99
"os/exec"
10-
"time"
10+
"path/filepath"
1111

1212
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor"
13-
14-
"context"
13+
"github.com/gitpod-io/gitpod/supervisor/api"
1514

1615
"github.com/google/shlex"
1716
"github.com/spf13/cobra"
@@ -24,25 +23,42 @@ var openCmd = &cobra.Command{
2423
Short: "Opens a file in Gitpod",
2524
Args: cobra.MinimumNArgs(1),
2625
RunE: func(cmd *cobra.Command, args []string) error {
27-
// TODO(ak) use NotificationService.NotifyActive supervisor API instead
28-
29-
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
30-
defer cancel()
26+
ctx := cmd.Context()
3127

3228
client, err := supervisor.New(ctx)
3329
if err != nil {
3430
return err
3531
}
3632
defer client.Close()
37-
3833
client.WaitForIDEReady(ctx)
3934

4035
wait, _ := cmd.Flags().GetBool("wait")
4136

4237
pcmd := os.Getenv("GP_OPEN_EDITOR")
4338
if pcmd == "" {
44-
return xerrors.Errorf("GP_OPEN_EDITOR is not set")
39+
var paths []string
40+
for _, path := range args {
41+
absPath, err := filepath.Abs(path)
42+
if err == nil {
43+
path = absPath
44+
}
45+
paths = append(paths, path)
46+
}
47+
48+
_, err := client.Notification.NotifyActive(ctx, &api.NotifyActiveRequest{
49+
ActionData: &api.NotifyActiveRequest_Open{
50+
Open: &api.NotifyActiveRequest_OpenData{
51+
Paths: paths,
52+
Await: wait,
53+
},
54+
},
55+
})
56+
if err != nil && ctx.Err() == nil {
57+
return xerrors.Errorf("failed to open: %w", err)
58+
}
59+
return nil
4560
}
61+
// TODO: backward compatibilty, remove when all IDEs are updated
4662
pargs, err := shlex.Split(pcmd)
4763
if err != nil {
4864
return xerrors.Errorf("cannot parse GP_OPEN_EDITOR: %w", err)

components/gitpod-cli/cmd/preview.go

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"regexp"
1212
"strconv"
1313
"strings"
14-
"time"
1514

1615
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor"
16+
"github.com/gitpod-io/gitpod/supervisor/api"
1717
"github.com/google/shlex"
1818
"github.com/spf13/cobra"
1919
"golang.org/x/xerrors"
@@ -31,34 +31,39 @@ var previewCmd = &cobra.Command{
3131
Short: "Opens a URL in the IDE's preview",
3232
Args: cobra.ExactArgs(1),
3333
RunE: func(cmd *cobra.Command, args []string) error {
34-
// TODO(ak) use NotificationService.NotifyActive supervisor API instead
35-
36-
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
37-
defer cancel()
38-
client, err := supervisor.New(ctx)
39-
if err != nil {
40-
return err
41-
}
42-
defer client.Close()
43-
44-
client.WaitForIDEReady(ctx)
45-
46-
gpBrowserEnvVar := "GP_PREVIEW_BROWSER"
47-
48-
url := replaceLocalhostInURL(args[0])
49-
if previewCmdOpts.External {
50-
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
51-
url = "https://" + url
52-
}
53-
gpBrowserEnvVar = "GP_EXTERNAL_BROWSER"
54-
}
55-
56-
return openPreview(gpBrowserEnvVar, url)
34+
return openPreview(cmd.Context(), args[0], previewCmdOpts.External)
5735
},
5836
}
5937

60-
func openPreview(gpBrowserEnvVar string, url string) error {
38+
func openPreview(ctx context.Context, url string, external bool) error {
39+
client, err := supervisor.New(ctx)
40+
if err != nil {
41+
return err
42+
}
43+
defer client.Close()
44+
client.WaitForIDEReady(ctx)
45+
46+
url = replaceLocalhostInURL(url)
47+
gpBrowserEnvVar := "GP_PREVIEW_BROWSER"
48+
if external {
49+
gpBrowserEnvVar = "GP_EXTERNAL_BROWSER"
50+
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
51+
url = "https://" + url
52+
}
53+
}
6154
pcmd := os.Getenv(gpBrowserEnvVar)
55+
if pcmd == "" {
56+
_, err := client.Notification.NotifyActive(ctx, &api.NotifyActiveRequest{
57+
ActionData: &api.NotifyActiveRequest_Preview{
58+
Preview: &api.NotifyActiveRequest_PreviewData{
59+
Url: url,
60+
External: external,
61+
},
62+
},
63+
})
64+
return err
65+
}
66+
// TODO: backward compatibilty, remove when all IDEs are updated
6267
if pcmd == "" {
6368
return xerrors.Errorf("%s is not set", gpBrowserEnvVar)
6469
}

components/gitpod-cli/hot-swap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Copyright (c) 2023 Gitpod GmbH. All rights reserved.
33
# Licensed under the GNU Affero General Public License (AGPL).
44
# See License.AGPL.txt in the project root for license information.
55

components/ide/code/leeway.Dockerfile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,9 @@ FROM scratch
9999
COPY --from=code_builder --chown=33333:33333 /vscode-web/ /ide/
100100
COPY --from=code_builder --chown=33333:33333 /vscode-reh-linux-x64/ /ide/
101101

102+
# TODO(ak) get rid of it as well
102103
ENV GITPOD_ENV_APPEND_PATH=/ide/bin/remote-cli:
103104

104-
# editor config
105-
ENV GITPOD_ENV_SET_EDITOR=/ide/bin/remote-cli/gitpod-code
106-
ENV GITPOD_ENV_SET_VISUAL="$GITPOD_ENV_SET_EDITOR"
107-
ENV GITPOD_ENV_SET_GP_OPEN_EDITOR="$GITPOD_ENV_SET_EDITOR"
108-
ENV GITPOD_ENV_SET_GIT_EDITOR="$GITPOD_ENV_SET_EDITOR --wait"
109-
ENV GITPOD_ENV_SET_GP_PREVIEW_BROWSER="/ide/bin/remote-cli/gitpod-code --preview"
110-
ENV GITPOD_ENV_SET_GP_EXTERNAL_BROWSER="/ide/bin/remote-cli/gitpod-code --openExternal"
111-
112105
ARG CODE_VERSION
113106
ARG CODE_COMMIT
114107
LABEL "io.gitpod.ide.version"=$CODE_VERSION

0 commit comments

Comments
 (0)