Skip to content

Commit

Permalink
- Improved plugin commands location and fixes in commands registry.
Browse files Browse the repository at this point in the history
- Improved Readme
  • Loading branch information
vinicioslc committed Jan 19, 2020
1 parent 0d13edd commit 7209b8b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 92 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# ADB Interface for VSCode

[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fvinicioslc%2Fadb-interface-vscode%2Fbadge%3Fref%3Dmaster&style=flat-square)](https://actions-badge.atrox.dev/vinicioslc/adb-interface-vscode/goto?ref=master)
![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/vinicioslc.adb-interface-vscode?style=flat-square)
![GitHub](https://img.shields.io/github/license/vinicioslc/adb-interface-vscode?style=flat-square)
![Visual Studio Marketplace Installs](https://img.shields.io/visual-studio-marketplace/i/vinicioslc.adb-interface-vscode?style=flat-square)
![Visual Studio Marketplace Rating (Stars)](https://img.shields.io/visual-studio-marketplace/stars/vinicioslc.adb-interface-vscode?style=flat-square)
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TKRZ7F4FV4QY4&source=url">![Donation will make this tree growth](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)</a>
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TKRZ7F4FV4QY4&source=url">paypal</a>

An simple adb extesion that makes possible to connect to an device over wifi connection without console.
# ADB Interface for VSCode

> #### Help are welcome ;)
Im am a simple adb extesion that makes possible to connect to an device over wifi connection without console.

> 1k > Installs im so thankful who installed !! \o\o\o\o/o/o/o/
`Help are welcome ;)`

`⚠️ Attention !! ONLY TESTED IN WINDOWS !! (For while, you must have ADB at your Enviroment Variables)`
`⚠️ WARN !! ONLY TESTED IN WINDOWS !! (For while, you must have ADB at your Enviroment Variables)`

## ADB commands.

Expand Down
39 changes: 19 additions & 20 deletions src/adb-manager/device-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { IConsoleInterface } from "../console-interface/iconsole-interface"
import adbCommands from "./adb-commands"
import { IConsoleInterface } from '../console-interface/iconsole-interface'
import adbCommands from './adb-commands'

export class DeviceHelpers {
static getDeviceManufacturer(
ConsoleInstance: IConsoleInterface,
ipAddress: string
): string {
return ConsoleInstance.execConsoleSync(
adbCommands.GET_DEVICE_MODEL(ipAddress)
).toString()
}

static getDeviceModel(
ConsoleInstance: IConsoleInterface,
deviceIP: string
): string {
return ConsoleInstance.execConsoleSync(
adbCommands.GET_DEVICE_MODEL(deviceIP)
).toString()
}
static getDeviceManufacturer(
ConsoleInstance: IConsoleInterface,
ipAddress: string
): string {
return ConsoleInstance.execConsoleSync(
adbCommands.GET_DEVICE_MODEL(ipAddress)
).toString()
}


static getDeviceModel(
ConsoleInstance: IConsoleInterface,
deviceIP: string
): string {
return ConsoleInstance.execConsoleSync(
adbCommands.GET_DEVICE_MODEL(deviceIP)
).toString()
}
}
17 changes: 8 additions & 9 deletions src/adb-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import adbCommands from './adb-commands'
import { ConsoleChannel } from '../console-channel'
import { ConsoleChannel, consoleReturnAre } from '../console-channel'
import adbReturns from './adb-returns'
import adbMessages from './adb-messages'
import { NetHelpers } from '../net-helpers'
Expand All @@ -15,7 +15,6 @@ const mapIPToDeviceName = (ipAddress: string): string => {
)
return `${extractedIP} | ${nameOfDevice}`
} catch (e) {
console.log(e)
return `${extractedIP} | NO DEVICE INFO`
}
}
Expand All @@ -37,21 +36,21 @@ export class ADBChannel extends ConsoleChannel {
deviceIP
)

if (output.includes(adbReturns.CONNECTED_TO())) {
if (consoleReturnAre(output, adbReturns.CONNECTED_TO())) {
finalResult = new ADBResult(
ADBResultState.ConnectedToDevice,
`Connected to: ${deviceName}`
)
}
if (output.includes(adbReturns.ALLREADY_CONNECTED_TO())) {
if (consoleReturnAre(output, adbReturns.ALLREADY_CONNECTED_TO())) {
throw new ADBInterfaceException(`Allready connected to: ${deviceName}`)
}
if (output.includes(adbReturns.CONNECTION_REFUSED(deviceIP))) {
if (consoleReturnAre(output, adbReturns.CONNECTION_REFUSED(deviceIP))) {
throw new ADBInterfaceException(
'Connection refused:\n Target machine actively refused connection.'
)
}
if (output.includes(adbReturns.MISSING_PORT(deviceIP))) {
if (consoleReturnAre(output, adbReturns.MISSING_PORT(deviceIP))) {
throw new ADBInterfaceException('Port is missing fail to connect in ADB.')
}

Expand All @@ -67,7 +66,7 @@ export class ADBChannel extends ConsoleChannel {
adbCommands.RESET_PORTS()
)
const output = result.toString()
if (output.includes(adbReturns.RESTARTING_PORT())) {
if (consoleReturnAre(output, adbReturns.RESTARTING_PORT())) {
finalResult = new ADBResult(
ADBResultState.DevicesInPortMode,
adbMessages.DEVICES_IN_TCP_MODE()
Expand Down Expand Up @@ -96,7 +95,7 @@ export class ADBChannel extends ConsoleChannel {
adbCommands.ADB_DISCONNECT_ALL()
)
const output = result.toString()
if (output.includes(adbReturns.DISCONNECTED_EVERTHING())) {
if (consoleReturnAre(output, adbReturns.DISCONNECTED_EVERTHING())) {
finalResult = new ADBResult(
ADBResultState.DisconnectedEverthing,
'Disconnected from all devices'
Expand All @@ -117,7 +116,7 @@ export class ADBChannel extends ConsoleChannel {
adbCommands.LIST_ADB_DEVICES()
)
const output = result.toString()
if (output.includes(adbReturns.LISTING_DEVICES())) {
if (consoleReturnAre(output, adbReturns.LISTING_DEVICES())) {
let ips = output.split(/[\r]|[\n]/gim)
ips = ips.filter(ip => IPHelpers.isAnIPAddress(ip))
// found devices on lan
Expand Down
57 changes: 57 additions & 0 deletions src/commands-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
ResetDevicesPort,
DisconnectAnyDevice,
ConnectToDevice,
ConnectToDeviceFromList,
EnableFirebaseDebugView,
DisableFirebaseDebugView,
KillADBServer
} from './extension/index'
import * as vscode from 'vscode'

export function commandsRegistry(vscodeContext: vscode.ExtensionContext) {
return [
{
name: 'adbInterface.adbwificonnect',
callback: () => {
return ConnectToDevice(vscodeContext)
}
},
{
name: 'adbInterface.adbResetPorts',
callback: () => {
return ResetDevicesPort(vscodeContext)
}
},
{
name: 'adbInterface.disconnectEverthing',
callback: () => {
return DisconnectAnyDevice(vscodeContext)
}
},
{
name: 'adbInterface.connectToDeviceFromList',
callback: () => {
return ConnectToDeviceFromList(vscodeContext)
}
},
{
name: 'adbInterface.enableFirebaseDebug',
callback: () => {
return EnableFirebaseDebugView(vscodeContext)
}
},
{
name: 'adbInterface.disableFirebaseDebug',
callback: () => {
return DisableFirebaseDebugView(vscodeContext)
}
},
{
name: 'adbInterface.killserver',
callback: () => {
return KillADBServer(vscodeContext)
}
}
]
}
3 changes: 3 additions & 0 deletions src/console-channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ export class ConsoleChannel {
return this.consoleInstance.execConsoleSync(consoleCommand)
}
}
export function consoleReturnAre(output: string, expected: string): boolean {
return output.includes(expected)
}
60 changes: 4 additions & 56 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode'
import {
ResetDevicesPort,
DisconnectAnyDevice,
ConnectToDevice,
ConnectToDeviceFromList,
EnableFirebaseDebugView,
DisableFirebaseDebugView,
KillADBServer
} from './extension/index'
import { commandsRegistry } from './commands-registry'

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
Expand All @@ -20,58 +12,14 @@ export function activate(context: vscode.ExtensionContext) {
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const commands = [
{
name: 'adbInterface.adbwificonnect',
callback: () => {
return ConnectToDevice(context)
}
},
{
name: 'adbInterface.adbResetPorts',
callback: () => {
return ResetDevicesPort(context)
}
},
{
name: 'adbInterface.disconnectEverthing',
callback: () => {
return DisconnectAnyDevice(context)
}
},
{
name: 'adbInterface.connectToDeviceFromList',
callback: () => {
return ConnectToDeviceFromList(context)
}
},
{
name: 'adbInterface.enableFirebaseDebug',
callback: () => {
return EnableFirebaseDebugView(context)
}
},
{
name: 'adbInterface.disableFirebaseDebug',
callback: () => {
return DisableFirebaseDebugView(context)
}
},
{
name: 'adbInterface.killserver',
callback: () => {
return KillADBServer(context)
}
}
]
for (const command of commands) {

commandsRegistry(context).map(command => {
let subscription = vscode.commands.registerCommand(
command.name,
command.callback
)
context.subscriptions.push(subscription)
}
return
})
}

// this method is called when your extension is deactivated
Expand Down

0 comments on commit 7209b8b

Please sign in to comment.