|
1 | 1 | import { readFile, writeFile } from "fs"; |
| 2 | +import * as path from "path"; |
2 | 3 | import { promisify } from "util"; |
| 4 | +import { IDisposable } from "@coder/disposable"; |
3 | 5 | 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"; |
5 | 10 |
|
6 | | -export class StorageDatabase implements storage.IStorageDatabase { |
| 11 | +export class StorageDatabase implements workspaceStorage.IStorageDatabase { |
7 | 12 |
|
8 | 13 | public readonly onDidChangeItemsExternal = Event.None; |
9 | 14 | private items = new Map<string, string>(); |
10 | 15 | private fetched: boolean = false; |
11 | 16 |
|
12 | 17 | public constructor(private readonly path: string) { |
| 18 | + path = path.replace(/\.vscdb$/, ".json"); |
| 19 | + logger.debug("Setting up storage", field("path", path)); |
13 | 20 | window.addEventListener("unload", () => { |
14 | 21 | if (!navigator.sendBeacon) { |
15 | 22 | throw new Error("cannot save state"); |
@@ -43,7 +50,7 @@ export class StorageDatabase implements storage.IStorageDatabase { |
43 | 50 | return this.items; |
44 | 51 | } |
45 | 52 |
|
46 | | - public updateItems(request: storage.IUpdateRequest): Promise<void> { |
| 53 | + public updateItems(request: workspaceStorage.IUpdateRequest): Promise<void> { |
47 | 54 | if (request.insert) { |
48 | 55 | request.insert.forEach((value, key) => this.items.set(key, value)); |
49 | 56 | } |
@@ -74,5 +81,19 @@ export class StorageDatabase implements storage.IStorageDatabase { |
74 | 81 |
|
75 | 82 | } |
76 | 83 |
|
| 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; |
77 | 98 | // @ts-ignore |
78 | | -storage.SQLiteStorageDatabase = StorageDatabase; |
| 99 | +globalStorage.GlobalStorageDatabaseChannelClient = GlobalStorageDatabase; |
0 commit comments