diff --git a/src/vs/platform/storage/node/storageService.ts b/src/vs/platform/storage/node/storageService.ts index 55bdea8422a2e966962c9612be65cbdeb067e571..24285b358405062c7a0e0aacbbc9e66d2d9eaff3 100644 --- a/src/vs/platform/storage/node/storageService.ts +++ b/src/vs/platform/storage/node/storageService.ts @@ -15,7 +15,7 @@ import { IWindowService } from 'vs/platform/windows/common/windows'; import { localize } from 'vs/nls'; import { mark, getDuration } from 'vs/base/common/performance'; import { join } from 'path'; -import { copy, exists, mkdirp, readdir } from 'vs/base/node/pfs'; +import { copy, exists, mkdirp, readdir, writeFile } from 'vs/base/node/pfs'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IWorkspaceInitializationPayload, isWorkspaceIdentifier, isSingleFolderWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces'; @@ -31,6 +31,7 @@ export class StorageService extends Disposable implements IStorageService { _serviceBrand: any; private static WORKSPACE_STORAGE_NAME = 'storage.db'; + private static WORKSPACE_META_NAME = 'workspace.json'; private _onDidChangeStorage: Emitter = this._register(new Emitter()); get onDidChangeStorage(): Event { return this._onDidChangeStorage.event; } @@ -300,10 +301,36 @@ export class StorageService extends Disposable implements IStorageService { return { path: workspaceStorageFolderPath, wasCreated: false }; } - return mkdirp(workspaceStorageFolderPath).then(() => ({ path: workspaceStorageFolderPath, wasCreated: true })); + return mkdirp(workspaceStorageFolderPath).then(() => { + + // Write metadata into folder + this.ensureWorkspaceStorageFolderMeta(payload); + + return { path: workspaceStorageFolderPath, wasCreated: true }; + }); }); } + private ensureWorkspaceStorageFolderMeta(payload: IWorkspaceInitializationPayload): void { + let meta: object; + if (isSingleFolderWorkspaceInitializationPayload(payload)) { + meta = { folder: payload.folder.toString() }; + } else if (isWorkspaceIdentifier(payload)) { + meta = { configuration: payload.configPath }; + } + + if (meta) { + const workspaceStorageMetaPath = join(this.getWorkspaceStorageFolderPath(payload), StorageService.WORKSPACE_META_NAME); + exists(workspaceStorageMetaPath).then(exists => { + if (exists) { + return void 0; // already existing + } + + return writeFile(workspaceStorageMetaPath, JSON.stringify(meta, void 0, 2)); + }).then(null, error => onUnexpectedError(error)); + } + } + get(key: string, scope: StorageScope, fallbackValue: string): string; get(key: string, scope: StorageScope): string | undefined; get(key: string, scope: StorageScope, fallbackValue?: string): string | undefined { diff --git a/src/vs/platform/workspaces/common/workspaces.ts b/src/vs/platform/workspaces/common/workspaces.ts index 55cb986751b7cef8d5dfee73e44f13711556afa5..31e0d076f35a29aba53ee0daa3c620999f73cba8 100644 --- a/src/vs/platform/workspaces/common/workspaces.ts +++ b/src/vs/platform/workspaces/common/workspaces.ts @@ -132,6 +132,7 @@ export function toWorkspaceIdentifier(workspace: IWorkspace): IWorkspaceIdentifi export type IMultiFolderWorkspaceInitializationPayload = IWorkspaceIdentifier; export interface ISingleFolderWorkspaceInitializationPayload { id: string; folder: ISingleFolderWorkspaceIdentifier; } export interface IEmptyWorkspaceInitializationPayload { id: string; } + export type IWorkspaceInitializationPayload = IMultiFolderWorkspaceInitializationPayload | ISingleFolderWorkspaceInitializationPayload | IEmptyWorkspaceInitializationPayload; export function isSingleFolderWorkspaceInitializationPayload(obj: any): obj is ISingleFolderWorkspaceInitializationPayload { diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index e47e7adb39985561649f9ae3a3212da6e8ad74b4..9b6df6381b26ad559df8bb14b4b075e521921d45 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -16,7 +16,7 @@ import { IWorkspaceContextService, Workspace, WorkbenchState } from 'vs/platform import { WorkspaceService } from 'vs/workbench/services/configuration/node/configurationService'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; -import { stat, exists, writeFile } from 'vs/base/node/pfs'; +import { stat } from 'vs/base/node/pfs'; import { EnvironmentService } from 'vs/platform/environment/node/environmentService'; import * as gracefulFs from 'graceful-fs'; import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron-browser/keybindingService'; @@ -44,7 +44,7 @@ import { MenubarChannelClient } from 'vs/platform/menubar/node/menubarIpc'; import { IMenubarService } from 'vs/platform/menubar/common/menubar'; import { Schemas } from 'vs/base/common/network'; import { sanitizeFilePath } from 'vs/base/node/extfs'; -import { basename, join } from 'path'; +import { basename } from 'path'; import { createHash } from 'crypto'; import { IdleValue } from 'vs/base/common/async'; import { setGlobalLeakWarningThreshold } from 'vs/base/common/event'; @@ -136,11 +136,6 @@ function openWorkbench(configuration: IWindowConfiguration): Promise { storageService }, mainServices, mainProcessClient, configuration); - // Store meta file in workspace storage after workbench is running - shell.onRunning(() => { - ensureWorkspaceStorageFolderMeta(payload, workspaceService, environmentService); - }); - // Gracefully Shutdown Storage shell.onShutdown(event => { event.join(storageService.close()); @@ -255,32 +250,6 @@ function createStorageService(payload: IWorkspaceInitializationPayload, environm }); } -function getWorkspaceStoragePath(payload: IWorkspaceInitializationPayload, environmentService: IEnvironmentService): string { - return join(environmentService.workspaceStorageHome, payload.id); // workspace home + workspace id; -} - -function ensureWorkspaceStorageFolderMeta(payload: IWorkspaceInitializationPayload, workspaceService: IWorkspaceContextService, environmentService: IEnvironmentService): void { - const state = workspaceService.getWorkbenchState(); - if (state === WorkbenchState.EMPTY) { - return; // no storage meta for empty workspaces - } - - const workspaceStorageMetaPath = join(getWorkspaceStoragePath(payload, environmentService), 'workspace.json'); - - exists(workspaceStorageMetaPath).then(exists => { - if (exists) { - return void 0; // already existing - } - - const workspace = workspaceService.getWorkspace(); - - return writeFile(workspaceStorageMetaPath, JSON.stringify({ - configuration: workspace.configuration ? uri.revive(workspace.configuration).toString() : void 0, - folder: state === WorkbenchState.FOLDER ? uri.revive(workspace.folders[0].uri).toString() : void 0 - }, undefined, 2)); - }).then(null, error => onUnexpectedError(error)); -} - function createStorageLegacyService(workspaceService: IWorkspaceContextService, environmentService: IEnvironmentService): IStorageLegacyService { let workspaceId: string; diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index 536a8931257ace737ac1fc67e87f1a7a2af24192..6ba68ff7d947e946327a31eb47ae801dfb1f368c 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -126,9 +126,6 @@ export class WorkbenchShell extends Disposable { private readonly _onShutdown = this._register(new Emitter()); get onShutdown(): Event { return this._onShutdown.event; } - private readonly _onRunning = this._register(new Emitter()); - get onRunning(): Event { return this._onRunning.event; } - private storageService: DelegatingStorageService; private environmentService: IEnvironmentService; private logService: ILogService; @@ -217,10 +214,8 @@ export class WorkbenchShell extends Disposable { // Startup Workbench workbench.startup().then(startupInfos => { - // Set lifecycle phase to `Runnning` so that other contributions can - // now do something we also emit this as event to interested parties outside + // Set lifecycle phase to `Runnning` this.lifecycleService.phase = LifecyclePhase.Running; - this._onRunning.fire(); // Startup Telemetry this.logStartupTelemetry(startupInfos);