Skip to content

Commit 15bfd15

Browse files
code-asherkylecarbs
authored andcommitted
Implement global storage database channel client
Since our channels don't actually go back to the server or anything like that. Could be something to look into though.
1 parent cba8196 commit 15bfd15

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

packages/vscode/src/fill/storageDatabase.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import { readFile, writeFile } from "fs";
2+
import * as path from "path";
23
import { promisify } from "util";
4+
import { IDisposable } from "@coder/disposable";
35
import { Event } from "vs/base/common/event";
4-
import * as storage from "vs/base/node/storage";
6+
import * as workspaceStorage from "vs/base/node/storage";
7+
import * as globalStorage from "vs/platform/storage/node/storageIpc";
8+
import * as paths from "./paths";
9+
import { logger, field } from "@coder/logger";
510

6-
export class StorageDatabase implements storage.IStorageDatabase {
11+
export class StorageDatabase implements workspaceStorage.IStorageDatabase {
712

813
public readonly onDidChangeItemsExternal = Event.None;
914
private items = new Map<string, string>();
1015
private fetched: boolean = false;
1116

1217
public constructor(private readonly path: string) {
18+
path = path.replace(/\.vscdb$/, ".json");
19+
logger.debug("Setting up storage", field("path", path));
1320
window.addEventListener("unload", () => {
1421
if (!navigator.sendBeacon) {
1522
throw new Error("cannot save state");
@@ -43,7 +50,7 @@ export class StorageDatabase implements storage.IStorageDatabase {
4350
return this.items;
4451
}
4552

46-
public updateItems(request: storage.IUpdateRequest): Promise<void> {
53+
public updateItems(request: workspaceStorage.IUpdateRequest): Promise<void> {
4754
if (request.insert) {
4855
request.insert.forEach((value, key) => this.items.set(key, value));
4956
}
@@ -74,5 +81,19 @@ export class StorageDatabase implements storage.IStorageDatabase {
7481

7582
}
7683

84+
export class GlobalStorageDatabase extends StorageDatabase implements IDisposable {
85+
86+
public constructor() {
87+
super(path.join(paths.getAppDataPath(), "globalStorage", "state.vscdb"));
88+
}
89+
90+
public dispose(): void {
91+
// Nothing to do.
92+
}
93+
94+
}
95+
96+
// @ts-ignore
97+
workspaceStorage.SQLiteStorageDatabase = StorageDatabase;
7798
// @ts-ignore
78-
storage.SQLiteStorageDatabase = StorageDatabase;
99+
globalStorage.GlobalStorageDatabaseChannelClient = GlobalStorageDatabase;

scripts/vscode.patch

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,13 @@ index 2bf7fe37d7..81cc668f12 100644
4747
}
4848
catch (err) {
4949
errorback(err);
50-
diff --git a/src/vs/platform/storage/node/storageService.ts b/src/vs/platform/storage/node/storageService.ts
51-
index 9e6a94bbd2..9e7f9cb595 100644
52-
--- a/src/vs/platform/storage/node/storageService.ts
53-
+++ b/src/vs/platform/storage/node/storageService.ts
54-
@@ -89,6 +89,9 @@ export class StorageService extends Disposable implements IStorageService {
55-
private initializeGlobalStorage(): Thenable<void> {
56-
mark('willInitGlobalStorage');
57-
58-
+ // TODO: shouldn't reject
59-
+ return Promise.reject(new Error("nope"));
60-
+
61-
return this.globalStorage.init().then(() => {
62-
mark('didInitGlobalStorage');
63-
}, error => {
64-
@@ -605,4 +608,4 @@ export class DelegatingStorageService extends Disposable implements IStorageServ
65-
private convertScope(scope: StorageScope): StorageLegacyScope {
66-
return scope === StorageScope.GLOBAL ? StorageLegacyScope.GLOBAL : StorageLegacyScope.WORKSPACE;
67-
}
68-
-}
69-
\ No newline at end of file
70-
+}
7150
diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts
7251
index a43d63aa51..4c6df2fcd9 100644
7352
--- a/src/vs/workbench/electron-browser/main.ts
7453
+++ b/src/vs/workbench/electron-browser/main.ts
7554
@@ -147,13 +147,14 @@ function openWorkbench(configuration: IWindowConfiguration): Promise<void> {
7655
shell.open();
77-
56+
7857
// Inform user about loading issues from the loader
7958
- (<any>self).require.config({
8059
- onError: err => {

0 commit comments

Comments
 (0)