From 276e91213eea325f689268e31be27049ee3651c8 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Tue, 18 Aug 2020 16:02:31 +0200 Subject: [PATCH 1/2] support isNew with global scope --- .../storage/browser/storageService.ts | 24 ++++++++++++------- src/vs/platform/storage/common/storage.ts | 7 +++--- .../storage/node/storageMainService.ts | 13 ++++++++-- .../platform/storage/node/storageService.ts | 18 +++++++------- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts index 59b1baf9120c..ab3fd347b69f 100644 --- a/src/vs/platform/storage/browser/storageService.ts +++ b/src/vs/platform/storage/browser/storageService.ts @@ -5,7 +5,7 @@ import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; import { Emitter } from 'vs/base/common/event'; -import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason, logStorage } from 'vs/platform/storage/common/storage'; +import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason, logStorage, IS_NEW_KEY } from 'vs/platform/storage/common/storage'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces'; import { IFileService, FileChangeType } from 'vs/platform/files/common/files'; @@ -20,8 +20,6 @@ export class BrowserStorageService extends Disposable implements IStorageService declare readonly _serviceBrand: undefined; - private static readonly WORKSPACE_IS_NEW_KEY = '__$__isNewStorageMarker'; - private readonly _onDidChangeStorage = this._register(new Emitter()); readonly onDidChangeStorage = this._onDidChangeStorage.event; @@ -82,12 +80,20 @@ export class BrowserStorageService extends Disposable implements IStorageService this.globalStorage.init() ]); - // Check to see if this is the first time we are "opening" this workspace - const firstOpen = this.workspaceStorage.getBoolean(BrowserStorageService.WORKSPACE_IS_NEW_KEY); + // Check to see if this is the first time we are "opening" the application + const firstOpen = this.globalStorage.getBoolean(IS_NEW_KEY); if (firstOpen === undefined) { - this.workspaceStorage.set(BrowserStorageService.WORKSPACE_IS_NEW_KEY, true); + this.globalStorage.set(IS_NEW_KEY, true); } else if (firstOpen) { - this.workspaceStorage.set(BrowserStorageService.WORKSPACE_IS_NEW_KEY, false); + this.globalStorage.set(IS_NEW_KEY, false); + } + + // Check to see if this is the first time we are "opening" this workspace + const firstWorkspaceOpen = this.workspaceStorage.getBoolean(IS_NEW_KEY); + if (firstWorkspaceOpen === undefined) { + this.workspaceStorage.set(IS_NEW_KEY, true); + } else if (firstWorkspaceOpen) { + this.workspaceStorage.set(IS_NEW_KEY, false); } // In the browser we do not have support for long running unload sequences. As such, @@ -189,8 +195,8 @@ export class BrowserStorageService extends Disposable implements IStorageService this.dispose(); } - isNew(scope: StorageScope.WORKSPACE): boolean { - return this.getBoolean(BrowserStorageService.WORKSPACE_IS_NEW_KEY, scope) === true; + isNew(scope: StorageScope): boolean { + return this.getBoolean(IS_NEW_KEY, scope) === true; } dispose(): void { diff --git a/src/vs/platform/storage/common/storage.ts b/src/vs/platform/storage/common/storage.ts index 1623957cb18e..52f9d10757a2 100644 --- a/src/vs/platform/storage/common/storage.ts +++ b/src/vs/platform/storage/common/storage.ts @@ -9,6 +9,8 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { isUndefinedOrNull } from 'vs/base/common/types'; import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces'; +export const IS_NEW_KEY = '__$__isNewStorageMarker'; + export const IStorageService = createDecorator('storageService'); export enum WillSaveStateReason { @@ -104,12 +106,11 @@ export interface IStorageService { migrate(toWorkspace: IWorkspaceInitializationPayload): Promise; /** - * Wether the storage for the given scope was created during this session or + * Whether the storage for the given scope was created during this session or * existed before. * - * Note: currently only implemented for `WORKSPACE` scope. */ - isNew(scope: StorageScope.WORKSPACE): boolean; + isNew(scope: StorageScope): boolean; /** * Allows to flush state, e.g. in cases where a shutdown is diff --git a/src/vs/platform/storage/node/storageMainService.ts b/src/vs/platform/storage/node/storageMainService.ts index 1abfd328ce66..564c052328cb 100644 --- a/src/vs/platform/storage/node/storageMainService.ts +++ b/src/vs/platform/storage/node/storageMainService.ts @@ -12,6 +12,7 @@ import { INativeEnvironmentService } from 'vs/platform/environment/node/environm import { SQLiteStorageDatabase, ISQLiteStorageDatabaseLoggingOptions } from 'vs/base/parts/storage/node/storage'; import { Storage, IStorage, InMemoryStorageDatabase } from 'vs/base/parts/storage/common/storage'; import { join } from 'vs/base/common/path'; +import { IS_NEW_KEY } from 'vs/platform/storage/common/storage'; export const IStorageMainService = createDecorator('storageMainService'); @@ -135,7 +136,7 @@ export class StorageMainService extends Disposable implements IStorageMainServic return this.initializePromise; } - private doInitialize(): Promise { + private async doInitialize(): Promise { this.storage.dispose(); this.storage = new Storage(new SQLiteStorageDatabase(this.storagePath, { logging: this.createLogginOptions() @@ -143,7 +144,15 @@ export class StorageMainService extends Disposable implements IStorageMainServic this._register(this.storage.onDidChangeStorage(key => this._onDidChangeStorage.fire({ key }))); - return this.storage.init(); + await this.storage.init(); + + // Check to see if this is the first time we are "opening" the application + const firstOpen = this.storage.getBoolean(IS_NEW_KEY); + if (firstOpen === undefined) { + await this.storage.set(IS_NEW_KEY, true); + } else if (firstOpen) { + await this.storage.set(IS_NEW_KEY, false); + } } get(key: string, fallbackValue: string): string; diff --git a/src/vs/platform/storage/node/storageService.ts b/src/vs/platform/storage/node/storageService.ts index 75514fe5a4fa..ac657056aa68 100644 --- a/src/vs/platform/storage/node/storageService.ts +++ b/src/vs/platform/storage/node/storageService.ts @@ -6,7 +6,7 @@ import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; import { Emitter } from 'vs/base/common/event'; import { ILogService, LogLevel } from 'vs/platform/log/common/log'; -import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason, logStorage } from 'vs/platform/storage/common/storage'; +import { IWorkspaceStorageChangeEvent, IStorageService, StorageScope, IWillSaveStateEvent, WillSaveStateReason, logStorage, IS_NEW_KEY } from 'vs/platform/storage/common/storage'; import { SQLiteStorageDatabase, ISQLiteStorageDatabaseLoggingOptions } from 'vs/base/parts/storage/node/storage'; import { Storage, IStorageDatabase, IStorage, StorageHint } from 'vs/base/parts/storage/common/storage'; import { mark } from 'vs/base/common/performance'; @@ -25,8 +25,6 @@ export class NativeStorageService extends Disposable implements IStorageService private static readonly WORKSPACE_STORAGE_NAME = 'state.vscdb'; private static readonly WORKSPACE_META_NAME = 'workspace.json'; - private static readonly WORKSPACE_IS_NEW_KEY = '__$__isNewStorageMarker'; - private readonly _onDidChangeStorage = this._register(new Emitter()); readonly onDidChangeStorage = this._onDidChangeStorage.event; @@ -108,11 +106,11 @@ export class NativeStorageService extends Disposable implements IStorageService await workspaceStorage.init(); // Check to see if this is the first time we are "opening" this workspace - const firstOpen = workspaceStorage.getBoolean(NativeStorageService.WORKSPACE_IS_NEW_KEY); - if (firstOpen === undefined) { - workspaceStorage.set(NativeStorageService.WORKSPACE_IS_NEW_KEY, result.wasCreated); - } else if (firstOpen) { - workspaceStorage.set(NativeStorageService.WORKSPACE_IS_NEW_KEY, false); + const firstWorkspaceOpen = workspaceStorage.getBoolean(IS_NEW_KEY); + if (firstWorkspaceOpen === undefined) { + workspaceStorage.set(IS_NEW_KEY, result.wasCreated); + } else if (firstWorkspaceOpen) { + workspaceStorage.set(IS_NEW_KEY, false); } } finally { mark('didInitWorkspaceStorage'); @@ -281,7 +279,7 @@ export class NativeStorageService extends Disposable implements IStorageService return this.createWorkspaceStorage(newWorkspaceStoragePath).init(); } - isNew(scope: StorageScope.WORKSPACE): boolean { - return this.getBoolean(NativeStorageService.WORKSPACE_IS_NEW_KEY, scope) === true; + isNew(scope: StorageScope): boolean { + return this.getBoolean(IS_NEW_KEY, scope) === true; } } From 89ba5a02d39806c817eaf785ced900a61d327587 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 19 Aug 2020 12:38:00 +0200 Subject: [PATCH 2/2] feedback: no need to wait --- src/vs/platform/storage/node/storageMainService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/storage/node/storageMainService.ts b/src/vs/platform/storage/node/storageMainService.ts index 564c052328cb..9ba93bb462ad 100644 --- a/src/vs/platform/storage/node/storageMainService.ts +++ b/src/vs/platform/storage/node/storageMainService.ts @@ -149,9 +149,9 @@ export class StorageMainService extends Disposable implements IStorageMainServic // Check to see if this is the first time we are "opening" the application const firstOpen = this.storage.getBoolean(IS_NEW_KEY); if (firstOpen === undefined) { - await this.storage.set(IS_NEW_KEY, true); + this.storage.set(IS_NEW_KEY, true); } else if (firstOpen) { - await this.storage.set(IS_NEW_KEY, false); + this.storage.set(IS_NEW_KEY, false); } }