fix sketch uri issue.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-21 18:49:23 +02:00
parent e1d86d0bda
commit 230bacfd01
5 changed files with 31 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import { inject, injectable } from 'inversify'; import { inject, injectable } from 'inversify';
import { remote } from 'electron'; import { remote } from 'electron';
import { ArduinoMenus } from '../menu/arduino-menus'; 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 { SaveAsSketch } from './save-as-sketch';
import { EditorManager } from '@theia/editor/lib/browser'; import { EditorManager } from '@theia/editor/lib/browser';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
@ -20,7 +20,11 @@ export class CloseSketch extends SketchContribution {
return; return;
} }
const isTemp = await this.sketchService.isTemp(sketch); 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({ const { response } = await remote.dialog.showMessageBox({
type: 'question', type: 'question',
buttons: ["Don't Save", 'Cancel', 'Save'], 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. * If the file was ever touched/modified. We get this based on the `version` of the monaco model.
*/ */
protected async wasTouched(sketch: Sketch): Promise<boolean> { protected async wasTouched(uri: string): Promise<boolean> {
const editorWidget = await this.editorManager.getByUri(new URI(sketch.uri).resolve(`${sketch.name}.ino`)); const editorWidget = await this.editorManager.getByUri(new URI(uri));
if (editorWidget) { if (editorWidget) {
const { editor } = editorWidget; const { editor } = editorWidget;
if (editor instanceof MonacoEditor) { if (editor instanceof MonacoEditor) {

View File

@ -80,6 +80,20 @@ export abstract class SketchContribution extends Contribution {
return sketches[0]; return sketches[0];
} }
protected async currentSketchFile(): Promise<string | undefined> {
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 { export namespace Contribution {

View File

@ -1,7 +1,7 @@
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import { remote } from 'electron'; import { remote } from 'electron';
import { ArduinoMenus } from '../menu/arduino-menus'; import { ArduinoMenus } from '../menu/arduino-menus';
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution'; import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
@injectable() @injectable()
export class OpenSketchExternal extends SketchContribution { export class OpenSketchExternal extends SketchContribution {
@ -28,9 +28,8 @@ export class OpenSketchExternal extends SketchContribution {
} }
protected async openExternal(): Promise<void> { protected async openExternal(): Promise<void> {
const sketch = await this.currentSketch(); const uri = await this.currentSketchFile();
if (sketch) { if (uri) {
const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString();
const exists = this.fileSystem.exists(uri); const exists = this.fileSystem.exists(uri);
if (exists) { if (exists) {
const fsPath = await this.fileSystem.getFsPath(uri); const fsPath = await this.fileSystem.getFsPath(uri);

View File

@ -57,8 +57,8 @@ export class UploadSketch extends SketchContribution {
} }
async uploadSketch(): Promise<void> { async uploadSketch(): Promise<void> {
const sketch = await this.currentSketch(); const uri = await this.currentSketchFile();
if (!sketch) { if (!uri) {
return; return;
} }
const monitorConfig = this.monitorConnection.monitorConfig; const monitorConfig = this.monitorConnection.monitorConfig;
@ -79,7 +79,7 @@ export class UploadSketch extends SketchContribution {
} }
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn); const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn);
await this.coreService.upload({ await this.coreService.upload({
sketchUri: sketch.uri, sketchUri: uri,
fqbn, fqbn,
port: selectedPort.address, port: selectedPort.address,
optimizeForDebug: this.editorMode.compileForDebug optimizeForDebug: this.editorMode.compileForDebug

View File

@ -53,8 +53,8 @@ export class VerifySketch extends SketchContribution {
} }
async verifySketch(): Promise<void> { async verifySketch(): Promise<void> {
const sketch = await this.currentSketch(); const uri = await this.currentSketchFile();
if (!sketch) { if (!uri) {
return; return;
} }
try { try {
@ -67,7 +67,7 @@ export class VerifySketch extends SketchContribution {
} }
const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn); const fqbn = await this.boardsDataStore.appendConfigToFqbn(boardsConfig.selectedBoard.fqbn);
await this.coreService.compile({ await this.coreService.compile({
sketchUri: sketch.uri, sketchUri: uri,
fqbn, fqbn,
optimizeForDebug: this.editorMode.compileForDebug optimizeForDebug: this.editorMode.compileForDebug
}); });