Skip to content

Commit 230bacf

Browse files
author
Akos Kitta
committed
fix sketch uri issue.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent e1d86d0 commit 230bacf

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/close-sketch.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { inject, injectable } from 'inversify';
22
import { remote } from 'electron';
33
import { ArduinoMenus } from '../menu/arduino-menus';
4-
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI, Sketch } from './contribution';
4+
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
55
import { SaveAsSketch } from './save-as-sketch';
66
import { EditorManager } from '@theia/editor/lib/browser';
77
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
@@ -20,7 +20,11 @@ export class CloseSketch extends SketchContribution {
2020
return;
2121
}
2222
const isTemp = await this.sketchService.isTemp(sketch);
23-
if (isTemp && await this.wasTouched(sketch)) {
23+
const uri = await this.currentSketchFile();
24+
if (!uri) {
25+
return;
26+
}
27+
if (isTemp && await this.wasTouched(uri)) {
2428
const { response } = await remote.dialog.showMessageBox({
2529
type: 'question',
2630
buttons: ["Don't Save", 'Cancel', 'Save'],
@@ -60,8 +64,8 @@ export class CloseSketch extends SketchContribution {
6064
/**
6165
* If the file was ever touched/modified. We get this based on the `version` of the monaco model.
6266
*/
63-
protected async wasTouched(sketch: Sketch): Promise<boolean> {
64-
const editorWidget = await this.editorManager.getByUri(new URI(sketch.uri).resolve(`${sketch.name}.ino`));
67+
protected async wasTouched(uri: string): Promise<boolean> {
68+
const editorWidget = await this.editorManager.getByUri(new URI(uri));
6569
if (editorWidget) {
6670
const { editor } = editorWidget;
6771
if (editor instanceof MonacoEditor) {

Diff for: arduino-ide-extension/src/browser/contributions/contribution.ts

+14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ export abstract class SketchContribution extends Contribution {
8080
return sketches[0];
8181
}
8282

83+
protected async currentSketchFile(): Promise<string | undefined> {
84+
const sketch = await this.currentSketch();
85+
if (sketch) {
86+
const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString();
87+
const exists = await this.fileSystem.exists(uri);
88+
if (!exists) {
89+
this.messageService.warn(`Could not find sketch file: ${uri}`);
90+
return undefined;
91+
}
92+
return uri;
93+
}
94+
return undefined;
95+
}
96+
8397
}
8498

8599
export namespace Contribution {

Diff for: arduino-ide-extension/src/browser/contributions/open-sketch-external.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { injectable } from 'inversify';
22
import { remote } from 'electron';
33
import { ArduinoMenus } from '../menu/arduino-menus';
4-
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
4+
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
55

66
@injectable()
77
export class OpenSketchExternal extends SketchContribution {
@@ -28,9 +28,8 @@ export class OpenSketchExternal extends SketchContribution {
2828
}
2929

3030
protected async openExternal(): Promise<void> {
31-
const sketch = await this.currentSketch();
32-
if (sketch) {
33-
const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString();
31+
const uri = await this.currentSketchFile();
32+
if (uri) {
3433
const exists = this.fileSystem.exists(uri);
3534
if (exists) {
3635
const fsPath = await this.fileSystem.getFsPath(uri);

Diff for: arduino-ide-extension/src/browser/contributions/upload-sketch.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export class UploadSketch extends SketchContribution {
5757
}
5858

5959
async uploadSketch(): Promise<void> {
60-
const sketch = await this.currentSketch();
61-
if (!sketch) {
60+
const uri = await this.currentSketchFile();
61+
if (!uri) {
6262
return;
6363
}
6464
const monitorConfig = this.monitorConnection.monitorConfig;
@@ -79,7 +79,7 @@ export class UploadSketch extends SketchContribution {
7979
}
8080
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn);
8181
await this.coreService.upload({
82-
sketchUri: sketch.uri,
82+
sketchUri: uri,
8383
fqbn,
8484
port: selectedPort.address,
8585
optimizeForDebug: this.editorMode.compileForDebug

Diff for: arduino-ide-extension/src/browser/contributions/verify-sketch.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export class VerifySketch extends SketchContribution {
5353
}
5454

5555
async verifySketch(): Promise<void> {
56-
const sketch = await this.currentSketch();
57-
if (!sketch) {
56+
const uri = await this.currentSketchFile();
57+
if (!uri) {
5858
return;
5959
}
6060
try {
@@ -67,7 +67,7 @@ export class VerifySketch extends SketchContribution {
6767
}
6868
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn);
6969
await this.coreService.compile({
70-
sketchUri: sketch.uri,
70+
sketchUri: uri,
7171
fqbn,
7272
optimizeForDebug: this.editorMode.compileForDebug
7373
});

0 commit comments

Comments
 (0)