Skip to content

Commit 7da8851

Browse files
author
Christian Weichel
committed
Added refresh attached boards command
1 parent 97135bd commit 7da8851

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

arduino-ide-extension/src/browser/arduino-commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ export namespace ArduinoCommands {
1818
category: 'File'
1919
}
2020

21+
export const REFRESH_BOARDS: Command = {
22+
id: "arduino-refresh-attached-boards",
23+
label: "Refresh attached boards"
24+
}
25+
2126
}

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ConnectedBoards } from './components/connected-boards';
1212
import { CoreService } from '../common/protocol/core-service';
1313
import { WorkspaceServiceExt } from './workspace-service-ext';
1414
import { ToolOutputServiceClient } from '../common/protocol/tool-output-service';
15-
import { ConfirmDialog } from '@theia/core/lib/browser';
1615
import { QuickPickService } from '@theia/core/lib/common/quick-pick-service';
1716
import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-frontend-contribution';
1817
import { BoardsNotificationService } from './boards-notification-service';
@@ -101,9 +100,14 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
101100
}
102101

103102
const uri = this.toUri(widget);
104-
if (uri) {
105-
const result = await this.coreService.compile({ uri: uri.toString() });
106-
console.log('compile result', result);
103+
if (!uri) {
104+
return;
105+
}
106+
107+
try {
108+
await this.coreService.compile({ uri: uri.toString() });
109+
} catch (e) {
110+
await this.messageService.error(e.toString());
107111
}
108112
}
109113
});
@@ -123,19 +127,28 @@ export class ArduinoFrontendContribution extends DefaultFrontendApplicationContr
123127
try {
124128
await this.coreService.upload({ uri: uri.toString() });
125129
} catch (e) {
126-
new ConfirmDialog({ title: "Error during upload", msg: e.toString(), ok: "Ok" }).open();
130+
await this.messageService.error(e.toString());
127131
}
128132
}
129133
});
130134
registry.registerCommand(ArduinoCommands.NEW_SKETCH, new WorkspaceRootUriAwareCommandHandler(this.workspaceService, this.selectionService, {
131135
execute: async uri => {
132136
try {
137+
// hack: sometimes we don't get the workspace root, but the currently active file: correct for that
138+
if (uri.path.ext !== "") {
139+
uri = uri.withPath(uri.path.dir.dir);
140+
}
141+
133142
await this.sketchFactory.createNewSketch(uri);
134143
} catch (e) {
135-
new ConfirmDialog({ title: "Cannot create new sketch", msg: e.toString(), ok: "Ok" }).open();
144+
await this.messageService.error(e.toString());
136145
}
137146
}
138-
}))
147+
}));
148+
registry.registerCommand(ArduinoCommands.REFRESH_BOARDS, {
149+
isEnabled: () => true,
150+
execute: () => this.boardsNotificationService.notifyBoardsInstalled()
151+
})
139152
}
140153

141154
private async onNoBoardsInstalled() {

arduino-ide-extension/src/browser/sketch-factory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ export class SketchFactory {
4040
this.fileSystem.createFolder(sketchDir.toString());
4141
this.fileSystem.createFile(sketchFile.toString(), { content: `
4242
void setup() {
43+
// put your setup code here, to run once:
4344
4445
}
4546
4647
void loop() {
48+
// put your main code here, to run repeatedly:
4749
4850
}
4951
` });

0 commit comments

Comments
 (0)