feat: get screen result for hrp ui server

This commit is contained in:
lilong.129
2024-11-05 17:38:14 +08:00
parent e279ac0a3a
commit 80abc92f71
4 changed files with 51 additions and 2 deletions

View File

@@ -1 +1 @@
v5.0.0+2411051646
v5.0.0+2411051738

View File

@@ -31,6 +31,7 @@ func NewServer(port int) error {
apiV1PlatformSerial.POST("/app/terminal", handleDeviceContext(), terminalAppHandler)
// get screen info
apiV1PlatformSerial.GET("/screenshot", handleDeviceContext(), screenshotHandler)
apiV1PlatformSerial.POST("/screenresult", handleDeviceContext(), screenResultHandler)
apiV1PlatformSerial.GET("/stub/source", handleDeviceContext(), sourceHandler)
apiV1PlatformSerial.GET("/adb/source", handleDeviceContext(), adbSourceHandler)
// Stub operations

View File

@@ -30,6 +30,10 @@ type InputRequest struct {
Frequency int `json:"frequency"` // only iOS
}
type ScreenRequest struct {
Options *uixt.ActionOptions `json:"options,omitempty"`
}
type KeycodeRequest struct {
Keycode int `json:"keycode"`
}

View File

@@ -30,7 +30,51 @@ func screenshotHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, HttpResponse{Result: base64.StdEncoding.EncodeToString(raw.Bytes())})
c.JSON(http.StatusOK,
HttpResponse{
Code: code.Success,
Message: "success",
Result: base64.StdEncoding.EncodeToString(raw.Bytes()),
},
)
}
func screenResultHandler(c *gin.Context) {
dExt, err := getContextDriver(c)
if err != nil {
return
}
var screenReq ScreenRequest
if err := c.ShouldBindJSON(&screenReq); err != nil {
handlerValidateRequestFailedContext(c, err)
return
}
var actionOptions []uixt.ActionOption
if screenReq.Options != nil {
actionOptions = screenReq.Options.Options()
}
screenResult, err := dExt.GetScreenResult(actionOptions...)
if err != nil {
log.Err(err).Msg("get screen result failed")
c.JSON(http.StatusInternalServerError,
HttpResponse{
Code: code.GetErrorCode(err),
Message: err.Error(),
},
)
c.Abort()
return
}
c.JSON(http.StatusOK,
HttpResponse{
Code: code.Success,
Message: "success",
Result: screenResult,
},
)
}
func sourceHandler(c *gin.Context) {