Guard against no workspaces root.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2019-05-08 12:10:29 +02:00
committed by Christian Weichel
parent d8625ad9c3
commit bfb0edf50c
7 changed files with 98 additions and 17 deletions

View File

@@ -1,4 +1,6 @@
import { inject, injectable } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { FileSystem } from '@theia/filesystem/lib/common';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { WorkspaceServiceExt } from './workspace-service-ext';
@@ -8,6 +10,9 @@ import { WorkspaceServiceExt } from './workspace-service-ext';
@injectable()
export class WorkspaceServiceExtImpl implements WorkspaceServiceExt {
@inject(FileSystem)
protected readonly fileSystem: FileSystem;
@inject(WorkspaceService)
protected readonly delegate: WorkspaceService;
@@ -16,4 +21,27 @@ export class WorkspaceServiceExtImpl implements WorkspaceServiceExt {
return stats.map(stat => stat.uri);
}
}
async defaultWorkspaceUri(): Promise<string> {
const home = await this.fileSystem.getCurrentUserHome();
if (home) {
return new URI(home.uri).resolve('Arduino-PoC').resolve('workspace').toString();
}
throw new Error(`Could not locate current user's home folder.`);
}
async defaultDownloadsDirUri(): Promise<string> {
const home = await this.fileSystem.getCurrentUserHome();
if (home) {
return new URI(home.uri).resolve('Arduino-PoC').resolve('downloads').toString();
}
throw new Error(`Could not locate current user's home folder.`);
}
async defaultDataDirUri(): Promise<string> {
const home = await this.fileSystem.getCurrentUserHome();
if (home) {
return new URI(home.uri).resolve('Arduino-PoC').resolve('data').toString();
}
throw new Error(`Could not locate current user's home folder.`);
}
}

View File

@@ -2,4 +2,11 @@ export const WorkspaceServiceExtPath = '/services/workspace-service-ext';
export const WorkspaceServiceExt = Symbol('WorkspaceServiceExt');
export interface WorkspaceServiceExt {
roots(): Promise<string[]>;
/**
* By default it is under `~/Arduino-PoC/workspace`.
* It might not exist yet.
*/
defaultWorkspaceUri(): Promise<string>;
defaultDownloadsDirUri(): Promise<string>;
defaultDataDirUri(): Promise<string>;
}