From 0fb16aeef62a8e70837cdacdc2787571b8aece37 Mon Sep 17 00:00:00 2001 From: Naman Dwivedi Date: Mon, 29 May 2017 16:33:40 +0530 Subject: [PATCH] tcp connection status --- adbhelper.js | 9 +++++++++ extension.js | 23 ++++++++++++++++++++--- icons/bug_report_icon.svg | 4 ++++ icons/remote_icon.svg | 4 ++++ icons/remote_off_icon.svg | 4 ++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 icons/bug_report_icon.svg create mode 100644 icons/remote_icon.svg create mode 100644 icons/remote_off_icon.svg diff --git a/adbhelper.js b/adbhelper.js index 1211c4f..5ccf8d5 100644 --- a/adbhelper.js +++ b/adbhelper.js @@ -49,6 +49,10 @@ function getDeviceDetail(deviceId) { } } +function startDaemon() { + GLib.spawn_async(null, ["bash", "-c", "adb devices"], null, GLib.SpawnFlags.SEARCH_PATH, null, null); + +} function takeScreenshot(deviceId) { let time = '$(date +%Y-%m-%d-%H:%M)' @@ -79,6 +83,11 @@ function establishTCPConnection(deviceId) { } +function useUsb() { + let [res, out, error] = GLib.spawn_async(null, ["bash", "-c", "adb usb"], null, GLib.SpawnFlags.SEARCH_PATH, null, null); + +} + function getDeviceIp(deviceId) { let [res, out, error] = GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId +" shell ip route | awk '{print $9}'"], null, GLib.SpawnFlags.SEARCH_PATH, null, null); return out.toString().trim(); diff --git a/extension.js b/extension.js index a06b33f..e3a3cad 100644 --- a/extension.js +++ b/extension.js @@ -19,6 +19,7 @@ const Me = ExtensionUtils.getCurrentExtension(); const AdbHelper = Me.imports.adbhelper; let screenRecord = {recording: false, deviceId: 0}; +let tcpConnection ={connected: false}; const AndroidMenuItem = new Lang.Class({ Name: 'AndroidMenuItem', @@ -71,6 +72,7 @@ const AndroidMenu = new Lang.Class({ this.actor.connect('button-press-event', Lang.bind(this,this._findDevices)); this._addErrorItem("No devices found"); + AdbHelper.startDaemon(); }, @@ -117,8 +119,15 @@ const AndroidMenu = new Lang.Class({ }, _connectTCP: function(device) { - let status = AdbHelper.establishTCPConnection(device.deviceId) - Main.notify(status) + + if(tcpConnection.connected) { + lAdbHelper.useUsb(); + tcpConnection.connected = false; + } else { + let status = AdbHelper.establishTCPConnection(device.deviceId); + tcpConnection.connected = true; + Main.notify(status); + } }, _addMenuItems: function(devices) { @@ -156,7 +165,15 @@ const AndroidMenu = new Lang.Class({ })); section.addMenuItem(recordScreenItem); - let remoteItem = new AndroidMenuItem({label: "Establish remote connection", icon: "android_icon"}); + let remoteLabel = "Establish remote connection" + let remoteIcon = "remote_icon" + + if(tcpConnection.connected) { + remoteLabel = "Connected over TCP. Click to use USB instead"; + remoteIcon = 'remote_off_icon' + } + + let remoteItem = new AndroidMenuItem({label: remoteLabel, icon: remoteIcon}); remoteItem.connect('activate', Lang.bind(this, function() { this._connectTCP(device) diff --git a/icons/bug_report_icon.svg b/icons/bug_report_icon.svg new file mode 100644 index 0000000..f599e66 --- /dev/null +++ b/icons/bug_report_icon.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/icons/remote_icon.svg b/icons/remote_icon.svg new file mode 100644 index 0000000..657fd56 --- /dev/null +++ b/icons/remote_icon.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/icons/remote_off_icon.svg b/icons/remote_off_icon.svg new file mode 100644 index 0000000..94aab42 --- /dev/null +++ b/icons/remote_off_icon.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file