Skip to content

Commit

Permalink
Merge pull request #13 from debugtalk/master
Browse files Browse the repository at this point in the history
add a helper function to get initialized giDevice.Device from gwda.Device
  • Loading branch information
electricbubble authored Jul 31, 2022
2 parents b7fe89c + 7fffca1 commit 07f4517
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ English | [🇨🇳中文](README_CN.md)
go get github.com/electricbubble/gwda
```

## QuickStart

#### [Connection Device](examples/connect/main.go)

```go
Expand Down
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
go get github.com/electricbubble/gwda
```

## 快速上手

#### [连接设备](examples/connect/main.go)

```go
Expand Down
5 changes: 5 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gwda

import (
"fmt"

giDevice "github.com/electricbubble/gidevice"
)

Expand Down Expand Up @@ -45,3 +46,7 @@ func (d Device) DeviceID() int {
func (d Device) SerialNumber() string {
return d.serialNumber
}

func (d Device) GIDevice() giDevice.Device {
return d.d
}
16 changes: 8 additions & 8 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"encoding/json"
"errors"
"fmt"
giDevice "github.com/electricbubble/gidevice"
"net"
"net/http"
"net/url"
"path"
"strings"
"sync"
"time"

giDevice "github.com/electricbubble/gidevice"
)

// NewDriver creates new remote client, this will also start a new session.
Expand All @@ -39,6 +40,7 @@ func NewDriver(capabilities Capabilities, urlPrefix string, mjpegPort ...int) (d
return wd, nil
}

// NewUSBDriver creates new client via USB connected device, this will also start a new session.
func NewUSBDriver(capabilities Capabilities, device ...Device) (driver WebDriver, err error) {
if len(device) == 0 {
if device, err = DeviceList(); err != nil {
Expand Down Expand Up @@ -78,12 +80,10 @@ func NewUSBDriver(capabilities Capabilities, device ...Device) (driver WebDriver
}
ticker := time.NewTicker(DefaultKeepAliveInterval)
for {
select {
case <-ticker.C:
if healthy, err := wd.IsWdaHealthy(); err != nil || !healthy {
ticker.Stop()
return
}
<-ticker.C
if healthy, err := wd.IsWdaHealthy(); err != nil || !healthy {
ticker.Stop()
return
}
}
}()
Expand Down Expand Up @@ -178,7 +178,7 @@ type remoteWD struct {
func (wd *remoteWD) NewSession(capabilities Capabilities) (sessionInfo SessionInfo, err error) {
// [[FBRoute POST:@"/session"].withoutSession respondWithTarget:self action:@selector(handleCreateSession:)]
data := make(map[string]interface{})
if capabilities == nil || len(capabilities) == 0 {
if len(capabilities) == 0 {
data["capabilities"] = make(map[string]interface{})
} else {
data["capabilities"] = map[string]interface{}{"alwaysMatch": capabilities}
Expand Down
3 changes: 2 additions & 1 deletion examples/info/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/electricbubble/gwda"
"log"

"github.com/electricbubble/gwda"
)

func main() {
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module github.com/electricbubble/gwda

go 1.15
go 1.16

require github.com/electricbubble/gidevice v0.0.4
require (
github.com/electricbubble/gidevice v0.6.2
howett.net/plist v1.0.0 // indirect
)
10 changes: 7 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
github.com/electricbubble/gidevice v0.0.4 h1:PbOt4AngNQTtO5j0vCZ3Xcj9mByDtZmjBYLTh8PJ9kc=
github.com/electricbubble/gidevice v0.0.4/go.mod h1:hWRHIPf4uyiEB56hnVHVvu6MoVg7RlJY8ZV2FVgLKZA=
github.com/electricbubble/gidevice v0.6.2 h1:eIeCHH7Xn5fTwnUv3qL8c7L4anKIHtjlTBkgr1LDVTc=
github.com/electricbubble/gidevice v0.6.2/go.mod h1:bRHL2M9qgeEKju8KRvKMZUVEg7t5zMnTiG3SJ3QDH5o=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 h1:EnfXoSqDfSNJv0VBNqY/88RNnhSGYkrHaO0mmFGbVsc=
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
howett.net/plist v0.0.0-20201203080718-1454fab16a06 h1:QDxUo/w2COstK1wIBYpzQlHX/NqaQTcf9jyz347nI58=
howett.net/plist v0.0.0-20201203080718-1454fab16a06/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=

0 comments on commit 07f4517

Please sign in to comment.