Throw errors if accessing paths before set
This commit is contained in:
@ -156,16 +156,10 @@ export class Client extends IdeClient {
|
||||
protected initialize(): Promise<void> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user