]> git.lizzy.rs Git - rust.git/blob - editors/code/src/persistent_state.ts
Better releaseId naming
[rust.git] / editors / code / src / persistent_state.ts
1 import * as vscode from 'vscode';
2 import { log } from './util';
3
4 export class PersistentState {
5     constructor(private readonly globalState: vscode.Memento) {
6         const { lastCheck, nightlyReleaseId, serverVersion } = this;
7         log.info("PersistentState:", { lastCheck, nightlyReleaseId, serverVersion });
8     }
9
10     /**
11      * Used to check for *nightly* updates once an hour.
12      */
13     get lastCheck(): number | undefined {
14         return this.globalState.get("lastCheck");
15     }
16     async updateLastCheck(value: number) {
17         await this.globalState.update("lastCheck", value);
18     }
19
20     /**
21      * Release id of the *nightly* extension.
22      * Used to check if we should update.
23      */
24     get nightlyReleaseId(): number | undefined {
25         return this.globalState.get("releaseId");
26     }
27     async updateNightlyReleaseId(value: number) {
28         await this.globalState.update("releaseId", value);
29     }
30     async removeNightlyReleaseId() {
31         await this.globalState.update("releaseId", undefined);
32     }
33
34     /**
35      * Version of the extension that installed the server.
36      * Used to check if we need to update the server.
37      */
38     get serverVersion(): string | undefined {
39         return this.globalState.get("serverVersion");
40     }
41     async updateServerVersion(value: string | undefined) {
42         await this.globalState.update("serverVersion", value);
43     }
44
45     /**
46      * Github authorization token.
47      * This is used for API requests against the Github API.
48      */
49     get githubToken(): string | undefined {
50         return this.globalState.get("githubToken");
51     }
52     async updateGithubToken(value: string | undefined) {
53         await this.globalState.update("githubToken", value);
54     }
55 }