From 230bacfd01c9984d3bf83a5055919793b6d654b7 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Tue, 21 Jul 2020 18:49:23 +0200 Subject: [PATCH] fix sketch uri issue. Signed-off-by: Akos Kitta --- .../src/browser/contributions/close-sketch.ts | 12 ++++++++---- .../src/browser/contributions/contribution.ts | 14 ++++++++++++++ .../browser/contributions/open-sketch-external.ts | 7 +++---- .../src/browser/contributions/upload-sketch.ts | 6 +++--- .../src/browser/contributions/verify-sketch.ts | 6 +++--- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/close-sketch.ts b/arduino-ide-extension/src/browser/contributions/close-sketch.ts index 92a1617e..3e2f1651 100644 --- a/arduino-ide-extension/src/browser/contributions/close-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/close-sketch.ts @@ -1,7 +1,7 @@ import { inject, injectable } from 'inversify'; import { remote } from 'electron'; import { ArduinoMenus } from '../menu/arduino-menus'; -import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI, Sketch } from './contribution'; +import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution'; import { SaveAsSketch } from './save-as-sketch'; import { EditorManager } from '@theia/editor/lib/browser'; import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; @@ -20,7 +20,11 @@ export class CloseSketch extends SketchContribution { return; } const isTemp = await this.sketchService.isTemp(sketch); - if (isTemp && await this.wasTouched(sketch)) { + const uri = await this.currentSketchFile(); + if (!uri) { + return; + } + if (isTemp && await this.wasTouched(uri)) { const { response } = await remote.dialog.showMessageBox({ type: 'question', buttons: ["Don't Save", 'Cancel', 'Save'], @@ -60,8 +64,8 @@ export class CloseSketch extends SketchContribution { /** * If the file was ever touched/modified. We get this based on the `version` of the monaco model. */ - protected async wasTouched(sketch: Sketch): Promise { - const editorWidget = await this.editorManager.getByUri(new URI(sketch.uri).resolve(`${sketch.name}.ino`)); + protected async wasTouched(uri: string): Promise { + const editorWidget = await this.editorManager.getByUri(new URI(uri)); if (editorWidget) { const { editor } = editorWidget; if (editor instanceof MonacoEditor) { diff --git a/arduino-ide-extension/src/browser/contributions/contribution.ts b/arduino-ide-extension/src/browser/contributions/contribution.ts index f99cb8a7..6fdb13ab 100644 --- a/arduino-ide-extension/src/browser/contributions/contribution.ts +++ b/arduino-ide-extension/src/browser/contributions/contribution.ts @@ -80,6 +80,20 @@ export abstract class SketchContribution extends Contribution { return sketches[0]; } + protected async currentSketchFile(): Promise { + const sketch = await this.currentSketch(); + if (sketch) { + const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString(); + const exists = await this.fileSystem.exists(uri); + if (!exists) { + this.messageService.warn(`Could not find sketch file: ${uri}`); + return undefined; + } + return uri; + } + return undefined; + } + } export namespace Contribution { diff --git a/arduino-ide-extension/src/browser/contributions/open-sketch-external.ts b/arduino-ide-extension/src/browser/contributions/open-sketch-external.ts index 51c3d260..33383bc3 100644 --- a/arduino-ide-extension/src/browser/contributions/open-sketch-external.ts +++ b/arduino-ide-extension/src/browser/contributions/open-sketch-external.ts @@ -1,7 +1,7 @@ import { injectable } from 'inversify'; import { remote } from 'electron'; import { ArduinoMenus } from '../menu/arduino-menus'; -import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution'; +import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution'; @injectable() export class OpenSketchExternal extends SketchContribution { @@ -28,9 +28,8 @@ export class OpenSketchExternal extends SketchContribution { } protected async openExternal(): Promise { - const sketch = await this.currentSketch(); - if (sketch) { - const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString(); + const uri = await this.currentSketchFile(); + if (uri) { const exists = this.fileSystem.exists(uri); if (exists) { const fsPath = await this.fileSystem.getFsPath(uri); diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index 5012338f..45a6804e 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -57,8 +57,8 @@ export class UploadSketch extends SketchContribution { } async uploadSketch(): Promise { - const sketch = await this.currentSketch(); - if (!sketch) { + const uri = await this.currentSketchFile(); + if (!uri) { return; } const monitorConfig = this.monitorConnection.monitorConfig; @@ -79,7 +79,7 @@ export class UploadSketch extends SketchContribution { } const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn); await this.coreService.upload({ - sketchUri: sketch.uri, + sketchUri: uri, fqbn, port: selectedPort.address, optimizeForDebug: this.editorMode.compileForDebug diff --git a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts index 3421c5be..bb83af24 100644 --- a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts @@ -53,8 +53,8 @@ export class VerifySketch extends SketchContribution { } async verifySketch(): Promise { - const sketch = await this.currentSketch(); - if (!sketch) { + const uri = await this.currentSketchFile(); + if (!uri) { return; } try { @@ -67,7 +67,7 @@ export class VerifySketch extends SketchContribution { } const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn); await this.coreService.compile({ - sketchUri: sketch.uri, + sketchUri: uri, fqbn, optimizeForDebug: this.editorMode.compileForDebug });