Skip to content

Commit aa77060

Browse files
Akos KittaChristian Weichel
Akos Kitta
authored and
Christian Weichel
committed
Force default workspace on startup.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent bb9435b commit aa77060

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

arduino-ide-extension/src/browser/arduino-frontend-module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../../src/browser/style/index.css';
12
import { ContainerModule, interfaces } from 'inversify';
23
import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
34
import { CommandContribution } from '@theia/core/lib/common/command';
@@ -18,11 +19,11 @@ import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-fro
1819
import { WorkspaceServiceExt, WorkspaceServiceExtPath } from './workspace-service-ext';
1920
import { WorkspaceServiceExtImpl } from './workspace-service-ext-impl';
2021
import { ToolOutputServiceClient } from '../common/protocol/tool-output-service';
21-
22-
import '../../src/browser/style/index.css';
2322
import { ToolOutputService } from '../common/protocol/tool-output-service';
2423
import { ToolOutputServiceClientImpl } from './tool-output/client-service-impl';
2524
import { BoardsNotificationService } from './boards-notification-service';
25+
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
26+
import { AWorkspaceService } from './arduino-workspace-service';
2627

2728
export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
2829
// Commands and toolbar items
@@ -83,4 +84,6 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
8384
container.get(BoardsService);
8485
return workspaceServiceExt;
8586
});
87+
88+
rebind(WorkspaceService).to(AWorkspaceService).inSingletonScope();
8689
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { WorkspaceService } from "@theia/workspace/lib/browser/workspace-service";
2+
import { injectable, inject } from "inversify";
3+
import { WorkspaceServer } from "@theia/workspace/lib/common";
4+
import { FileSystem } from "@theia/filesystem/lib/common";
5+
import URI from "@theia/core/lib/common/uri";
6+
7+
/**
8+
* This is workaround to have custom frontend binding for the default workspace, although we
9+
* already have a custom binding for the backend.
10+
*/
11+
@injectable()
12+
export class AWorkspaceService extends WorkspaceService {
13+
14+
@inject(WorkspaceServer)
15+
protected readonly workspaceServer: WorkspaceServer;
16+
17+
@inject(FileSystem)
18+
protected readonly fileSystem: FileSystem;
19+
20+
protected async getDefaultWorkspacePath(): Promise<string | undefined> {
21+
const result = await super.getDefaultWorkspacePath();
22+
if (result) {
23+
return result;
24+
}
25+
const userHome = await this.fileSystem.getCurrentUserHome();
26+
if (userHome) {
27+
// The backend has created this location if it was missing.
28+
return new URI(userHome.uri).resolve('Arduino-PoC').resolve('workspace').toString();
29+
}
30+
return undefined;
31+
}
32+
33+
}

arduino-ide-extension/src/node/arduino-backend-module.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { CoreClientProviderPath, CoreClientProvider } from './core-client-provid
1515
import { ToolOutputService, ToolOutputServiceClient, ToolOutputServiceServer } from '../common/protocol/tool-output-service';
1616
import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core';
1717
import { ToolOutputServiceServerImpl } from './tool-output-service-impl';
18+
import { DefaultWorkspaceServerExt } from './default-workspace-server-ext';
19+
import { WorkspaceServer } from '@theia/workspace/lib/common';
1820

1921
export default new ContainerModule((bind, unbind, isBound, rebind) => {
2022
bind(ArduinoDaemon).toSelf().inSingletonScope();
@@ -77,4 +79,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
7779
const parentLogger = ctx.container.get<ILogger>(ILogger);
7880
return parentLogger.child('daemon');
7981
}).inSingletonScope().whenTargetNamed('daemon');
82+
83+
// Default workspace server extension to initialize and use a fallback workspace (`~/Arduino-PoC/workspace/`)
84+
// If nothing was set previously.
85+
bind(DefaultWorkspaceServerExt).toSelf().inSingletonScope();
86+
rebind(WorkspaceServer).toService(DefaultWorkspaceServerExt);
8087
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as os from 'os';
2+
import * as path from 'path';
3+
import * as fs from 'fs-extra';
4+
import { injectable } from 'inversify';
5+
import { FileUri } from '@theia/core/lib/node/file-uri';
6+
import { DefaultWorkspaceServer } from '@theia/workspace/lib/node/default-workspace-server';
7+
8+
@injectable()
9+
export class DefaultWorkspaceServerExt extends DefaultWorkspaceServer {
10+
11+
/**
12+
* Reads the most recently used workspace root from the user's home directory.
13+
*/
14+
// tslint:disable-next-line:no-any
15+
protected async readRecentWorkspacePathsFromUserHome(): Promise<any> {
16+
const paths = await super.readRecentWorkspacePathsFromUserHome();
17+
if (!paths || paths.recentRoots.length === 0) {
18+
const defaultWorkspacePath = path.resolve(os.homedir(), 'Arduino-PoC', 'workspace');
19+
if (!fs.existsSync(defaultWorkspacePath)) {
20+
fs.mkdirpSync(defaultWorkspacePath);
21+
}
22+
return {
23+
recentRoots: [
24+
FileUri.create(defaultWorkspacePath)
25+
]
26+
};
27+
}
28+
return paths;
29+
}
30+
31+
async getMostRecentlyUsedWorkspace(): Promise<string | undefined> {
32+
const result = await super.getMostRecentlyUsedWorkspace();
33+
console.log(result);
34+
return result;
35+
}
36+
37+
}

0 commit comments

Comments
 (0)