code-server/packages/ide/src/fill/os.ts
Asher 588da0443c
Some cleanup
- Use whateverEmitter.event for the onWhatever methods.
- Add readonly to a bunch of things.
- Remove some redundancy in types.
- Move initializations out of the constructor and into the declarations
  where it was reasonable to do so.
- Disable a few no-any violations.
2019-02-06 11:53:23 -06:00

48 lines
968 B
TypeScript

import { InitData } from "@coder/protocol";
import { client } from "./client";
class OS {
private _homedir: string | undefined;
private _tmpdir: string | undefined;
public constructor() {
client.initData.then((data) => {
this.initialize(data);
});
}
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;
}
public platform(): NodeJS.Platform {
if (navigator.appVersion.indexOf("Win") != -1) {
return "win32";
}
if (navigator.appVersion.indexOf("Mac") != -1) {
return "darwin";
}
return "linux";
}
}
export = new OS();