microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.3

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/common/android/deviceHelper.ts

58lines · modeblame

77e8babbdigeff10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
fcb6a5dadlebu10 years ago4import {ChildProcess} from "../node/childProcess";
5import {CommandExecutor} from "../commandExecutor";
6import * as Q from "q";
7
8export interface IDevice {
9id: string;
10isOnline: boolean;
11}
12
aab2095edigeff10 years ago13export interface IDeviceHelper {
14getConnectedDevices(): Q.Promise<IDevice[]>;
15reloadAppInDebugMode(projectRoot: string, packageName: string, debugTarget?: string): Q.Promise<void>;
16launchApp(projectRoot: string, packageName: string, debugTarget?: string): Q.Promise<void>;
17}
18
19export class DeviceHelper implements IDeviceHelper {
fcb6a5dadlebu10 years ago20
21/**
22* Gets the list of Android connected devices and emulators.
23*/
24public getConnectedDevices(): Q.Promise<IDevice[]> {
25let childProcess = new ChildProcess();
26return childProcess.execToString("adb devices")
27.then(output => {
28return this.parseConnectedDevices(output);
29});
30}
31
32/**
33* Broadcasts an intent to reload the application in debug mode.
34*/
35public reloadAppInDebugMode(projectRoot: string, packageName: string, debugTarget?: string): Q.Promise<void> {
2a8515bcdlebu10 years ago36let enableDebugCommand = `adb ${debugTarget ? "-s " + debugTarget : ""} shell am broadcast -a "${packageName}.RELOAD_APP_ACTION" --ez jsproxy true`;
fcb6a5dadlebu10 years ago37return new CommandExecutor(projectRoot).execute(enableDebugCommand);
38}
39
40/**
41* Sends an intent which launches the main activity of the application.
42*/
43public launchApp(projectRoot: string, packageName: string, debugTarget?: string): Q.Promise<void> {
2a8515bcdlebu10 years ago44let launchAppCommand = `adb -s ${debugTarget} shell am start -n ${packageName}/.MainActivity`;
fcb6a5dadlebu10 years ago45return new CommandExecutor(projectRoot).execute(launchAppCommand);
46}
47
48private parseConnectedDevices(input: string): IDevice[] {
49let result: IDevice[] = [];
50let regex = new RegExp("^(\\S+)\\t(\\S+)$", "mg");
51let match = regex.exec(input);
52while (match != null) {
53result.push({ id: match[1], isOnline: match[2] === "device" });
54match = regex.exec(input);
55}
56return result;
57}
58}