diff --git a/main.go b/main.go index 99f75f9..0fe973c 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ var ( debug bool rt = mux.NewRouter() + udidNames = map[string]string{} ) type statusResp struct { @@ -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", diff --git a/revproxy.go b/revproxy.go index 95161ae..6c67d1d 100644 --- a/revproxy.go +++ b/revproxy.go @@ -9,6 +9,7 @@ import ( "net/url" "strconv" "strings" + // "fmt" ) type transport struct { @@ -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)) diff --git a/web/assets/remote-control.html b/web/assets/remote-control.html index abdf288..103c0b2 100644 --- a/web/assets/remote-control.html +++ b/web/assets/remote-control.html @@ -78,6 +78,10 @@ height: 100%; } + .cursor-pointer { + cursor: pointer; + } + video::-webkit-media-controls-panel { /* always show video controls */ display: flex !important; @@ -96,7 +100,7 @@
-

iPhone 6

+

{{device.name}}


@@ -104,22 +108,25 @@

设备详情

+ + + + - + - - - -
UDID
ScreenSize x
SessionId + + +
RefreshCount
Current{{current.toFixed(3)}} mA
@@ -133,6 +140,7 @@

设备详情

+
@@ -258,6 +266,9 @@

设备详情

el: "#app", // delimiters: ["[[", "]]"], data: { + device: { + name: '', + }, display: { width: 0, height: 0, @@ -267,7 +278,6 @@

设备详情

refreshCount: 0, sessionId: null, pageHidden: false, - current: 0, inputText: '', wsAdmin: null, record: { @@ -317,6 +327,14 @@

设备详情

}.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) { @@ -409,7 +427,7 @@

设备详情

fromY: fromY, toX: toX, toY: toY, - duration: 0.2, + duration: 0, }) }) }, @@ -422,6 +440,9 @@

设备详情

console.log(ret); }) }, + clearText: function(n) { + this.sendText("\b".repeat(n || 30)) + }, sendText: function(text) { return $.ajax({ url: "/session/" + this.sessionId + "/wda/keys", @@ -458,6 +479,7 @@

设备详情

}) .then(function(ret) { this.sessionId = ret.sessionId; + Object.assign(this.device, ret.value.device); return $.ajax({ url: "/session/" + ret.sessionId + "/window/size", })