diff options
Diffstat (limited to 'editors/code/src/persistent_state.ts')
-rw-r--r-- | editors/code/src/persistent_state.ts | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/editors/code/src/persistent_state.ts b/editors/code/src/persistent_state.ts index 13095b806..138d11b89 100644 --- a/editors/code/src/persistent_state.ts +++ b/editors/code/src/persistent_state.ts | |||
@@ -1,49 +1,41 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import { log } from "./util"; | 2 | import { log } from './util'; |
3 | 3 | ||
4 | export class PersistentState { | 4 | export class PersistentState { |
5 | constructor(private readonly ctx: vscode.ExtensionContext) { | 5 | constructor(private readonly globalState: vscode.Memento) { |
6 | const { lastCheck, releaseId, serverVersion } = this; | ||
7 | log.debug("PersistentState: ", { lastCheck, releaseId, serverVersion }); | ||
6 | } | 8 | } |
7 | 9 | ||
8 | readonly installedNightlyExtensionReleaseDate = new DateStorage( | 10 | /** |
9 | "installed-nightly-extension-release-date", | 11 | * Used to check for *nightly* updates once an hour. |
10 | this.ctx.globalState | 12 | */ |
11 | ); | 13 | get lastCheck(): number | undefined { |
12 | readonly serverReleaseDate = new DateStorage("server-release-date", this.ctx.globalState); | 14 | return this.globalState.get("lastCheck"); |
13 | readonly serverReleaseTag = new Storage<null | string>("server-release-tag", this.ctx.globalState, null); | ||
14 | } | ||
15 | |||
16 | |||
17 | export class Storage<T> { | ||
18 | constructor( | ||
19 | private readonly key: string, | ||
20 | private readonly storage: vscode.Memento, | ||
21 | private readonly defaultVal: T | ||
22 | ) { } | ||
23 | |||
24 | get(): T { | ||
25 | const val = this.storage.get(this.key, this.defaultVal); | ||
26 | log.debug(this.key, "==", val); | ||
27 | return val; | ||
28 | } | 15 | } |
29 | async set(val: T) { | 16 | async updateLastCheck(value: number) { |
30 | log.debug(this.key, "=", val); | 17 | await this.globalState.update("lastCheck", value); |
31 | await this.storage.update(this.key, val); | ||
32 | } | 18 | } |
33 | } | ||
34 | export class DateStorage { | ||
35 | inner: Storage<null | string>; | ||
36 | 19 | ||
37 | constructor(key: string, storage: vscode.Memento) { | 20 | /** |
38 | this.inner = new Storage(key, storage, null); | 21 | * Release id of the *nightly* extension. |
22 | * Used to check if we should update. | ||
23 | */ | ||
24 | get releaseId(): number | undefined { | ||
25 | return this.globalState.get("releaseId"); | ||
39 | } | 26 | } |
40 | 27 | async updateReleaseId(value: number) { | |
41 | get(): null | Date { | 28 | await this.globalState.update("releaseId", value); |
42 | const dateStr = this.inner.get(); | ||
43 | return dateStr ? new Date(dateStr) : null; | ||
44 | } | 29 | } |
45 | 30 | ||
46 | async set(date: null | Date) { | 31 | /** |
47 | await this.inner.set(date ? date.toString() : null); | 32 | * Version of the extension that installed the server. |
33 | * Used to check if we need to update the server. | ||
34 | */ | ||
35 | get serverVersion(): string | undefined { | ||
36 | return this.globalState.get("serverVersion"); | ||
37 | } | ||
38 | async updateServerVersion(value: string | undefined) { | ||
39 | await this.globalState.update("serverVersion", value); | ||
48 | } | 40 | } |
49 | } | 41 | } |