microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/common/extensionMessaging.ts
41lines · 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 {HostPlatform} from "./hostPlatform"; |
| 5 | import {Crypto} from "./node/crypto"; |
| 6 | |
| 7 | /** |
| 8 | * Defines the messages sent to the extension. |
| 9 | * Add new messages to this enum. |
| 10 | */ |
| 11 | export enum ExtensionMessage { |
| 12 | START_PACKAGER, |
| 13 | STOP_PACKAGER, |
| 14 | PREWARM_BUNDLE_CACHE, |
| 15 | START_MONITORING_LOGCAT, |
| 16 | STOP_MONITORING_LOGCAT, |
| 17 | SEND_TELEMETRY |
| 18 | } |
| 19 | |
| 20 | export interface MessageWithArguments { |
| 21 | message: ExtensionMessage; |
| 22 | args: any[]; |
| 23 | } |
| 24 | |
| 25 | export let ErrorMarker = "vscodereactnative-error-marker"; |
| 26 | |
| 27 | export class MessagingChannel { |
| 28 | constructor(private projectRootPath: string) { |
| 29 | // Nothing needed here |
| 30 | } |
| 31 | |
| 32 | public getPath(): string { |
| 33 | /* We need to use a different value for each VS Code window so the pipe names won't clash. |
| 34 | We create the pipe path hashing the user id + project root path so both client and server |
| 35 | will generate the same path, yet it's unique for each vs code instance */ |
| 36 | const userID = HostPlatform.getUserID(); |
| 37 | const uniqueSeed = `${userID}:${this.projectRootPath}`; |
| 38 | const hash = new Crypto().hash(uniqueSeed); |
| 39 | return HostPlatform.getPipePath(`vscode-reactnative-${hash}`); |
| 40 | } |
| 41 | } |
| 42 | |