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