Skip to content

Commit e78db75

Browse files
author
Akos Kitta
committed
fix: move prompt
force a fallback if user rejects move after restoring and invalid sketch Signed-off-by: Akos Kitta <[email protected]>
1 parent a2af5be commit e78db75

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

arduino-ide-extension/src/browser/contributions/open-sketch-files.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { nls } from '@theia/core/lib/common/nls';
22
import { inject, injectable } from '@theia/core/shared/inversify';
33
import type { EditorOpenerOptions } from '@theia/editor/lib/browser/editor-manager';
44
import { Later } from '../../common/nls';
5-
import { SketchesError } from '../../common/protocol';
5+
import { Sketch, SketchesError } from '../../common/protocol';
66
import {
77
Command,
88
CommandRegistry,
@@ -66,12 +66,20 @@ export class OpenSketchFiles extends SketchContribution {
6666
});
6767
}
6868
const { workspaceError } = this.workspaceService;
69+
// This happens when the IDE2 has been started from a terminal with a /path/to/invalid/sketch. (#964)
70+
// Or user has started the IDE2 from clicking on an `ino` file.
6971
if (SketchesError.InvalidName.is(workspaceError)) {
70-
return this.promptMove(workspaceError);
72+
await this.promptMove(workspaceError);
7173
}
7274
} catch (err) {
75+
// This happens when the user gracefully closed IDE2, all went well
76+
// but the main sketch file or the sketch folder was modified and when user restarts the IDE2
77+
// the sketch path is not valid anymore. (#964)
7378
if (SketchesError.InvalidName.is(err)) {
74-
return this.promptMove(err);
79+
const movedSketch = await this.promptMove(err);
80+
if (!movedSketch) {
81+
return this.openFallbackSketch();
82+
}
7583
}
7684

7785
if (SketchesError.NotFound.is(err)) {
@@ -96,7 +104,7 @@ export class OpenSketchFiles extends SketchContribution {
96104
invalidMainSketchUri: string;
97105
}
98106
>
99-
): Promise<void> {
107+
): Promise<Sketch | undefined> {
100108
const { invalidMainSketchUri } = err.data;
101109
requestAnimationFrame(() => this.messageService.error(err.message));
102110
await wait(10); // let IDE2 toast the error message.
@@ -106,10 +114,12 @@ export class OpenSketchFiles extends SketchContribution {
106114
labelProvider: this.labelProvider,
107115
});
108116
if (movedSketch) {
109-
return this.workspaceService.open(new URI(movedSketch.uri), {
117+
this.workspaceService.open(new URI(movedSketch.uri), {
110118
preserveWindow: true,
111119
});
120+
return movedSketch;
112121
}
122+
return undefined;
113123
}
114124

115125
private async openFallbackSketch(): Promise<void> {

0 commit comments

Comments
 (0)