2019-01-19 04:46:40 +07:00
|
|
|
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("not initialized");
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._homedir;
|
|
|
|
}
|
|
|
|
|
|
|
|
public tmpdir(): string {
|
|
|
|
if (typeof this._tmpdir === "undefined") {
|
|
|
|
throw new Error("not initialized");
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._tmpdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
public initialize(data: InitData): void {
|
|
|
|
this._homedir = data.homeDirectory;
|
|
|
|
this._tmpdir = data.tmpDirectory;
|
|
|
|
}
|
|
|
|
|
2019-01-29 00:14:06 +07:00
|
|
|
public platform(): NodeJS.Platform {
|
|
|
|
if (navigator.appVersion.indexOf("Win") != -1) {
|
|
|
|
return "win32";
|
|
|
|
}
|
|
|
|
if (navigator.appVersion.indexOf("Mac") != -1) {
|
|
|
|
return "darwin";
|
|
|
|
}
|
2019-02-06 07:08:48 +07:00
|
|
|
|
2019-01-29 00:14:06 +07:00
|
|
|
return "linux";
|
|
|
|
}
|
2019-01-19 04:46:40 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
export = new OS();
|