#1089: IDE2 falls back to new sketch if opening failed. (#1152)

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:
Akos Kitta
2022-07-18 11:10:33 +02:00
committed by GitHub
parent fe31d15b9f
commit 8ad10b5adf
35 changed files with 881 additions and 659 deletions

View File

@@ -69,3 +69,5 @@ export interface IDEUpdaterClient {
notifyDownloadProgressChanged(message: ProgressInfo): void;
notifyDownloadFinished(message: UpdateInfo): void;
}
export const SKIP_IDE_VERSION = 'skipIDEVersion';

View File

@@ -17,6 +17,7 @@ import {
} from '../../browser/utils/constants';
import * as monaco from '@theia/monaco-editor-core';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
const READ_ONLY_FILES = ['sketch.json'];
const READ_ONLY_FILES_REMOTE = ['thingProperties.h', 'thingsProperties.h'];
@@ -47,7 +48,9 @@ export class SketchesServiceClientImpl
@inject(ConfigService)
protected readonly configService: ConfigService;
protected toDispose = new DisposableCollection();
@inject(FrontendApplicationStateService)
private readonly appStateService: FrontendApplicationStateService;
protected sketches = new Map<string, SketchRef>();
// TODO: rename this + event to the `onBlabla` pattern
protected sketchbookDidChangeEmitter = new Emitter<{
@@ -55,8 +58,16 @@ export class SketchesServiceClientImpl
removed: SketchRef[];
}>();
readonly onSketchbookDidChange = this.sketchbookDidChangeEmitter.event;
protected currentSketchDidChangeEmitter = new Emitter<CurrentSketch>();
readonly onCurrentSketchDidChange = this.currentSketchDidChangeEmitter.event;
private _currentSketch = new Deferred<CurrentSketch>();
protected toDispose = new DisposableCollection(
this.sketchbookDidChangeEmitter,
this.currentSketchDidChangeEmitter
);
private _currentSketch: CurrentSketch | undefined;
private currentSketchLoaded = new Deferred<CurrentSketch>();
onStart(): void {
this.configService.getConfiguration().then(({ sketchDirUri }) => {
@@ -110,9 +121,14 @@ export class SketchesServiceClientImpl
);
});
});
this.loadCurrentSketch().then((currentSketch) =>
this._currentSketch.resolve(currentSketch)
);
this.appStateService
.reachedState('started_contributions')
.then(async () => {
const currentSketch = await this.loadCurrentSketch();
this._currentSketch = currentSketch;
this.currentSketchDidChangeEmitter.fire(this._currentSketch);
this.currentSketchLoaded.resolve(this._currentSketch);
});
}
onStop(): void {
@@ -143,7 +159,11 @@ export class SketchesServiceClientImpl
}
async currentSketch(): Promise<CurrentSketch> {
return this._currentSketch.promise;
return this.currentSketchLoaded.promise;
}
tryGetCurrentSketch(): CurrentSketch | undefined {
return this._currentSketch;
}
async currentSketchFile(): Promise<string | undefined> {

View File

@@ -1,5 +1,21 @@
import { ApplicationError } from '@theia/core/lib/common/application-error';
import URI from '@theia/core/lib/common/uri';
export namespace SketchesError {
export const Codes = {
NotFound: 5001,
};
export const NotFound = ApplicationError.declare(
Codes.NotFound,
(message: string, uri: string) => {
return {
message,
data: { uri },
};
}
);
}
export const SketchesServicePath = '/services/sketches-service';
export const SketchesService = Symbol('SketchesService');
export interface SketchesService {