From cdaf61edab9ac5f87f84d88edfb8611fc6ce67cf Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 15 Jun 2022 08:31:56 +0200 Subject: [PATCH] :lipstick: --- .../notification/common/notification.ts | 3 +- .../storage/browser/storageService.ts | 5 +- src/vs/platform/storage/common/storage.ts | 46 +++++++++++++++---- src/vs/platform/storage/common/storageIpc.ts | 4 +- .../electron-main/storageMainService.ts | 2 +- .../experiments/common/experimentService.ts | 4 +- .../common/notificationService.ts | 2 +- 7 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/vs/platform/notification/common/notification.ts b/src/vs/platform/notification/common/notification.ts index 5c4fa815ab7..612aa179426 100644 --- a/src/vs/platform/notification/common/notification.ts +++ b/src/vs/platform/notification/common/notification.ts @@ -72,7 +72,8 @@ export interface INeverShowAgainOptions { /** * Whether to persist the choice in the current workspace or for all workspaces. By - * default it will be persisted for all workspaces (= `NeverShowAgainScope.GLOBAL`). + * default it will be persisted for all workspaces across all profiles + * (= `NeverShowAgainScope.APPLICATION`). */ readonly scope?: NeverShowAgainScope; } diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts index be5d10fce81..677e3ca90aa 100644 --- a/src/vs/platform/storage/browser/storageService.ts +++ b/src/vs/platform/storage/browser/storageService.ts @@ -64,8 +64,11 @@ export class BrowserStorageService extends AbstractStorageService { const promises: Promise[] = []; promises.push(IndexedDBStorageDatabase.create({ id: this.getId(StorageScope.APPLICATION), broadcastChanges: true }, this.logService)); promises.push(IndexedDBStorageDatabase.create({ id: this.getId(StorageScope.WORKSPACE) }, this.logService)); - // Create global storage only if the current profile is not a default profie otherwise we use the application storage if (!this.userDataProfileService.currentProfile.isDefault) { + + // Create global storage only if the current profile is not a + // default profie otherwise we use the application storage + promises.push(IndexedDBStorageDatabase.create({ id: this.getId(StorageScope.GLOBAL), broadcastChanges: true }, this.logService)); } const [applicationStorageDatabase, workspaceStorageDatabase, globalStorageDatabase] = await Promises.settled(promises); diff --git a/src/vs/platform/storage/common/storage.ts b/src/vs/platform/storage/common/storage.ts index ececf161093..9061792183d 100644 --- a/src/vs/platform/storage/common/storage.ts +++ b/src/vs/platform/storage/common/storage.ts @@ -31,7 +31,7 @@ export enum WillSaveStateReason { } export interface IWillSaveStateEvent { - reason: WillSaveStateReason; + readonly reason: WillSaveStateReason; } export interface IStorageService { @@ -522,12 +522,15 @@ export abstract class AbstractStorageService extends Disposable implements IStor } async logStorage(): Promise { + const applicationItems = this.getStorage(StorageScope.APPLICATION)?.items ?? new Map(); const globalItems = this.getStorage(StorageScope.GLOBAL)?.items ?? new Map(); const workspaceItems = this.getStorage(StorageScope.WORKSPACE)?.items ?? new Map(); return logStorage( + applicationItems, globalItems, workspaceItems, + this.getLogDetails(StorageScope.APPLICATION) ?? '', this.getLogDetails(StorageScope.GLOBAL) ?? '', this.getLogDetails(StorageScope.WORKSPACE) ?? '' ); @@ -553,9 +556,9 @@ export class InMemoryStorageService extends AbstractStorageService { constructor() { super(); - this._register(this.applicationStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.APPLICATION, key))); - this._register(this.globalStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.GLOBAL, key))); this._register(this.workspaceStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.WORKSPACE, key))); + this._register(this.globalStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.GLOBAL, key))); + this._register(this.applicationStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.APPLICATION, key))); } protected getStorage(scope: StorageScope): IStorage { @@ -587,7 +590,7 @@ export class InMemoryStorageService extends AbstractStorageService { } } -export async function logStorage(global: Map, workspace: Map, globalPath: string, workspacePath: string): Promise { +export async function logStorage(application: Map, global: Map, workspace: Map, applicationPath: string, globalPath: string, workspacePath: string): Promise { const safeParse = (value: string) => { try { return JSON.parse(value); @@ -596,6 +599,13 @@ export async function logStorage(global: Map, workspace: Map(); + const applicationItemsParsed = new Map(); + application.forEach((value, key) => { + applicationItems.set(key, value); + applicationItemsParsed.set(key, safeParse(value)); + }); + const globalItems = new Map(); const globalItemsParsed = new Map(); global.forEach((value, key) => { @@ -610,15 +620,31 @@ export async function logStorage(global: Map, workspace: Map { - globalValues.push({ key, value }); + if (applicationPath !== globalPath) { + console.group(`Storage: Application (path: ${applicationPath})`); + } else { + console.group(`Storage: Application & Global (path: ${applicationPath}, default profile)`); + } + const applicationValues: { key: string; value: string }[] = []; + applicationItems.forEach((value, key) => { + applicationValues.push({ key, value }); }); - console.table(globalValues); + console.table(applicationValues); console.groupEnd(); - console.log(globalItemsParsed); + console.log(applicationItemsParsed); + + if (applicationPath !== globalPath) { + console.group(`Storage: Global (path: ${globalPath}, profile specific)`); + const globalValues: { key: string; value: string }[] = []; + globalItems.forEach((value, key) => { + globalValues.push({ key, value }); + }); + console.table(globalValues); + console.groupEnd(); + + console.log(globalItemsParsed); + } console.group(`Storage: Workspace (path: ${workspacePath})`); const workspaceValues: { key: string; value: string }[] = []; diff --git a/src/vs/platform/storage/common/storageIpc.ts b/src/vs/platform/storage/common/storageIpc.ts index 41a1f23f68e..e61a2736999 100644 --- a/src/vs/platform/storage/common/storageIpc.ts +++ b/src/vs/platform/storage/common/storageIpc.ts @@ -24,8 +24,8 @@ export interface IBaseSerializableStorageRequest { readonly profile: IUserDataProfileDto | undefined; /** - * Workspace to correlate storage. Can be undefined to denote - * application or global scope depending on profile. + * Workspace to correlate storage. Can be undefined to + * denote application or global scope depending on profile. */ readonly workspace: ISerializedWorkspaceIdentifier | ISerializedSingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined; } diff --git a/src/vs/platform/storage/electron-main/storageMainService.ts b/src/vs/platform/storage/electron-main/storageMainService.ts index 64f0815e794..e1770742e7e 100644 --- a/src/vs/platform/storage/electron-main/storageMainService.ts +++ b/src/vs/platform/storage/electron-main/storageMainService.ts @@ -16,7 +16,7 @@ import { ApplicationStorageMain, GlobalStorageMain, InMemoryStorageMain, IStorag import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'; import { IAnyWorkspaceIdentifier, IEmptyWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace'; -//#region Storage Main Service (intent: make global and workspace storage accessible to windows from main process) +//#region Storage Main Service (intent: make application, global and workspace storage accessible to windows from main process) export const IStorageMainService = createDecorator('storageMainService'); diff --git a/src/vs/workbench/contrib/experiments/common/experimentService.ts b/src/vs/workbench/contrib/experiments/common/experimentService.ts index c66a550ef63..f6e71c6c793 100644 --- a/src/vs/workbench/contrib/experiments/common/experimentService.ts +++ b/src/vs/workbench/contrib/experiments/common/experimentService.ts @@ -19,7 +19,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' import { IProductService } from 'vs/platform/product/common/productService'; import { asJson, IRequestService } from 'vs/platform/request/common/request'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; -import { ITelemetryService, lastSessionDateStorageKey } from 'vs/platform/telemetry/common/telemetry'; +import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkspaceTagsService } from 'vs/workbench/contrib/tags/common/workspaceTags'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; @@ -483,7 +483,7 @@ export class ExperimentService extends Disposable implements IExperimentService return Promise.resolve(ExperimentState.NoRun); } - const isNewUser = !this.storageService.get(lastSessionDateStorageKey, StorageScope.APPLICATION); + const isNewUser = this.storageService.isNew(StorageScope.APPLICATION); if ((condition.newUser === true && !isNewUser) || (condition.newUser === false && isNewUser)) { return Promise.resolve(ExperimentState.NoRun); diff --git a/src/vs/workbench/services/notification/common/notificationService.ts b/src/vs/workbench/services/notification/common/notificationService.ts index f2af90db01e..f618b5e9ce0 100644 --- a/src/vs/workbench/services/notification/common/notificationService.ts +++ b/src/vs/workbench/services/notification/common/notificationService.ts @@ -151,7 +151,7 @@ export class NotificationService extends Disposable implements INotificationServ case NeverShowAgainScope.WORKSPACE: return StorageScope.WORKSPACE; default: - return StorageScope.GLOBAL; + return StorageScope.APPLICATION; } }