microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/v-peq/removeNode10TodoComments

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/networkInspector/clientUtils.ts

76lines · 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
4/* eslint-disable */
5/* eslint-enable prettier/prettier*/
6
7import { ClientIdConstituents, ClientQuery } from "./clientDevice";
8import { OutputChannelLogger } from "../log/OutputChannelLogger";
9
10export enum ClientOS {
11 iOS = "iOS",
12 Android = "Android",
13 Windows = "Windows",
14 MacOS = "MacOS",
15}
16
17/**
18 * @preserve
19 * Start region: the code is borrowed from https://github.com/facebook/flipper/blob/v0.79.1/desktop/app/src/utils/clientUtils.tsx#L60-L78
20 *
21 * Copyright (c) Facebook, Inc. and its affiliates.
22 *
23 * This source code is licensed under the MIT license found in the
24 * LICENSE file in the root directory of this source tree.
25 *
26 * @format
27 */
28export function buildClientId(
29 clientInfo: {
30 app: string;
31 os: ClientOS;
32 device: string;
33 device_id: string;
34 },
35 logger: OutputChannelLogger,
36): string {
37 for (const key of ["app", "os", "device", "device_id"] as Array<keyof ClientIdConstituents>) {
38 if (!clientInfo[key]) {
39 logger.error(`Attempted to build clientId with invalid ${key}: "${clientInfo[key]}`);
40 }
41 }
42 const escapedName = escape(clientInfo.app);
43 return `${escapedName}#${clientInfo.os}#${clientInfo.device}#${clientInfo.device_id}`;
44}
45
46/**
47 * @preserve
48 * End region: https://github.com/facebook/flipper/blob/v0.79.1/desktop/app/src/utils/clientUtils.tsx#L60-L78
49 */
50
51/**
52 * @preserve
53 * Start region: the code is borrowed from https://github.com/facebook/flipper/blob/v0.79.1/desktop/app/src/server.tsx#L74-L83
54 *
55 * Copyright (c) Facebook, Inc. and its affiliates.
56 *
57 * This source code is licensed under the MIT license found in the
58 * LICENSE file in the root directory of this source tree.
59 *
60 * @format
61 */
62export function appNameWithUpdateHint(query: ClientQuery): string {
63 // in previous version (before 3), app may not appear in correct device
64 // section because it refers to the name given by client which is not fixed
65 // for android emulators, so it is indicated as outdated so that developers
66 // might want to update SDK to get rid of this connection swap problem
67 if (query.os === ClientOS.Android && (!query.sdk_version || query.sdk_version < 3)) {
68 return query.app + " (Outdated SDK)";
69 }
70 return query.app;
71}
72
73/**
74 * @preserve
75 * End region: https://github.com/facebook/flipper/blob/v0.79.1/desktop/app/src/server.tsx#L74-L83
76 */
77