Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
add udid and device name
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Aug 29, 2017
1 parent d2a7a91 commit f94790f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
debug bool

rt = mux.NewRouter()
udidNames = map[string]string{}
)

type statusResp struct {
Expand Down Expand Up @@ -147,6 +148,12 @@ func main() {
if pWda == "" {
return
}
// device name
nameBytes, _ := exec.Command("idevicename", "-u", udid).Output()
deviceName := strings.TrimSpace(string(nameBytes))
udidNames[udid] = deviceName
log.Printf("device name: %s", deviceName)

log.Printf("launch WebDriverAgent(dir=%s)", pWda)
c := exec.Command("xcodebuild",
"-verbose",
Expand Down
6 changes: 5 additions & 1 deletion revproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"strconv"
"strings"
// "fmt"
)

type transport struct {
Expand Down Expand Up @@ -36,7 +37,10 @@ func (t *transport) RoundTrip(req *http.Request) (resp *http.Response, err error
return nil, err
}
resp.Body.Close()
jsonResp.Value["udid"] = udid
jsonResp.Value["device"] = map[string]interface{}{
"udid": udid,
"name": udidNames[udid],
}
data, _ := json.Marshal(jsonResp)
// update body and fix length
resp.Body = ioutil.NopCloser(bytes.NewReader(data))
Expand Down
38 changes: 30 additions & 8 deletions web/assets/remote-control.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
height: 100%;
}

.cursor-pointer {
cursor: pointer;
}

video::-webkit-media-controls-panel {
/* always show video controls */
display: flex !important;
Expand All @@ -96,30 +100,33 @@
</div>
</div>
<div class="col-sm-6">
<h3>iPhone 6</h3>
<h3>{{device.name}}</h3>
<hr>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">设备详情</h3>
</div>
<table class="table">
<tbody>
<tr>
<td>UDID</td>
<td v-text="device.udid"></td>
</tr>
<tr>
<td>ScreenSize</td>
<td><span v-text="display.width"></span>x<span v-text="display.height"></span></td>
</tr>
<tr>
<td>SessionId</td>
<td><span v-text="sessionId"></span></td>
<td>
<span v-text="sessionId"></span>
<span @click="refreshSessionId" class="glyphicon glyphicon-refresh cursor-pointer"></span>
</td>
</tr>
<tr>
<td>RefreshCount</td>
<td><span v-text="refreshCount"></span></td>
</tr>
<tr>
<td>Current</td>
<td>{{current.toFixed(3)}} mA</td>
</tr>
</tbody>
</table>
</div>
Expand All @@ -133,6 +140,7 @@ <h3 class="panel-title">设备详情</h3>
<input type="text" class="form-control" v-model="inputText" placeholder="Input text ..." @keyup.enter="sendText(inputText+'\n')">
<span class="input-group-btn">
<button class="btn btn-default" type="button" @click="sendText(inputText)">SendText</button>
<button class="btn btn-default" type="button" @click="clearText(30)">Clear</button>
</span>
</div>
</div>
Expand Down Expand Up @@ -258,6 +266,9 @@ <h3 class="panel-title">设备详情</h3>
el: "#app",
// delimiters: ["[[", "]]"],
data: {
device: {
name: '',
},
display: {
width: 0,
height: 0,
Expand All @@ -267,7 +278,6 @@ <h3 class="panel-title">设备详情</h3>
refreshCount: 0,
sessionId: null,
pageHidden: false,
current: 0,
inputText: '',
wsAdmin: null,
record: {
Expand Down Expand Up @@ -317,6 +327,14 @@ <h3 class="panel-title">设备详情</h3>
}.bind(this);
},
methods: {
refreshSessionId: function() {
$.ajax({
url: "/status",
})
.then(function(ret) {
this.sessionId = ret.sessionId;
}.bind(this))
},
toggleRecord: function() {
var self = this;
if (!this.record.running) {
Expand Down Expand Up @@ -409,7 +427,7 @@ <h3 class="panel-title">设备详情</h3>
fromY: fromY,
toX: toX,
toY: toY,
duration: 0.2,
duration: 0,
})
})
},
Expand All @@ -422,6 +440,9 @@ <h3 class="panel-title">设备详情</h3>
console.log(ret);
})
},
clearText: function(n) {
this.sendText("\b".repeat(n || 30))
},
sendText: function(text) {
return $.ajax({
url: "/session/" + this.sessionId + "/wda/keys",
Expand Down Expand Up @@ -458,6 +479,7 @@ <h3 class="panel-title">设备详情</h3>
})
.then(function(ret) {
this.sessionId = ret.sessionId;
Object.assign(this.device, ret.value.device);
return $.ajax({
url: "/session/" + ret.sessionId + "/window/size",
})
Expand Down

0 comments on commit f94790f

Please sign in to comment.