microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
267aac11f942068130da1a6e532653fb460bc8b8

Branches

Tags

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

Clone

HTTPS

Download ZIP

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