From 15bfd157420704c2e9ae0607771f46c785fcd378 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 22 Jan 2019 14:54:51 -0600 Subject: [PATCH] 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. --- packages/vscode/src/fill/storageDatabase.ts | 29 ++++++++++++++++++--- scripts/vscode.patch | 23 +--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/vscode/src/fill/storageDatabase.ts b/packages/vscode/src/fill/storageDatabase.ts index d63ad5bf..1e947122 100644 --- a/packages/vscode/src/fill/storageDatabase.ts +++ b/packages/vscode/src/fill/storageDatabase.ts @@ -1,15 +1,22 @@ import { readFile, writeFile } from "fs"; +import * as path from "path"; import { promisify } from "util"; +import { IDisposable } from "@coder/disposable"; import { Event } from "vs/base/common/event"; -import * as storage from "vs/base/node/storage"; +import * as workspaceStorage from "vs/base/node/storage"; +import * as globalStorage from "vs/platform/storage/node/storageIpc"; +import * as paths from "./paths"; +import { logger, field } from "@coder/logger"; -export class StorageDatabase implements storage.IStorageDatabase { +export class StorageDatabase implements workspaceStorage.IStorageDatabase { public readonly onDidChangeItemsExternal = Event.None; private items = new Map(); private fetched: boolean = false; public constructor(private readonly path: string) { + path = path.replace(/\.vscdb$/, ".json"); + logger.debug("Setting up storage", field("path", path)); window.addEventListener("unload", () => { if (!navigator.sendBeacon) { throw new Error("cannot save state"); @@ -43,7 +50,7 @@ export class StorageDatabase implements storage.IStorageDatabase { return this.items; } - public updateItems(request: storage.IUpdateRequest): Promise { + public updateItems(request: workspaceStorage.IUpdateRequest): Promise { if (request.insert) { request.insert.forEach((value, key) => this.items.set(key, value)); } @@ -74,5 +81,19 @@ export class StorageDatabase implements storage.IStorageDatabase { } +export class GlobalStorageDatabase extends StorageDatabase implements IDisposable { + + public constructor() { + super(path.join(paths.getAppDataPath(), "globalStorage", "state.vscdb")); + } + + public dispose(): void { + // Nothing to do. + } + +} + // @ts-ignore -storage.SQLiteStorageDatabase = StorageDatabase; +workspaceStorage.SQLiteStorageDatabase = StorageDatabase; +// @ts-ignore +globalStorage.GlobalStorageDatabaseChannelClient = GlobalStorageDatabase; diff --git a/scripts/vscode.patch b/scripts/vscode.patch index 55801b30..9708b302 100644 --- a/scripts/vscode.patch +++ b/scripts/vscode.patch @@ -47,34 +47,13 @@ index 2bf7fe37d7..81cc668f12 100644 } catch (err) { errorback(err); -diff --git a/src/vs/platform/storage/node/storageService.ts b/src/vs/platform/storage/node/storageService.ts -index 9e6a94bbd2..9e7f9cb595 100644 ---- a/src/vs/platform/storage/node/storageService.ts -+++ b/src/vs/platform/storage/node/storageService.ts -@@ -89,6 +89,9 @@ export class StorageService extends Disposable implements IStorageService { - private initializeGlobalStorage(): Thenable { - mark('willInitGlobalStorage'); - -+ // TODO: shouldn't reject -+ return Promise.reject(new Error("nope")); -+ - return this.globalStorage.init().then(() => { - mark('didInitGlobalStorage'); - }, error => { -@@ -605,4 +608,4 @@ export class DelegatingStorageService extends Disposable implements IStorageServ - private convertScope(scope: StorageScope): StorageLegacyScope { - return scope === StorageScope.GLOBAL ? StorageLegacyScope.GLOBAL : StorageLegacyScope.WORKSPACE; - } --} -\ No newline at end of file -+} diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index a43d63aa51..4c6df2fcd9 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -147,13 +147,14 @@ function openWorkbench(configuration: IWindowConfiguration): Promise { shell.open(); - + // Inform user about loading issues from the loader - (self).require.config({ - onError: err => {