Merge pull request #104933 from microsoft/sandy081/globalIsNew

support isNew with global scope
This commit is contained in:
Sandeep Somavarapu
2020-08-19 12:38:36 +02:00
committed by GitHub
4 changed files with 38 additions and 24 deletions
@@ -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<IWorkspaceStorageChangeEvent>());
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 {
+4 -3
View File
@@ -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<IStorageService>('storageService');
export enum WillSaveStateReason {
@@ -104,12 +106,11 @@ export interface IStorageService {
migrate(toWorkspace: IWorkspaceInitializationPayload): Promise<void>;
/**
* 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
@@ -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<IStorageMainService>('storageMainService');
@@ -135,7 +136,7 @@ export class StorageMainService extends Disposable implements IStorageMainServic
return this.initializePromise;
}
private doInitialize(): Promise<void> {
private async doInitialize(): Promise<void> {
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) {
this.storage.set(IS_NEW_KEY, true);
} else if (firstOpen) {
this.storage.set(IS_NEW_KEY, false);
}
}
get(key: string, fallbackValue: string): string;
+8 -10
View File
@@ -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<IWorkspaceStorageChangeEvent>());
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;
}
}