2020-03-16 19:23:38 +01:00
|
|
|
import * as vscode from 'vscode';
|
2020-03-17 12:44:31 +01:00
|
|
|
import { log } from './util';
|
2020-03-16 19:23:38 +01:00
|
|
|
|
|
|
|
|
export class PersistentState {
|
2020-03-17 12:44:31 +01:00
|
|
|
constructor(private readonly globalState: vscode.Memento) {
|
|
|
|
|
const { lastCheck, releaseId, serverVersion } = this;
|
2020-07-05 17:42:52 +03:00
|
|
|
log.info("PersistentState:", { lastCheck, releaseId, serverVersion });
|
2020-03-16 19:23:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-17 12:44:31 +01:00
|
|
|
/**
|
|
|
|
|
* Used to check for *nightly* updates once an hour.
|
|
|
|
|
*/
|
|
|
|
|
get lastCheck(): number | undefined {
|
|
|
|
|
return this.globalState.get("lastCheck");
|
2020-03-16 19:23:38 +01:00
|
|
|
}
|
2020-03-17 12:44:31 +01:00
|
|
|
async updateLastCheck(value: number) {
|
|
|
|
|
await this.globalState.update("lastCheck", value);
|
2020-03-16 19:23:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-17 12:44:31 +01:00
|
|
|
/**
|
|
|
|
|
* Release id of the *nightly* extension.
|
|
|
|
|
* Used to check if we should update.
|
|
|
|
|
*/
|
|
|
|
|
get releaseId(): number | undefined {
|
|
|
|
|
return this.globalState.get("releaseId");
|
2020-03-16 19:23:38 +01:00
|
|
|
}
|
2020-03-17 12:44:31 +01:00
|
|
|
async updateReleaseId(value: number) {
|
|
|
|
|
await this.globalState.update("releaseId", value);
|
2020-03-16 19:23:38 +01:00
|
|
|
}
|
2021-05-23 11:49:34 +03:00
|
|
|
async removeReleaseId() {
|
|
|
|
|
await this.globalState.update("releaseId", undefined);
|
|
|
|
|
}
|
2020-03-16 19:23:38 +01:00
|
|
|
|
2020-03-17 12:44:31 +01:00
|
|
|
/**
|
|
|
|
|
* Version of the extension that installed the server.
|
|
|
|
|
* Used to check if we need to update the server.
|
|
|
|
|
*/
|
|
|
|
|
get serverVersion(): string | undefined {
|
|
|
|
|
return this.globalState.get("serverVersion");
|
|
|
|
|
}
|
|
|
|
|
async updateServerVersion(value: string | undefined) {
|
|
|
|
|
await this.globalState.update("serverVersion", value);
|
2020-03-16 19:23:38 +01:00
|
|
|
}
|
2020-09-22 23:12:51 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Github authorization token.
|
|
|
|
|
* This is used for API requests against the Github API.
|
|
|
|
|
*/
|
|
|
|
|
get githubToken(): string | undefined {
|
|
|
|
|
return this.globalState.get("githubToken");
|
|
|
|
|
}
|
|
|
|
|
async updateGithubToken(value: string | undefined) {
|
|
|
|
|
await this.globalState.update("githubToken", value);
|
|
|
|
|
}
|
2020-03-16 19:23:38 +01:00
|
|
|
}
|