diff options
| author | Nate Sesti <sestinj@gmail.com> | 2023-07-19 00:33:50 -0700 | 
|---|---|---|
| committer | Nate Sesti <sestinj@gmail.com> | 2023-07-19 00:33:50 -0700 | 
| commit | 1b92180d4b7720bf1cf36dd63142760d421dabf8 (patch) | |
| tree | 26e25e005b06526267c2a140c1fbf1cbf822f066 /extension/src/util | |
| parent | 924a0c09259d25a4dfe62c0a626a9204df45daa9 (diff) | |
| parent | a7c57e1d1e4a0eff3e4b598f8bf0448ea6068353 (diff) | |
| download | sncontinue-1b92180d4b7720bf1cf36dd63142760d421dabf8.tar.gz sncontinue-1b92180d4b7720bf1cf36dd63142760d421dabf8.tar.bz2 sncontinue-1b92180d4b7720bf1cf36dd63142760d421dabf8.zip  | |
Merge branch 'main' into config-py
Diffstat (limited to 'extension/src/util')
| -rw-r--r-- | extension/src/util/messenger.ts | 10 | ||||
| -rw-r--r-- | extension/src/util/util.ts | 29 | 
2 files changed, 39 insertions, 0 deletions
diff --git a/extension/src/util/messenger.ts b/extension/src/util/messenger.ts index b1df161b..3044898e 100644 --- a/extension/src/util/messenger.ts +++ b/extension/src/util/messenger.ts @@ -16,6 +16,8 @@ export abstract class Messenger {    abstract onClose(callback: () => void): void; +  abstract onError(callback: () => void): void; +    abstract sendAndReceive(messageType: string, data: any): Promise<any>;  } @@ -26,6 +28,7 @@ export class WebsocketMessenger extends Messenger {    } = {};    private onOpenListeners: (() => void)[] = [];    private onCloseListeners: (() => void)[] = []; +  private onErrorListeners: (() => void)[] = [];    private serverUrl: string;    _newWebsocket(): WebSocket { @@ -43,6 +46,9 @@ export class WebsocketMessenger extends Messenger {      for (const listener of this.onCloseListeners) {        this.onClose(listener);      } +    for (const listener of this.onErrorListeners) { +      this.onError(listener); +    }      for (const messageType in this.onMessageListeners) {        for (const listener of this.onMessageListeners[messageType]) {          this.onMessageType(messageType, listener); @@ -151,4 +157,8 @@ export class WebsocketMessenger extends Messenger {    onClose(callback: () => void): void {      this.websocket.addEventListener("close", callback);    } + +  onError(callback: () => void): void { +    this.websocket.addEventListener("error", callback); +  }  } diff --git a/extension/src/util/util.ts b/extension/src/util/util.ts index d33593e1..dfc10c90 100644 --- a/extension/src/util/util.ts +++ b/extension/src/util/util.ts @@ -1,5 +1,6 @@  import { RangeInFile, SerializedDebugContext } from "../client";  import * as fs from "fs"; +const os = require("os");  function charIsEscapedAtIndex(index: number, str: string): boolean {    if (index === 0) return false; @@ -113,3 +114,31 @@ export function debounced(delay: number, fn: Function) {      }, delay);    };  } + +type Platform = "mac" | "linux" | "windows" | "unknown"; + +function getPlatform(): Platform { +  const platform = os.platform(); +  if (platform === "darwin") { +    return "mac"; +  } else if (platform === "linux") { +    return "linux"; +  } else if (platform === "win32") { +    return "windows"; +  } else { +    return "unknown"; +  } +} + +export function getMetaKeyLabel() { +  const platform = getPlatform(); +  switch (platform) { +    case "mac": +      return "⌘"; +    case "linux": +    case "windows": +      return "^"; +    default: +      return "⌘"; +  } +}  | 
