microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b5dd05b96ebb0f85736935514bd3fef31f7af2d5

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/android/androidPlatform.ts

44lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as Q from "q";
5import {IAppPlatform} from "../platformResolver";
6import {IRunOptions} from "../launchArgs";
7import {CommandExecutor} from "../../common/commandExecutor";
8import {Package} from "../../common/node/package";
9import {PackageNameResolver} from "../../common/android/packageNameResolver";
10import {MakeOutcomeFailDependingOnOutput, PatternToFailure} from "../../common/MakeOutcomeFailDependingOnOutput";
11
12/**
13 * Android specific platform implementation for debugging RN applications.
14 */
15export class AndroidPlatform implements IAppPlatform {
16 // We should add the common Android build/run erros we find to this list
17 private static RUN_ANDROID_FAILURE_PATTERNS: PatternToFailure = {
18 "Failed to install on any devices": "Could not install the app on any available device. Make sure you have a correctly"
19 + " configured device or emulator running. See https://facebook.github.io/react-native/docs/android-setup.html",
20 "com.android.ddmlib.ShellCommandUnresponsiveException": "An Android shell command timed-out. Please retry the operation." };
21
22 private static RUN_ANDROID_SUCCESS_PATTERNS: string[] = ["BUILD SUCCESSFUL", "Starting the app", "Starting: Intent"];
23
24 public runApp(runOptions: IRunOptions): Q.Promise<void> {
25 const runAndroidSpawn = new CommandExecutor(runOptions.projectRoot).spawnChildReactCommandProcess("run-android");
26 return new MakeOutcomeFailDependingOnOutput(
27 () =>
28 Q(AndroidPlatform.RUN_ANDROID_SUCCESS_PATTERNS),
29 () =>
30 Q(AndroidPlatform.RUN_ANDROID_FAILURE_PATTERNS)).process(runAndroidSpawn);
31 }
32
33 public enableJSDebuggingMode(runOptions: IRunOptions): Q.Promise<void> {
34 let pkg = new Package(runOptions.projectRoot);
35
36 return pkg.name()
37 .then(appName => new PackageNameResolver(appName).resolvePackageName(runOptions.projectRoot))
38 .then(packageName => {
39 let enableDebugCommand = `adb shell am broadcast -a "${packageName.toLowerCase()}.RELOAD_APP_ACTION" --ez jsproxy true`;
40 let cexec = new CommandExecutor(runOptions.projectRoot);
41 return cexec.execute(enableDebugCommand);
42 });
43 }
44}