Skip to content

Commit 975aadb

Browse files
committed
WIP
1 parent 29988ae commit 975aadb

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

cmd/browsers.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type BrowserComputerService interface {
8686
MoveMouse(ctx context.Context, id string, body kernel.BrowserComputerMoveMouseParams, opts ...option.RequestOption) (err error)
8787
PressKey(ctx context.Context, id string, body kernel.BrowserComputerPressKeyParams, opts ...option.RequestOption) (err error)
8888
Scroll(ctx context.Context, id string, body kernel.BrowserComputerScrollParams, opts ...option.RequestOption) (err error)
89+
SetCursorVisibility(ctx context.Context, id string, body kernel.BrowserComputerSetCursorVisibilityParams, opts ...option.RequestOption) (res *kernel.BrowserComputerSetCursorVisibilityResponse, err error)
8990
TypeText(ctx context.Context, id string, body kernel.BrowserComputerTypeTextParams, opts ...option.RequestOption) (err error)
9091
}
9192

@@ -567,6 +568,11 @@ type BrowsersComputerDragMouseInput struct {
567568
HoldKeys []string
568569
}
569570

571+
type BrowsersComputerSetCursorInput struct {
572+
Identifier string
573+
Hidden bool
574+
}
575+
570576
func (b BrowsersCmd) ComputerClickMouse(ctx context.Context, in BrowsersComputerClickMouseInput) error {
571577
if b.computer == nil {
572578
pterm.Error.Println("computer service not available")
@@ -789,6 +795,32 @@ func (b BrowsersCmd) ComputerDragMouse(ctx context.Context, in BrowsersComputerD
789795
return nil
790796
}
791797

798+
func (b BrowsersCmd) ComputerSetCursor(ctx context.Context, in BrowsersComputerSetCursorInput) error {
799+
if b.computer == nil {
800+
pterm.Error.Println("computer service not available")
801+
return nil
802+
}
803+
br, err := b.resolveBrowserByIdentifier(ctx, in.Identifier)
804+
if err != nil {
805+
return util.CleanedUpSdkError{Err: err}
806+
}
807+
if br == nil {
808+
pterm.Error.Printf("Browser '%s' not found\n", in.Identifier)
809+
return nil
810+
}
811+
body := kernel.BrowserComputerSetCursorVisibilityParams{Hidden: in.Hidden}
812+
_, err = b.computer.SetCursorVisibility(ctx, br.SessionID, body)
813+
if err != nil {
814+
return util.CleanedUpSdkError{Err: err}
815+
}
816+
if in.Hidden {
817+
pterm.Success.Println("Cursor hidden")
818+
} else {
819+
pterm.Success.Println("Cursor shown")
820+
}
821+
return nil
822+
}
823+
792824
// Replays
793825
type BrowsersReplaysListInput struct {
794826
Identifier string
@@ -1955,7 +1987,12 @@ func init() {
19551987
computerDrag.Flags().String("button", "left", "Mouse button: left,middle,right")
19561988
computerDrag.Flags().StringSlice("hold-key", []string{}, "Modifier keys to hold (repeatable)")
19571989

1958-
computerRoot.AddCommand(computerClick, computerMove, computerScreenshot, computerType, computerPressKey, computerScroll, computerDrag)
1990+
// computer set-cursor
1991+
computerSetCursor := &cobra.Command{Use: "set-cursor <id|persistent-id>", Short: "Hide or show the cursor", Args: cobra.ExactArgs(1), RunE: runBrowsersComputerSetCursor}
1992+
computerSetCursor.Flags().Bool("hidden", false, "Whether to hide the cursor (true) or show it (false)")
1993+
_ = computerSetCursor.MarkFlagRequired("hidden")
1994+
1995+
computerRoot.AddCommand(computerClick, computerMove, computerScreenshot, computerType, computerPressKey, computerScroll, computerDrag, computerSetCursor)
19591996
browsersCmd.AddCommand(computerRoot)
19601997

19611998
// playwright
@@ -2462,6 +2499,14 @@ func runBrowsersComputerDragMouse(cmd *cobra.Command, args []string) error {
24622499
return b.ComputerDragMouse(cmd.Context(), BrowsersComputerDragMouseInput{Identifier: args[0], Path: path, Delay: delay, StepDelayMs: stepDelayMs, StepsPerSegment: stepsPerSegment, Button: button, HoldKeys: holdKeys})
24632500
}
24642501

2502+
func runBrowsersComputerSetCursor(cmd *cobra.Command, args []string) error {
2503+
client := getKernelClient(cmd)
2504+
svc := client.Browsers
2505+
hidden, _ := cmd.Flags().GetBool("hidden")
2506+
b := BrowsersCmd{browsers: &svc, computer: &svc.Computer}
2507+
return b.ComputerSetCursor(cmd.Context(), BrowsersComputerSetCursorInput{Identifier: args[0], Hidden: hidden})
2508+
}
2509+
24652510
func truncateURL(url string, maxLen int) string {
24662511
if len(url) <= maxLen {
24672512
return url

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/charmbracelet/fang v0.2.0
99
github.com/golang-jwt/jwt/v5 v5.2.2
1010
github.com/joho/godotenv v1.5.1
11-
github.com/onkernel/kernel-go-sdk v0.18.0
11+
github.com/onkernel/kernel-go-sdk v0.19.0
1212
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
1313
github.com/pterm/pterm v0.12.80
1414
github.com/samber/lo v1.51.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe
9191
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
9292
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
9393
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
94-
github.com/onkernel/kernel-go-sdk v0.18.0 h1:hlBqxL2sEUto6h449b93C0YkAQeRdxrhn5cAScbhjaQ=
95-
github.com/onkernel/kernel-go-sdk v0.18.0/go.mod h1:MjUR92i8UPqjrmneyVykae6GuB3GGSmnQtnjf1v74Dc=
94+
github.com/onkernel/kernel-go-sdk v0.19.0 h1:kfLHmcye/zEF9INP3zIXffmVLGFVZiZNFs4NeVAgya0=
95+
github.com/onkernel/kernel-go-sdk v0.19.0/go.mod h1:t80buN1uCA/hwvm4D2SpjTJzZWcV7bWOFo9d7qdXD8M=
9696
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
9797
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
9898
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)