diff --git a/packages/workspace/src/browser/workspace-storage-service.ts b/packages/workspace/src/browser/workspace-storage-service.ts index d02a288fce2a6..1288d3f5144ee 100644 --- a/packages/workspace/src/browser/workspace-storage-service.ts +++ b/packages/workspace/src/browser/workspace-storage-service.ts @@ -7,9 +7,10 @@ import { StorageService } from '@theia/core/lib/browser/storage-service'; import { WorkspaceService } from './workspace-service'; -import { inject, injectable } from 'inversify'; +import { inject, injectable, postConstruct } from 'inversify'; import { ILogger } from '@theia/core/lib/common'; import { LocalStorageService } from '@theia/core/lib/browser/storage-service'; +import URI from '@theia/core/lib/common/uri'; /* * Prefixes any stored data with the current workspace path. @@ -21,18 +22,24 @@ export class WorkspaceStorageService implements StorageService { private initialized: Promise; protected storageService: StorageService; - constructor( @inject(WorkspaceService) protected workspaceService: WorkspaceService, - @inject(ILogger) protected logger: ILogger) { - this.initialized = this.workspaceService.root.then(stat => { - if (stat) { - this.prefix = stat.uri; - } else { - this.prefix = '_global_'; - } - }); + @inject(WorkspaceService) + protected workspaceService: WorkspaceService; + + @inject(ILogger) + protected logger: ILogger; + + constructor() { this.storageService = new LocalStorageService(this.logger); } + @postConstruct() + protected async init(): Promise { + const statFile = await this.workspaceService.root; + const workspace = statFile ? new URI(statFile.uri).path : '_global_'; + this.prefix = `${window.location.pathname}:${workspace}`; + this.initialized = Promise.resolve(); + } + async setData(key: string, data: T): Promise { if (!this.prefix) { await this.initialized; diff --git a/packages/workspace/src/node/default-workspace-server.ts b/packages/workspace/src/node/default-workspace-server.ts index bbaff6530a646..e19a955d2b1f0 100644 --- a/packages/workspace/src/node/default-workspace-server.ts +++ b/packages/workspace/src/node/default-workspace-server.ts @@ -10,7 +10,7 @@ import * as yargs from 'yargs'; import * as fs from 'fs-extra'; import * as os from 'os'; -import { injectable, inject } from "inversify"; +import { injectable, inject, postConstruct } from "inversify"; import { FileUri } from '@theia/core/lib/node'; import { CliContribution } from '@theia/core/lib/node/cli'; import { Deferred } from '@theia/core/lib/common/promise-util'; @@ -20,6 +20,7 @@ import { WorkspaceServer } from "../common"; export class WorkspaceCliContribution implements CliContribution { workspaceRoot = new Deferred(); + domain?: string; configure(conf: yargs.Argv): void { conf.usage("$0 [workspace-directory] [options]"); @@ -29,6 +30,8 @@ export class WorkspaceCliContribution implements CliContribution { } setArguments(args: yargs.Arguments): void { + this.domain = args.domain; + let wsPath = args._[2]; if (!wsPath) { wsPath = args['root-dir']; @@ -50,18 +53,18 @@ export class DefaultWorkspaceServer implements WorkspaceServer { protected root: Promise; - constructor( - @inject(WorkspaceCliContribution) protected readonly cliParams: WorkspaceCliContribution - ) { + @inject(WorkspaceCliContribution) + protected readonly cliParams: WorkspaceCliContribution; + + @postConstruct() + protected async init(): Promise { this.root = this.getRootURIFromCli(); - this.root.then(async root => { - if (!root) { - const data = await this.readFromUserHome(); - if (data && data.recentRoots) { - this.root = Promise.resolve(data.recentRoots[0]); - } + if (!await this.root) { + const data = await this.readFromUserHome(); + if (data && data.recentRoots) { + this.root = Promise.resolve(data.recentRoots[0]); } - }); + } } getRoot(): Promise {