Skip to content

Commit

Permalink
tcp connection status
Browse files Browse the repository at this point in the history
  • Loading branch information
naman14 committed May 29, 2017
1 parent ec6e1b7 commit 0fb16ae
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
9 changes: 9 additions & 0 deletions adbhelper.js
Expand Up @@ -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)'
Expand Down Expand Up @@ -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();
Expand Down
23 changes: 20 additions & 3 deletions extension.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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();

},

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions icons/bug_report_icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions icons/remote_icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions icons/remote_off_icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0fb16ae

Please sign in to comment.