aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/persistent_state.ts
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-17 11:44:31 +0000
committerAleksey Kladov <[email protected]>2020-03-19 08:04:59 +0000
commitfb6e655de8a44c65275ad45a27bf5bd684670ba0 (patch)
tree9c307ac69c8fc59465ee2fb6f9a8a619fc064167 /editors/code/src/persistent_state.ts
parentf0a1b64d7ee3baa7ccf980b35b85f0a4a3b85b1a (diff)
Rewrite auto-update
Everything now happens in main.ts, in the bootstrap family of functions. The current flow is: * check everything only on extension installation. * if the user is on nightly channel, try to download the nightly extension and reload. * when we install nightly extension, we persist its release id, so that we can check if the current release is different. * if server binary was not downloaded by the current version of the extension, redownload it (we persist the version of ext that downloaded the server).
Diffstat (limited to 'editors/code/src/persistent_state.ts')
-rw-r--r--editors/code/src/persistent_state.ts64
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 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import { log } from "./util"; 2import { log } from './util';
3 3
4export class PersistentState { 4export 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
17export 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}
34export 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}