diff --git a/packages/ide/src/client.ts b/packages/ide/src/client.ts index c1cb3d74f..1c9b26f5c 100644 --- a/packages/ide/src/client.ts +++ b/packages/ide/src/client.ts @@ -1,5 +1,5 @@ import { field, logger, time, Time } from "@coder/logger"; -import { ISharedProcessData } from "@coder/protocol"; +import { SharedProcessData } from "@coder/protocol"; import { retry } from "./retry"; import { upload } from "./upload"; import { client } from "./fill/client"; @@ -25,7 +25,7 @@ export abstract class IdeClient { private readonly loadTime: Time; public readonly initData = client.initData; - public readonly sharedProcessData: Promise; + public readonly sharedProcessData: Promise; public readonly onSharedProcessActive = client.onSharedProcessActive; public constructor() { diff --git a/packages/protocol/src/browser/client.ts b/packages/protocol/src/browser/client.ts index 9fb8a6e6d..abbc5925a 100644 --- a/packages/protocol/src/browser/client.ts +++ b/packages/protocol/src/browser/client.ts @@ -1,4 +1,4 @@ -import { ReadWriteConnection, InitData, OperatingSystem, ISharedProcessData } from "../common/connection"; +import { ReadWriteConnection, InitData, OperatingSystem, SharedProcessData } from "../common/connection"; import { NewEvalMessage, ServerMessage, EvalDoneMessage, EvalFailedMessage, TypedValue, ClientMessage, NewSessionMessage, TTYDimensions, SessionOutputMessage, CloseSessionInputMessage, WorkingInitMessage, EvalEventMessage } from "../proto"; import { Emitter } from "@coder/events"; import { logger, field } from "@coder/logger"; @@ -30,7 +30,7 @@ export class Client { private readonly initDataEmitter = new Emitter(); private readonly initDataPromise: Promise; - private readonly sharedProcessActiveEmitter = new Emitter(); + private readonly sharedProcessActiveEmitter = new Emitter(); public readonly onSharedProcessActive = this.sharedProcessActiveEmitter.event; /** diff --git a/packages/protocol/src/common/connection.ts b/packages/protocol/src/common/connection.ts index c32f85a6a..06e255dc5 100644 --- a/packages/protocol/src/common/connection.ts +++ b/packages/protocol/src/common/connection.ts @@ -24,7 +24,7 @@ export interface InitData { readonly builtInExtensionsDirectory: string; } -export interface ISharedProcessData { +export interface SharedProcessData { readonly socketPath: string; readonly logPath: string; } diff --git a/packages/vscode/src/client.ts b/packages/vscode/src/client.ts index bddbb9630..6fb618186 100644 --- a/packages/vscode/src/client.ts +++ b/packages/vscode/src/client.ts @@ -156,16 +156,10 @@ export class Client extends IdeClient { protected initialize(): Promise { registerContextMenuListener(); - const pathSets = this.sharedProcessData.then((data) => { - paths._paths.socketPath = data.socketPath; - process.env.VSCODE_LOGS = data.logPath; - }); - this._clipboardContextKey = new RawContextKey("nativeClipboard", this.clipboard.isEnabled); - return this.task("Start workbench", 1000, async (data) => { - paths._paths.appData = data.dataDirectory; - paths._paths.defaultUserData = data.dataDirectory; + return this.task("Start workbench", 1000, async (data, sharedData) => { + paths._paths.initialize(data, sharedData); this._builtInExtensionsDirectory = data.builtInExtensionsDirectory; process.env.SHELL = data.shell; @@ -190,7 +184,7 @@ export class Client extends IdeClient { bounded.set(enabled); }); this.clipboard.initialize(); - }, this.initData, pathSets); + }, this.initData, this.sharedProcessData); } } diff --git a/packages/vscode/src/fill/paths.ts b/packages/vscode/src/fill/paths.ts index 01bcb353c..eff2472aa 100644 --- a/packages/vscode/src/fill/paths.ts +++ b/packages/vscode/src/fill/paths.ts @@ -1,8 +1,42 @@ -export const _paths = { - appData: "/tmp", - defaultUserData: "/tmp", - socketPath: "/tmp/vscode-remote.sock", -}; +import { InitData, SharedProcessData } from "@coder/protocol"; +class Paths { + private _appData: string | undefined; + private _defaultUserData: string | undefined; + private _socketPath: string | undefined; + + public get appData(): string { + if (typeof this._appData === "undefined") { + throw new Error("trying to access appData before it has been set"); + } + + return this._appData; + } + + public get defaultUserData(): string { + if (typeof this._defaultUserData === "undefined") { + throw new Error("trying to access defaultUserData before it has been set"); + } + + return this._defaultUserData; + } + + public get socketPath(): string { + if (typeof this._socketPath === "undefined") { + throw new Error("trying to access socketPath before it has been set"); + } + + return this._socketPath; + } + + public initialize(data: InitData, sharedData: SharedProcessData): void { + process.env.VSCODE_LOGS = sharedData.logPath; + this._appData = data.dataDirectory; + this._defaultUserData = data.dataDirectory; + this._socketPath = sharedData.socketPath; + } +} + +export const _paths = new Paths(); export const getAppDataPath = (): string => _paths.appData; export const getDefaultUserDataPath = (): string => _paths.defaultUserData;