package pluginsdk import ( "context" "github.com/Nwflower/reims-go/pkg/pluginproto" ) // The console methods a plugin may call on a VM the user authorized it for. // A key or a pointer button sent with a press stays held in the guest until a // release arrives, so a caller that holds input must pair it or call Release; // the host lifts whatever is still held when the plugin's process goes away. // Screenshot captures the guest screen. Region is measured in the coordinate // space of the reference frame of size Width by Height, and MaxWidth caps the // width of the returned image. A Blank frame is a normal state during boot, // login and display switches, not a failure. func (s *Server) Screenshot(ctx context.Context, req pluginproto.ScreenshotParams) (pluginproto.ScreenshotResult, error) { var res pluginproto.ScreenshotResult err := s.callFeature(ctx, "host/console.screenshot", req, &res) return res, err } // MovePointer moves the pointer to x, y, given in a frame of size width by // height. func (s *Server) MovePointer(ctx context.Context, vm string, x, y, width, height int) error { return s.callFeature(ctx, "host/console.pointer", pluginproto.PointerParams{ VM: vm, Action: "move", X: x, Y: y, Width: width, Height: height, }, nil) } // PointerButton presses or releases one pointer button. func (s *Server) PointerButton(ctx context.Context, vm, button string, down bool) error { return s.callFeature(ctx, "host/console.pointer", pluginproto.PointerParams{ VM: vm, Action: "button", Button: button, Down: &down, }, nil) } // Click presses and releases one pointer button. func (s *Server) Click(ctx context.Context, vm, button string) error { return s.callFeature(ctx, "host/console.pointer", pluginproto.PointerParams{ VM: vm, Action: "click", Button: button, }, nil) } // Scroll sends wheel steps. A positive delta scrolls down, or right when // horizontal is set. func (s *Server) Scroll(ctx context.Context, vm string, delta int, horizontal bool) error { return s.callFeature(ctx, "host/console.pointer", pluginproto.PointerParams{ VM: vm, Action: "scroll", Delta: delta, Horizontal: horizontal, }, nil) } // Key presses and releases one key with its modifiers held. func (s *Server) Key(ctx context.Context, vm, key string, modifiers ...string) error { return s.callFeature(ctx, "host/console.key", pluginproto.KeyParams{ VM: vm, Key: key, Modifiers: modifiers, }, nil) } // KeyDown presses one key and leaves it held in the guest. func (s *Server) KeyDown(ctx context.Context, vm, key string) error { down := true return s.callFeature(ctx, "host/console.key", pluginproto.KeyParams{VM: vm, Key: key, Down: &down}, nil) } // KeyUp releases one key this plugin pressed with KeyDown. func (s *Server) KeyUp(ctx context.Context, vm, key string) error { down := false return s.callFeature(ctx, "host/console.key", pluginproto.KeyParams{VM: vm, Key: key, Down: &down}, nil) } // Release lifts the keys and pointer buttons this plugin still holds. func (s *Server) Release(ctx context.Context, vm string, keys, buttons []string) error { return s.callFeature(ctx, "host/console.release", pluginproto.ReleaseParams{ VM: vm, Keys: keys, Buttons: buttons, }, nil) } // Type types text as US-layout key strokes and returns how many characters // reached the guest. func (s *Server) Type(ctx context.Context, vm, text string) (int, error) { var res pluginproto.CharactersResult if err := s.callFeature(ctx, "host/console.type", pluginproto.TypeParams{VM: vm, Text: text}, &res); err != nil { return 0, err } return res.Characters, nil } // TypeSecret has the host type one of this plugin's own secret settings. The // plugin never sees the value, and the user must have enabled the plugin's // secret-typing consent for that VM. func (s *Server) TypeSecret(ctx context.Context, vm, setting string) (int, error) { var res pluginproto.CharactersResult if err := s.callFeature(ctx, "host/console.typeSecret", pluginproto.TypeSecretParams{VM: vm, Setting: setting}, &res); err != nil { return 0, err } return res.Characters, nil }