microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
9ce5a77672ce675025efc1b6f9130474c60ccd0b

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/android/androidPlatform.ts

45lines · 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 "Android project not found": "Android project not found." };
22
23 private static RUN_ANDROID_SUCCESS_PATTERNS: string[] = ["BUILD SUCCESSFUL", "Starting the app", "Starting: Intent"];
24
25 public runApp(runOptions: IRunOptions): Q.Promise<void> {
26 const runAndroidSpawn = new CommandExecutor(runOptions.projectRoot).spawnChildReactCommandProcess("run-android");
27 return new MakeOutcomeFailDependingOnOutput(
28 () =>
29 Q(AndroidPlatform.RUN_ANDROID_SUCCESS_PATTERNS),
30 () =>
31 Q(AndroidPlatform.RUN_ANDROID_FAILURE_PATTERNS)).process(runAndroidSpawn);
32 }
33
34 public enableJSDebuggingMode(runOptions: IRunOptions): Q.Promise<void> {
35 let pkg = new Package(runOptions.projectRoot);
36
37 return pkg.name()
38 .then(appName => new PackageNameResolver(appName).resolvePackageName(runOptions.projectRoot))
39 .then(packageName => {
40 let enableDebugCommand = `adb shell am broadcast -a "${packageName.toLowerCase()}.RELOAD_APP_ACTION" --ez jsproxy true`;
41 let cexec = new CommandExecutor(runOptions.projectRoot);
42 return cexec.execute(enableDebugCommand);
43 });
44 }
45}