From 21641ffda55f12a41b921060bfc66a8b3ce487c8 Mon Sep 17 00:00:00 2001 From: Siyuan Date: Thu, 13 Nov 2025 15:02:30 +0000 Subject: [PATCH] chore: move generated methods to separate files --- internal/native/grpc_client.go | 203 ----------------------- internal/native/grpc_clientmethods.go | 212 ++++++++++++++++++++++++ internal/native/grpc_server.go | 220 ------------------------ internal/native/grpc_servermethods.go | 230 ++++++++++++++++++++++++++ 4 files changed, 442 insertions(+), 423 deletions(-) create mode 100644 internal/native/grpc_clientmethods.go create mode 100644 internal/native/grpc_servermethods.go diff --git a/internal/native/grpc_client.go b/internal/native/grpc_client.go index fec49ecb..772fb839 100644 --- a/internal/native/grpc_client.go +++ b/internal/native/grpc_client.go @@ -256,206 +256,3 @@ func (c *GRPCClient) Close() error { return c.conn.Close() } - -// Video methods -func (c *GRPCClient) VideoSetSleepMode(enabled bool) error { - _, err := c.client.VideoSetSleepMode(context.Background(), &pb.VideoSetSleepModeRequest{Enabled: enabled}) - return err -} - -func (c *GRPCClient) VideoGetSleepMode() (bool, error) { - resp, err := c.client.VideoGetSleepMode(context.Background(), &pb.Empty{}) - if err != nil { - return false, err - } - return resp.Enabled, nil -} - -func (c *GRPCClient) VideoSleepModeSupported() bool { - resp, err := c.client.VideoSleepModeSupported(context.Background(), &pb.Empty{}) - if err != nil { - return false - } - return resp.Supported -} - -func (c *GRPCClient) VideoSetQualityFactor(factor float64) error { - _, err := c.client.VideoSetQualityFactor(context.Background(), &pb.VideoSetQualityFactorRequest{Factor: factor}) - return err -} - -func (c *GRPCClient) VideoGetQualityFactor() (float64, error) { - resp, err := c.client.VideoGetQualityFactor(context.Background(), &pb.Empty{}) - if err != nil { - return 0, err - } - return resp.Factor, nil -} - -func (c *GRPCClient) VideoSetEDID(edid string) error { - _, err := c.client.VideoSetEDID(context.Background(), &pb.VideoSetEDIDRequest{Edid: edid}) - return err -} - -func (c *GRPCClient) VideoGetEDID() (string, error) { - resp, err := c.client.VideoGetEDID(context.Background(), &pb.Empty{}) - if err != nil { - return "", err - } - return resp.Edid, nil -} - -func (c *GRPCClient) VideoLogStatus() (string, error) { - resp, err := c.client.VideoLogStatus(context.Background(), &pb.Empty{}) - if err != nil { - return "", err - } - return resp.Status, nil -} - -func (c *GRPCClient) VideoStop() error { - _, err := c.client.VideoStop(context.Background(), &pb.Empty{}) - return err -} - -func (c *GRPCClient) VideoStart() error { - _, err := c.client.VideoStart(context.Background(), &pb.Empty{}) - return err -} - -// UI methods -func (c *GRPCClient) GetLVGLVersion() (string, error) { - resp, err := c.client.GetLVGLVersion(context.Background(), &pb.Empty{}) - if err != nil { - return "", err - } - return resp.Version, nil -} - -func (c *GRPCClient) UIObjHide(objName string) (bool, error) { - resp, err := c.client.UIObjHide(context.Background(), &pb.UIObjHideRequest{ObjName: objName}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjShow(objName string) (bool, error) { - resp, err := c.client.UIObjShow(context.Background(), &pb.UIObjShowRequest{ObjName: objName}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UISetVar(name string, value string) { - _, _ = c.client.UISetVar(context.Background(), &pb.UISetVarRequest{Name: name, Value: value}) -} - -func (c *GRPCClient) UIGetVar(name string) string { - resp, err := c.client.UIGetVar(context.Background(), &pb.UIGetVarRequest{Name: name}) - if err != nil { - return "" - } - return resp.Value -} - -func (c *GRPCClient) UIObjAddState(objName string, state string) (bool, error) { - resp, err := c.client.UIObjAddState(context.Background(), &pb.UIObjAddStateRequest{ObjName: objName, State: state}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjClearState(objName string, state string) (bool, error) { - resp, err := c.client.UIObjClearState(context.Background(), &pb.UIObjClearStateRequest{ObjName: objName, State: state}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjAddFlag(objName string, flag string) (bool, error) { - resp, err := c.client.UIObjAddFlag(context.Background(), &pb.UIObjAddFlagRequest{ObjName: objName, Flag: flag}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjClearFlag(objName string, flag string) (bool, error) { - resp, err := c.client.UIObjClearFlag(context.Background(), &pb.UIObjClearFlagRequest{ObjName: objName, Flag: flag}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjSetOpacity(objName string, opacity int) (bool, error) { - resp, err := c.client.UIObjSetOpacity(context.Background(), &pb.UIObjSetOpacityRequest{ObjName: objName, Opacity: int32(opacity)}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjFadeIn(objName string, duration uint32) (bool, error) { - resp, err := c.client.UIObjFadeIn(context.Background(), &pb.UIObjFadeInRequest{ObjName: objName, Duration: duration}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjFadeOut(objName string, duration uint32) (bool, error) { - resp, err := c.client.UIObjFadeOut(context.Background(), &pb.UIObjFadeOutRequest{ObjName: objName, Duration: duration}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjSetLabelText(objName string, text string) (bool, error) { - resp, err := c.client.UIObjSetLabelText(context.Background(), &pb.UIObjSetLabelTextRequest{ObjName: objName, Text: text}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UIObjSetImageSrc(objName string, image string) (bool, error) { - resp, err := c.client.UIObjSetImageSrc(context.Background(), &pb.UIObjSetImageSrcRequest{ObjName: objName, Image: image}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) DisplaySetRotation(rotation uint16) (bool, error) { - resp, err := c.client.DisplaySetRotation(context.Background(), &pb.DisplaySetRotationRequest{Rotation: uint32(rotation)}) - if err != nil { - return false, err - } - return resp.Success, nil -} - -func (c *GRPCClient) UpdateLabelIfChanged(objName string, newText string) { - _, _ = c.client.UpdateLabelIfChanged(context.Background(), &pb.UpdateLabelIfChangedRequest{ObjName: objName, NewText: newText}) -} - -func (c *GRPCClient) UpdateLabelAndChangeVisibility(objName string, newText string) { - _, _ = c.client.UpdateLabelAndChangeVisibility(context.Background(), &pb.UpdateLabelAndChangeVisibilityRequest{ObjName: objName, NewText: newText}) -} - -func (c *GRPCClient) SwitchToScreenIf(screenName string, shouldSwitch []string) { - _, _ = c.client.SwitchToScreenIf(context.Background(), &pb.SwitchToScreenIfRequest{ScreenName: screenName, ShouldSwitch: shouldSwitch}) -} - -func (c *GRPCClient) SwitchToScreenIfDifferent(screenName string) { - _, _ = c.client.SwitchToScreenIfDifferent(context.Background(), &pb.SwitchToScreenIfDifferentRequest{ScreenName: screenName}) -} - -func (c *GRPCClient) DoNotUseThisIsForCrashTestingOnly() { - _, _ = c.client.DoNotUseThisIsForCrashTestingOnly(context.Background(), &pb.Empty{}) -} diff --git a/internal/native/grpc_clientmethods.go b/internal/native/grpc_clientmethods.go new file mode 100644 index 00000000..c9a83adc --- /dev/null +++ b/internal/native/grpc_clientmethods.go @@ -0,0 +1,212 @@ +package native + +import ( + "context" + + pb "github.com/jetkvm/kvm/internal/native/proto" +) + +// Below are generated methods, do not edit manually + +// Video methods +func (c *GRPCClient) VideoSetSleepMode(enabled bool) error { + _, err := c.client.VideoSetSleepMode(context.Background(), &pb.VideoSetSleepModeRequest{Enabled: enabled}) + return err +} + +func (c *GRPCClient) VideoGetSleepMode() (bool, error) { + resp, err := c.client.VideoGetSleepMode(context.Background(), &pb.Empty{}) + if err != nil { + return false, err + } + return resp.Enabled, nil +} + +func (c *GRPCClient) VideoSleepModeSupported() bool { + resp, err := c.client.VideoSleepModeSupported(context.Background(), &pb.Empty{}) + if err != nil { + return false + } + return resp.Supported +} + +func (c *GRPCClient) VideoSetQualityFactor(factor float64) error { + _, err := c.client.VideoSetQualityFactor(context.Background(), &pb.VideoSetQualityFactorRequest{Factor: factor}) + return err +} + +func (c *GRPCClient) VideoGetQualityFactor() (float64, error) { + resp, err := c.client.VideoGetQualityFactor(context.Background(), &pb.Empty{}) + if err != nil { + return 0, err + } + return resp.Factor, nil +} + +func (c *GRPCClient) VideoSetEDID(edid string) error { + _, err := c.client.VideoSetEDID(context.Background(), &pb.VideoSetEDIDRequest{Edid: edid}) + return err +} + +func (c *GRPCClient) VideoGetEDID() (string, error) { + resp, err := c.client.VideoGetEDID(context.Background(), &pb.Empty{}) + if err != nil { + return "", err + } + return resp.Edid, nil +} + +func (c *GRPCClient) VideoLogStatus() (string, error) { + resp, err := c.client.VideoLogStatus(context.Background(), &pb.Empty{}) + if err != nil { + return "", err + } + return resp.Status, nil +} + +func (c *GRPCClient) VideoStop() error { + _, err := c.client.VideoStop(context.Background(), &pb.Empty{}) + return err +} + +func (c *GRPCClient) VideoStart() error { + _, err := c.client.VideoStart(context.Background(), &pb.Empty{}) + return err +} + +// UI methods +func (c *GRPCClient) GetLVGLVersion() (string, error) { + resp, err := c.client.GetLVGLVersion(context.Background(), &pb.Empty{}) + if err != nil { + return "", err + } + return resp.Version, nil +} + +func (c *GRPCClient) UIObjHide(objName string) (bool, error) { + resp, err := c.client.UIObjHide(context.Background(), &pb.UIObjHideRequest{ObjName: objName}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjShow(objName string) (bool, error) { + resp, err := c.client.UIObjShow(context.Background(), &pb.UIObjShowRequest{ObjName: objName}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UISetVar(name string, value string) { + _, _ = c.client.UISetVar(context.Background(), &pb.UISetVarRequest{Name: name, Value: value}) +} + +func (c *GRPCClient) UIGetVar(name string) string { + resp, err := c.client.UIGetVar(context.Background(), &pb.UIGetVarRequest{Name: name}) + if err != nil { + return "" + } + return resp.Value +} + +func (c *GRPCClient) UIObjAddState(objName string, state string) (bool, error) { + resp, err := c.client.UIObjAddState(context.Background(), &pb.UIObjAddStateRequest{ObjName: objName, State: state}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjClearState(objName string, state string) (bool, error) { + resp, err := c.client.UIObjClearState(context.Background(), &pb.UIObjClearStateRequest{ObjName: objName, State: state}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjAddFlag(objName string, flag string) (bool, error) { + resp, err := c.client.UIObjAddFlag(context.Background(), &pb.UIObjAddFlagRequest{ObjName: objName, Flag: flag}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjClearFlag(objName string, flag string) (bool, error) { + resp, err := c.client.UIObjClearFlag(context.Background(), &pb.UIObjClearFlagRequest{ObjName: objName, Flag: flag}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjSetOpacity(objName string, opacity int) (bool, error) { + resp, err := c.client.UIObjSetOpacity(context.Background(), &pb.UIObjSetOpacityRequest{ObjName: objName, Opacity: int32(opacity)}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjFadeIn(objName string, duration uint32) (bool, error) { + resp, err := c.client.UIObjFadeIn(context.Background(), &pb.UIObjFadeInRequest{ObjName: objName, Duration: duration}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjFadeOut(objName string, duration uint32) (bool, error) { + resp, err := c.client.UIObjFadeOut(context.Background(), &pb.UIObjFadeOutRequest{ObjName: objName, Duration: duration}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjSetLabelText(objName string, text string) (bool, error) { + resp, err := c.client.UIObjSetLabelText(context.Background(), &pb.UIObjSetLabelTextRequest{ObjName: objName, Text: text}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UIObjSetImageSrc(objName string, image string) (bool, error) { + resp, err := c.client.UIObjSetImageSrc(context.Background(), &pb.UIObjSetImageSrcRequest{ObjName: objName, Image: image}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) DisplaySetRotation(rotation uint16) (bool, error) { + resp, err := c.client.DisplaySetRotation(context.Background(), &pb.DisplaySetRotationRequest{Rotation: uint32(rotation)}) + if err != nil { + return false, err + } + return resp.Success, nil +} + +func (c *GRPCClient) UpdateLabelIfChanged(objName string, newText string) { + _, _ = c.client.UpdateLabelIfChanged(context.Background(), &pb.UpdateLabelIfChangedRequest{ObjName: objName, NewText: newText}) +} + +func (c *GRPCClient) UpdateLabelAndChangeVisibility(objName string, newText string) { + _, _ = c.client.UpdateLabelAndChangeVisibility(context.Background(), &pb.UpdateLabelAndChangeVisibilityRequest{ObjName: objName, NewText: newText}) +} + +func (c *GRPCClient) SwitchToScreenIf(screenName string, shouldSwitch []string) { + _, _ = c.client.SwitchToScreenIf(context.Background(), &pb.SwitchToScreenIfRequest{ScreenName: screenName, ShouldSwitch: shouldSwitch}) +} + +func (c *GRPCClient) SwitchToScreenIfDifferent(screenName string) { + _, _ = c.client.SwitchToScreenIfDifferent(context.Background(), &pb.SwitchToScreenIfDifferentRequest{ScreenName: screenName}) +} + +func (c *GRPCClient) DoNotUseThisIsForCrashTestingOnly() { + _, _ = c.client.DoNotUseThisIsForCrashTestingOnly(context.Background(), &pb.Empty{}) +} diff --git a/internal/native/grpc_server.go b/internal/native/grpc_server.go index f1a1e301..304203ce 100644 --- a/internal/native/grpc_server.go +++ b/internal/native/grpc_server.go @@ -8,8 +8,6 @@ import ( "github.com/rs/zerolog" "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" pb "github.com/jetkvm/kvm/internal/native/proto" ) @@ -100,224 +98,6 @@ func (s *grpcServer) IsReady(ctx context.Context, req *pb.IsReadyRequest) (*pb.I return &pb.IsReadyResponse{Ready: true, VideoReady: true}, nil } -// Video methods -func (s *grpcServer) VideoSetSleepMode(ctx context.Context, req *pb.VideoSetSleepModeRequest) (*pb.Empty, error) { - if err := s.native.VideoSetSleepMode(req.Enabled); err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.Empty{}, nil -} - -func (s *grpcServer) VideoGetSleepMode(ctx context.Context, req *pb.Empty) (*pb.VideoGetSleepModeResponse, error) { - enabled, err := s.native.VideoGetSleepMode() - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.VideoGetSleepModeResponse{Enabled: enabled}, nil -} - -func (s *grpcServer) VideoSleepModeSupported(ctx context.Context, req *pb.Empty) (*pb.VideoSleepModeSupportedResponse, error) { - return &pb.VideoSleepModeSupportedResponse{Supported: s.native.VideoSleepModeSupported()}, nil -} - -func (s *grpcServer) VideoSetQualityFactor(ctx context.Context, req *pb.VideoSetQualityFactorRequest) (*pb.Empty, error) { - if err := s.native.VideoSetQualityFactor(req.Factor); err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.Empty{}, nil -} - -func (s *grpcServer) VideoGetQualityFactor(ctx context.Context, req *pb.Empty) (*pb.VideoGetQualityFactorResponse, error) { - factor, err := s.native.VideoGetQualityFactor() - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.VideoGetQualityFactorResponse{Factor: factor}, nil -} - -func (s *grpcServer) VideoSetEDID(ctx context.Context, req *pb.VideoSetEDIDRequest) (*pb.Empty, error) { - if err := s.native.VideoSetEDID(req.Edid); err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.Empty{}, nil -} - -func (s *grpcServer) VideoGetEDID(ctx context.Context, req *pb.Empty) (*pb.VideoGetEDIDResponse, error) { - edid, err := s.native.VideoGetEDID() - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.VideoGetEDIDResponse{Edid: edid}, nil -} - -func (s *grpcServer) VideoLogStatus(ctx context.Context, req *pb.Empty) (*pb.VideoLogStatusResponse, error) { - logStatus, err := s.native.VideoLogStatus() - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.VideoLogStatusResponse{Status: logStatus}, nil -} - -func (s *grpcServer) VideoStop(ctx context.Context, req *pb.Empty) (*pb.Empty, error) { - procPrefix = "jetkvm: [native]" - setProcTitle(lastProcTitle) - - if err := s.native.VideoStop(); err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.Empty{}, nil -} - -func (s *grpcServer) VideoStart(ctx context.Context, req *pb.Empty) (*pb.Empty, error) { - procPrefix = "jetkvm: [native+video]" - setProcTitle(lastProcTitle) - - if err := s.native.VideoStart(); err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.Empty{}, nil -} - -// UI methods -func (s *grpcServer) GetLVGLVersion(ctx context.Context, req *pb.Empty) (*pb.GetLVGLVersionResponse, error) { - version, err := s.native.GetLVGLVersion() - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.GetLVGLVersionResponse{Version: version}, nil -} - -func (s *grpcServer) UIObjHide(ctx context.Context, req *pb.UIObjHideRequest) (*pb.UIObjHideResponse, error) { - success, err := s.native.UIObjHide(req.ObjName) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjHideResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjShow(ctx context.Context, req *pb.UIObjShowRequest) (*pb.UIObjShowResponse, error) { - success, err := s.native.UIObjShow(req.ObjName) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjShowResponse{Success: success}, nil -} - -func (s *grpcServer) UISetVar(ctx context.Context, req *pb.UISetVarRequest) (*pb.Empty, error) { - s.native.UISetVar(req.Name, req.Value) - return &pb.Empty{}, nil -} - -func (s *grpcServer) UIGetVar(ctx context.Context, req *pb.UIGetVarRequest) (*pb.UIGetVarResponse, error) { - value := s.native.UIGetVar(req.Name) - return &pb.UIGetVarResponse{Value: value}, nil -} - -func (s *grpcServer) UIObjAddState(ctx context.Context, req *pb.UIObjAddStateRequest) (*pb.UIObjAddStateResponse, error) { - success, err := s.native.UIObjAddState(req.ObjName, req.State) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjAddStateResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjClearState(ctx context.Context, req *pb.UIObjClearStateRequest) (*pb.UIObjClearStateResponse, error) { - success, err := s.native.UIObjClearState(req.ObjName, req.State) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjClearStateResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjAddFlag(ctx context.Context, req *pb.UIObjAddFlagRequest) (*pb.UIObjAddFlagResponse, error) { - success, err := s.native.UIObjAddFlag(req.ObjName, req.Flag) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjAddFlagResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjClearFlag(ctx context.Context, req *pb.UIObjClearFlagRequest) (*pb.UIObjClearFlagResponse, error) { - success, err := s.native.UIObjClearFlag(req.ObjName, req.Flag) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjClearFlagResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjSetOpacity(ctx context.Context, req *pb.UIObjSetOpacityRequest) (*pb.UIObjSetOpacityResponse, error) { - success, err := s.native.UIObjSetOpacity(req.ObjName, int(req.Opacity)) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjSetOpacityResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjFadeIn(ctx context.Context, req *pb.UIObjFadeInRequest) (*pb.UIObjFadeInResponse, error) { - success, err := s.native.UIObjFadeIn(req.ObjName, req.Duration) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjFadeInResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjFadeOut(ctx context.Context, req *pb.UIObjFadeOutRequest) (*pb.UIObjFadeOutResponse, error) { - success, err := s.native.UIObjFadeOut(req.ObjName, req.Duration) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjFadeOutResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjSetLabelText(ctx context.Context, req *pb.UIObjSetLabelTextRequest) (*pb.UIObjSetLabelTextResponse, error) { - success, err := s.native.UIObjSetLabelText(req.ObjName, req.Text) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjSetLabelTextResponse{Success: success}, nil -} - -func (s *grpcServer) UIObjSetImageSrc(ctx context.Context, req *pb.UIObjSetImageSrcRequest) (*pb.UIObjSetImageSrcResponse, error) { - success, err := s.native.UIObjSetImageSrc(req.ObjName, req.Image) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.UIObjSetImageSrcResponse{Success: success}, nil -} - -func (s *grpcServer) DisplaySetRotation(ctx context.Context, req *pb.DisplaySetRotationRequest) (*pb.DisplaySetRotationResponse, error) { - success, err := s.native.DisplaySetRotation(uint16(req.Rotation)) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - return &pb.DisplaySetRotationResponse{Success: success}, nil -} - -func (s *grpcServer) UpdateLabelIfChanged(ctx context.Context, req *pb.UpdateLabelIfChangedRequest) (*pb.Empty, error) { - s.native.UpdateLabelIfChanged(req.ObjName, req.NewText) - return &pb.Empty{}, nil -} - -func (s *grpcServer) UpdateLabelAndChangeVisibility(ctx context.Context, req *pb.UpdateLabelAndChangeVisibilityRequest) (*pb.Empty, error) { - s.native.UpdateLabelAndChangeVisibility(req.ObjName, req.NewText) - return &pb.Empty{}, nil -} - -func (s *grpcServer) SwitchToScreenIf(ctx context.Context, req *pb.SwitchToScreenIfRequest) (*pb.Empty, error) { - s.native.SwitchToScreenIf(req.ScreenName, req.ShouldSwitch) - return &pb.Empty{}, nil -} - -func (s *grpcServer) SwitchToScreenIfDifferent(ctx context.Context, req *pb.SwitchToScreenIfDifferentRequest) (*pb.Empty, error) { - s.native.SwitchToScreenIfDifferent(req.ScreenName) - return &pb.Empty{}, nil -} - -func (s *grpcServer) DoNotUseThisIsForCrashTestingOnly(ctx context.Context, req *pb.Empty) (*pb.Empty, error) { - s.native.DoNotUseThisIsForCrashTestingOnly() - return &pb.Empty{}, nil -} - // StreamEvents streams events from the native process func (s *grpcServer) StreamEvents(req *pb.Empty, stream pb.NativeService_StreamEventsServer) error { setProcTitle("connected") diff --git a/internal/native/grpc_servermethods.go b/internal/native/grpc_servermethods.go new file mode 100644 index 00000000..cc16dfd1 --- /dev/null +++ b/internal/native/grpc_servermethods.go @@ -0,0 +1,230 @@ +package native + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + pb "github.com/jetkvm/kvm/internal/native/proto" +) + +// Below are generated methods, do not edit manually + +// Video methods +func (s *grpcServer) VideoSetSleepMode(ctx context.Context, req *pb.VideoSetSleepModeRequest) (*pb.Empty, error) { + if err := s.native.VideoSetSleepMode(req.Enabled); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.Empty{}, nil +} + +func (s *grpcServer) VideoGetSleepMode(ctx context.Context, req *pb.Empty) (*pb.VideoGetSleepModeResponse, error) { + enabled, err := s.native.VideoGetSleepMode() + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.VideoGetSleepModeResponse{Enabled: enabled}, nil +} + +func (s *grpcServer) VideoSleepModeSupported(ctx context.Context, req *pb.Empty) (*pb.VideoSleepModeSupportedResponse, error) { + return &pb.VideoSleepModeSupportedResponse{Supported: s.native.VideoSleepModeSupported()}, nil +} + +func (s *grpcServer) VideoSetQualityFactor(ctx context.Context, req *pb.VideoSetQualityFactorRequest) (*pb.Empty, error) { + if err := s.native.VideoSetQualityFactor(req.Factor); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.Empty{}, nil +} + +func (s *grpcServer) VideoGetQualityFactor(ctx context.Context, req *pb.Empty) (*pb.VideoGetQualityFactorResponse, error) { + factor, err := s.native.VideoGetQualityFactor() + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.VideoGetQualityFactorResponse{Factor: factor}, nil +} + +func (s *grpcServer) VideoSetEDID(ctx context.Context, req *pb.VideoSetEDIDRequest) (*pb.Empty, error) { + if err := s.native.VideoSetEDID(req.Edid); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.Empty{}, nil +} + +func (s *grpcServer) VideoGetEDID(ctx context.Context, req *pb.Empty) (*pb.VideoGetEDIDResponse, error) { + edid, err := s.native.VideoGetEDID() + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.VideoGetEDIDResponse{Edid: edid}, nil +} + +func (s *grpcServer) VideoLogStatus(ctx context.Context, req *pb.Empty) (*pb.VideoLogStatusResponse, error) { + logStatus, err := s.native.VideoLogStatus() + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.VideoLogStatusResponse{Status: logStatus}, nil +} + +func (s *grpcServer) VideoStop(ctx context.Context, req *pb.Empty) (*pb.Empty, error) { + procPrefix = "jetkvm: [native]" + setProcTitle(lastProcTitle) + + if err := s.native.VideoStop(); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.Empty{}, nil +} + +func (s *grpcServer) VideoStart(ctx context.Context, req *pb.Empty) (*pb.Empty, error) { + procPrefix = "jetkvm: [native+video]" + setProcTitle(lastProcTitle) + + if err := s.native.VideoStart(); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.Empty{}, nil +} + +// UI methods +func (s *grpcServer) GetLVGLVersion(ctx context.Context, req *pb.Empty) (*pb.GetLVGLVersionResponse, error) { + version, err := s.native.GetLVGLVersion() + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.GetLVGLVersionResponse{Version: version}, nil +} + +func (s *grpcServer) UIObjHide(ctx context.Context, req *pb.UIObjHideRequest) (*pb.UIObjHideResponse, error) { + success, err := s.native.UIObjHide(req.ObjName) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjHideResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjShow(ctx context.Context, req *pb.UIObjShowRequest) (*pb.UIObjShowResponse, error) { + success, err := s.native.UIObjShow(req.ObjName) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjShowResponse{Success: success}, nil +} + +func (s *grpcServer) UISetVar(ctx context.Context, req *pb.UISetVarRequest) (*pb.Empty, error) { + s.native.UISetVar(req.Name, req.Value) + return &pb.Empty{}, nil +} + +func (s *grpcServer) UIGetVar(ctx context.Context, req *pb.UIGetVarRequest) (*pb.UIGetVarResponse, error) { + value := s.native.UIGetVar(req.Name) + return &pb.UIGetVarResponse{Value: value}, nil +} + +func (s *grpcServer) UIObjAddState(ctx context.Context, req *pb.UIObjAddStateRequest) (*pb.UIObjAddStateResponse, error) { + success, err := s.native.UIObjAddState(req.ObjName, req.State) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjAddStateResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjClearState(ctx context.Context, req *pb.UIObjClearStateRequest) (*pb.UIObjClearStateResponse, error) { + success, err := s.native.UIObjClearState(req.ObjName, req.State) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjClearStateResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjAddFlag(ctx context.Context, req *pb.UIObjAddFlagRequest) (*pb.UIObjAddFlagResponse, error) { + success, err := s.native.UIObjAddFlag(req.ObjName, req.Flag) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjAddFlagResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjClearFlag(ctx context.Context, req *pb.UIObjClearFlagRequest) (*pb.UIObjClearFlagResponse, error) { + success, err := s.native.UIObjClearFlag(req.ObjName, req.Flag) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjClearFlagResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjSetOpacity(ctx context.Context, req *pb.UIObjSetOpacityRequest) (*pb.UIObjSetOpacityResponse, error) { + success, err := s.native.UIObjSetOpacity(req.ObjName, int(req.Opacity)) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjSetOpacityResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjFadeIn(ctx context.Context, req *pb.UIObjFadeInRequest) (*pb.UIObjFadeInResponse, error) { + success, err := s.native.UIObjFadeIn(req.ObjName, req.Duration) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjFadeInResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjFadeOut(ctx context.Context, req *pb.UIObjFadeOutRequest) (*pb.UIObjFadeOutResponse, error) { + success, err := s.native.UIObjFadeOut(req.ObjName, req.Duration) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjFadeOutResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjSetLabelText(ctx context.Context, req *pb.UIObjSetLabelTextRequest) (*pb.UIObjSetLabelTextResponse, error) { + success, err := s.native.UIObjSetLabelText(req.ObjName, req.Text) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjSetLabelTextResponse{Success: success}, nil +} + +func (s *grpcServer) UIObjSetImageSrc(ctx context.Context, req *pb.UIObjSetImageSrcRequest) (*pb.UIObjSetImageSrcResponse, error) { + success, err := s.native.UIObjSetImageSrc(req.ObjName, req.Image) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.UIObjSetImageSrcResponse{Success: success}, nil +} + +func (s *grpcServer) DisplaySetRotation(ctx context.Context, req *pb.DisplaySetRotationRequest) (*pb.DisplaySetRotationResponse, error) { + success, err := s.native.DisplaySetRotation(uint16(req.Rotation)) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &pb.DisplaySetRotationResponse{Success: success}, nil +} + +func (s *grpcServer) UpdateLabelIfChanged(ctx context.Context, req *pb.UpdateLabelIfChangedRequest) (*pb.Empty, error) { + s.native.UpdateLabelIfChanged(req.ObjName, req.NewText) + return &pb.Empty{}, nil +} + +func (s *grpcServer) UpdateLabelAndChangeVisibility(ctx context.Context, req *pb.UpdateLabelAndChangeVisibilityRequest) (*pb.Empty, error) { + s.native.UpdateLabelAndChangeVisibility(req.ObjName, req.NewText) + return &pb.Empty{}, nil +} + +func (s *grpcServer) SwitchToScreenIf(ctx context.Context, req *pb.SwitchToScreenIfRequest) (*pb.Empty, error) { + s.native.SwitchToScreenIf(req.ScreenName, req.ShouldSwitch) + return &pb.Empty{}, nil +} + +func (s *grpcServer) SwitchToScreenIfDifferent(ctx context.Context, req *pb.SwitchToScreenIfDifferentRequest) (*pb.Empty, error) { + s.native.SwitchToScreenIfDifferent(req.ScreenName) + return &pb.Empty{}, nil +} + +func (s *grpcServer) DoNotUseThisIsForCrashTestingOnly(ctx context.Context, req *pb.Empty) (*pb.Empty, error) { + s.native.DoNotUseThisIsForCrashTestingOnly() + return &pb.Empty{}, nil +}