mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-08 11:56:36 +00:00
Force default workspace on startup.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
bb9435b125
commit
aa770607de
@ -1,3 +1,4 @@
|
||||
import '../../src/browser/style/index.css';
|
||||
import { ContainerModule, interfaces } from 'inversify';
|
||||
import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
|
||||
import { CommandContribution } from '@theia/core/lib/common/command';
|
||||
@ -18,11 +19,11 @@ import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-fro
|
||||
import { WorkspaceServiceExt, WorkspaceServiceExtPath } from './workspace-service-ext';
|
||||
import { WorkspaceServiceExtImpl } from './workspace-service-ext-impl';
|
||||
import { ToolOutputServiceClient } from '../common/protocol/tool-output-service';
|
||||
|
||||
import '../../src/browser/style/index.css';
|
||||
import { ToolOutputService } from '../common/protocol/tool-output-service';
|
||||
import { ToolOutputServiceClientImpl } from './tool-output/client-service-impl';
|
||||
import { BoardsNotificationService } from './boards-notification-service';
|
||||
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
||||
import { AWorkspaceService } from './arduino-workspace-service';
|
||||
|
||||
export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
|
||||
// Commands and toolbar items
|
||||
@ -83,4 +84,6 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
|
||||
container.get(BoardsService);
|
||||
return workspaceServiceExt;
|
||||
});
|
||||
|
||||
rebind(WorkspaceService).to(AWorkspaceService).inSingletonScope();
|
||||
});
|
||||
|
@ -0,0 +1,33 @@
|
||||
import { WorkspaceService } from "@theia/workspace/lib/browser/workspace-service";
|
||||
import { injectable, inject } from "inversify";
|
||||
import { WorkspaceServer } from "@theia/workspace/lib/common";
|
||||
import { FileSystem } from "@theia/filesystem/lib/common";
|
||||
import URI from "@theia/core/lib/common/uri";
|
||||
|
||||
/**
|
||||
* This is workaround to have custom frontend binding for the default workspace, although we
|
||||
* already have a custom binding for the backend.
|
||||
*/
|
||||
@injectable()
|
||||
export class AWorkspaceService extends WorkspaceService {
|
||||
|
||||
@inject(WorkspaceServer)
|
||||
protected readonly workspaceServer: WorkspaceServer;
|
||||
|
||||
@inject(FileSystem)
|
||||
protected readonly fileSystem: FileSystem;
|
||||
|
||||
protected async getDefaultWorkspacePath(): Promise<string | undefined> {
|
||||
const result = await super.getDefaultWorkspacePath();
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
const userHome = await this.fileSystem.getCurrentUserHome();
|
||||
if (userHome) {
|
||||
// The backend has created this location if it was missing.
|
||||
return new URI(userHome.uri).resolve('Arduino-PoC').resolve('workspace').toString();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,8 @@ import { CoreClientProviderPath, CoreClientProvider } from './core-client-provid
|
||||
import { ToolOutputService, ToolOutputServiceClient, ToolOutputServiceServer } from '../common/protocol/tool-output-service';
|
||||
import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core';
|
||||
import { ToolOutputServiceServerImpl } from './tool-output-service-impl';
|
||||
import { DefaultWorkspaceServerExt } from './default-workspace-server-ext';
|
||||
import { WorkspaceServer } from '@theia/workspace/lib/common';
|
||||
|
||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
bind(ArduinoDaemon).toSelf().inSingletonScope();
|
||||
@ -77,4 +79,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
const parentLogger = ctx.container.get<ILogger>(ILogger);
|
||||
return parentLogger.child('daemon');
|
||||
}).inSingletonScope().whenTargetNamed('daemon');
|
||||
|
||||
// Default workspace server extension to initialize and use a fallback workspace (`~/Arduino-PoC/workspace/`)
|
||||
// If nothing was set previously.
|
||||
bind(DefaultWorkspaceServerExt).toSelf().inSingletonScope();
|
||||
rebind(WorkspaceServer).toService(DefaultWorkspaceServerExt);
|
||||
});
|
||||
|
@ -0,0 +1,37 @@
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs-extra';
|
||||
import { injectable } from 'inversify';
|
||||
import { FileUri } from '@theia/core/lib/node/file-uri';
|
||||
import { DefaultWorkspaceServer } from '@theia/workspace/lib/node/default-workspace-server';
|
||||
|
||||
@injectable()
|
||||
export class DefaultWorkspaceServerExt extends DefaultWorkspaceServer {
|
||||
|
||||
/**
|
||||
* Reads the most recently used workspace root from the user's home directory.
|
||||
*/
|
||||
// tslint:disable-next-line:no-any
|
||||
protected async readRecentWorkspacePathsFromUserHome(): Promise<any> {
|
||||
const paths = await super.readRecentWorkspacePathsFromUserHome();
|
||||
if (!paths || paths.recentRoots.length === 0) {
|
||||
const defaultWorkspacePath = path.resolve(os.homedir(), 'Arduino-PoC', 'workspace');
|
||||
if (!fs.existsSync(defaultWorkspacePath)) {
|
||||
fs.mkdirpSync(defaultWorkspacePath);
|
||||
}
|
||||
return {
|
||||
recentRoots: [
|
||||
FileUri.create(defaultWorkspacePath)
|
||||
]
|
||||
};
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
async getMostRecentlyUsedWorkspace(): Promise<string | undefined> {
|
||||
const result = await super.getMostRecentlyUsedWorkspace();
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user