Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
Anmol Sethi 02f62882b8 Propagate full env to browser (#756)
* Propogate full env to browser

* Add support for setting $ITEM_URL

* Add serviceURL getter
2019-06-11 11:54:49 -05:00

58 lines
1.3 KiB
TypeScript

import { OperatingSystem, InitData } from "@coder/protocol";
import { client } from "./client";
class OS {
private _homedir: string | undefined;
private _tmpdir: string | undefined;
private _platform: NodeJS.Platform | undefined;
public constructor() {
client.initData.then((d) => this.initialize(d));
}
public homedir(): string {
if (typeof this._homedir === "undefined") {
throw new Error("trying to access homedir before it has been set");
}
return this._homedir;
}
public tmpdir(): string {
if (typeof this._tmpdir === "undefined") {
throw new Error("trying to access tmpdir before it has been set");
}
return this._tmpdir;
}
public initialize(data: InitData): void {
this._homedir = data.homeDirectory;
this._tmpdir = data.tmpDirectory;
switch (data.os) {
case OperatingSystem.Windows: this._platform = "win32"; break;
case OperatingSystem.Mac: this._platform = "darwin"; break;
default: this._platform = "linux"; break;
}
process.platform = this._platform;
process.env = {};
data.env.forEach((v, k) => {
process.env[k] = v;
});
}
public release(): string {
return "Unknown";
}
public platform(): NodeJS.Platform {
if (typeof this._platform === "undefined") {
throw new Error("trying to access platform before it has been set");
}
return this._platform;
}
}
export = new OS();