Skip to content

Commit 4717abe

Browse files
authored
Merge pull request #282 from gifflet/feature/recent-apps-button
Add recent apps endpoint
2 parents d583e96 + ae33626 commit 4717abe

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

hub-ui

provider/router/control.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@ func deviceHome(dev devices.PlatformDevice) (*http.Response, error) {
289289
}
290290
}
291291

292+
func deviceRecents(dev devices.PlatformDevice) error {
293+
if dev.GetOS() == "ios" {
294+
return fmt.Errorf("App switcher not supported on iOS via WDA")
295+
}
296+
cmd := exec.CommandContext(dev.GetContext(), "adb", "-s", dev.GetUDID(), "shell", "input", "keyevent", "KEYCODE_APP_SWITCH")
297+
return cmd.Run()
298+
}
299+
292300
func activateApp(dev devices.PlatformDevice, appIdentifier string) (*http.Response, error) {
293301
if dev.GetOS() == "ios" {
294302
requestBody := struct {

provider/router/device_routes.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ func DeviceHome(c *gin.Context) {
8686
c.JSON(homeResponse.StatusCode, models.APIResponse[any]{Success: homeResponse.StatusCode < 400, Message: string(homeResponseBody)})
8787
}
8888

89+
func DeviceRecents(c *gin.Context) {
90+
udid := c.Param("udid")
91+
platDev, ok := devices.DevManager.Get(udid)
92+
if !ok {
93+
api.NotFound(c, fmt.Sprintf("Device with UDID %s not found", udid))
94+
return
95+
}
96+
platDev.GetLogger().LogInfo("appium_interact", "Opening Recent Apps")
97+
98+
if err := deviceRecents(platDev); err != nil {
99+
platDev.GetLogger().LogError("appium_interact", fmt.Sprintf("Failed to open Recent Apps - %s", err))
100+
api.InternalError(c, err.Error())
101+
return
102+
}
103+
104+
api.OKMessage(c, "Recent Apps opened")
105+
}
106+
89107
func DeviceGetClipboard(c *gin.Context) {
90108
udid := c.Param("udid")
91109
platDev, ok := devices.DevManager.Get(udid)

provider/router/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func HandleRequests() *gin.Engine {
5757
deviceGroup.POST("/tap", DeviceTap)
5858
deviceGroup.POST("/touchAndHold", DeviceTouchAndHold)
5959
deviceGroup.POST("/home", DeviceHome)
60+
deviceGroup.POST("/recents", DeviceRecents)
6061
deviceGroup.POST("/lock", DeviceLock)
6162
deviceGroup.POST("/unlock", DeviceUnlock)
6263
deviceGroup.POST("/screenshot", DeviceScreenshot)

0 commit comments

Comments
 (0)