mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-09 02:18:32 +00:00
IDE2 falls back to a new sketch if the opening fails. Closes #1089 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
@@ -4,7 +4,7 @@ import { CommandService } from '@theia/core/lib/common/command';
|
||||
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
||||
import { FrontendApplication as TheiaFrontendApplication } from '@theia/core/lib/browser/frontend-application';
|
||||
import { SketchesService } from '../../../common/protocol';
|
||||
import { ArduinoCommands } from '../../arduino-commands';
|
||||
import { OpenSketchFiles } from '../../contributions/open-sketch-files';
|
||||
|
||||
@injectable()
|
||||
export class FrontendApplication extends TheiaFrontendApplication {
|
||||
@@ -25,33 +25,11 @@ export class FrontendApplication extends TheiaFrontendApplication {
|
||||
this.workspaceService.roots.then(async (roots) => {
|
||||
for (const root of roots) {
|
||||
await this.commandService.executeCommand(
|
||||
ArduinoCommands.OPEN_SKETCH_FILES.id,
|
||||
OpenSketchFiles.Commands.OPEN_SKETCH_FILES.id,
|
||||
root.resource
|
||||
);
|
||||
this.sketchesService.markAsRecentlyOpened(root.resource.toString()); // no await, will get the notification later and rebuild the menu
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override getStartupIndicator(
|
||||
host: HTMLElement
|
||||
): HTMLElement | undefined {
|
||||
let startupElement = this.doGetStartupIndicator(host, 'old-theia-preload'); // https://github.com/eclipse-theia/theia/pull/10761#issuecomment-1131476318
|
||||
if (!startupElement) {
|
||||
startupElement = this.doGetStartupIndicator(host, 'theia-preload'); // We show the new Theia spinner in dev mode.
|
||||
}
|
||||
return startupElement;
|
||||
}
|
||||
|
||||
private doGetStartupIndicator(
|
||||
host: HTMLElement,
|
||||
classNames: string
|
||||
): HTMLElement | undefined {
|
||||
const elements = host.getElementsByClassName(classNames);
|
||||
const first = elements[0];
|
||||
if (first instanceof HTMLElement) {
|
||||
return first;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,11 @@ import {
|
||||
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
|
||||
import { BoardsConfig } from '../../boards/boards-config';
|
||||
import { FileStat } from '@theia/filesystem/lib/common/files';
|
||||
import { StartupTask } from '../../widgets/sketchbook/startup-task';
|
||||
import {
|
||||
StartupTask,
|
||||
StartupTasks,
|
||||
} from '../../widgets/sketchbook/startup-task';
|
||||
import { setURL } from '../../utils/window';
|
||||
|
||||
@injectable()
|
||||
export class WorkspaceService extends TheiaWorkspaceService {
|
||||
@@ -60,6 +64,17 @@ export class WorkspaceService extends TheiaWorkspaceService {
|
||||
this.onCurrentWidgetChange({ newValue, oldValue: null });
|
||||
}
|
||||
|
||||
protected override async toFileStat(
|
||||
uri: string | URI | undefined
|
||||
): Promise<FileStat | undefined> {
|
||||
const stat = await super.toFileStat(uri);
|
||||
if (!stat) {
|
||||
const newSketchUri = await this.sketchService.createNewSketch();
|
||||
return this.toFileStat(newSketchUri.uri);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
// Was copied from the Theia implementation.
|
||||
// Unlike the default behavior, IDE2 does not check the existence of the workspace before open.
|
||||
protected override async doGetDefaultWorkspaceUri(): Promise<
|
||||
@@ -78,6 +93,7 @@ export class WorkspaceService extends TheiaWorkspaceService {
|
||||
const wpPath = decodeURI(window.location.hash.substring(1));
|
||||
const workspaceUri = new URI().withPath(wpPath).withScheme('file');
|
||||
// ### Customization! Here, we do no check if the workspace exists.
|
||||
// ### The error or missing sketch handling is done in the customized `toFileStat`.
|
||||
return workspaceUri.toString();
|
||||
} else {
|
||||
// Else, ask the server for its suggested workspace (usually the one
|
||||
@@ -127,7 +143,7 @@ export class WorkspaceService extends TheiaWorkspaceService {
|
||||
protected override openWindow(uri: FileStat, options?: WorkspaceInput): void {
|
||||
const workspacePath = uri.resource.path.toString();
|
||||
if (this.shouldPreserveWindow(options)) {
|
||||
this.reloadWindow();
|
||||
this.reloadWindow(options); // Unlike Theia, IDE2 passes the `input` downstream.
|
||||
} else {
|
||||
try {
|
||||
this.openNewWindow(workspacePath, options); // Unlike Theia, IDE2 passes the `input` downstream.
|
||||
@@ -139,21 +155,25 @@ export class WorkspaceService extends TheiaWorkspaceService {
|
||||
}
|
||||
}
|
||||
|
||||
protected override reloadWindow(options?: WorkspaceInput): void {
|
||||
if (StartupTasks.WorkspaceInput.is(options)) {
|
||||
setURL(StartupTask.append(options.tasks, new URL(window.location.href)));
|
||||
}
|
||||
super.reloadWindow();
|
||||
}
|
||||
|
||||
protected override openNewWindow(
|
||||
workspacePath: string,
|
||||
options?: WorkspaceInput
|
||||
): void {
|
||||
const { boardsConfig } = this.boardsServiceProvider;
|
||||
const url = BoardsConfig.Config.setConfig(
|
||||
let url = BoardsConfig.Config.setConfig(
|
||||
boardsConfig,
|
||||
new URL(window.location.href)
|
||||
); // Set the current boards config for the new browser window.
|
||||
url.hash = workspacePath;
|
||||
if (StartupTask.WorkspaceInput.is(options)) {
|
||||
url.searchParams.set(
|
||||
StartupTask.QUERY_STRING,
|
||||
encodeURIComponent(JSON.stringify(options.tasks))
|
||||
);
|
||||
if (StartupTasks.WorkspaceInput.is(options)) {
|
||||
url = StartupTask.append(options.tasks, url);
|
||||
}
|
||||
|
||||
this.windowService.openNewWindow(url.toString());
|
||||
|
||||
@@ -10,21 +10,31 @@ import {
|
||||
CurrentSketch,
|
||||
SketchesServiceClientImpl,
|
||||
} from '../../../common/protocol/sketches-service-client-impl';
|
||||
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||
|
||||
@injectable()
|
||||
export class WorkspaceVariableContribution extends TheiaWorkspaceVariableContribution {
|
||||
@inject(SketchesServiceClientImpl)
|
||||
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
|
||||
private readonly sketchesServiceClient: SketchesServiceClientImpl;
|
||||
|
||||
protected currentSketch?: Sketch;
|
||||
private currentSketch?: Sketch;
|
||||
|
||||
@postConstruct()
|
||||
protected override init(): void {
|
||||
this.sketchesServiceClient.currentSketch().then((sketch) => {
|
||||
if (CurrentSketch.isValid(sketch)) {
|
||||
this.currentSketch = sketch;
|
||||
}
|
||||
});
|
||||
const sketch = this.sketchesServiceClient.tryGetCurrentSketch();
|
||||
if (CurrentSketch.isValid(sketch)) {
|
||||
this.currentSketch = sketch;
|
||||
} else {
|
||||
const toDispose = new DisposableCollection();
|
||||
toDispose.push(
|
||||
this.sketchesServiceClient.onCurrentSketchDidChange((sketch) => {
|
||||
if (CurrentSketch.isValid(sketch)) {
|
||||
this.currentSketch = sketch;
|
||||
}
|
||||
toDispose.dispose();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
override getResourceUri(): URI | undefined {
|
||||
|
||||
Reference in New Issue
Block a user