Skip to content

Commit 8e66de6

Browse files
author
Akos Kitta
committed
feat: simplify board and port handling
Closes #1319 Signed-off-by: Akos Kitta <[email protected]>
1 parent f6a4325 commit 8e66de6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2288
-2689
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import {
6161
BoardsConfigDialog,
6262
BoardsConfigDialogProps,
6363
} from './boards/boards-config-dialog';
64-
import { BoardsConfigDialogWidget } from './boards/boards-config-dialog-widget';
6564
import { ScmContribution as TheiaScmContribution } from '@theia/scm/lib/browser/scm-contribution';
6665
import { ScmContribution } from './theia/scm/scm-contribution';
6766
import { SearchInWorkspaceFrontendContribution as TheiaSearchInWorkspaceFrontendContribution } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution';
@@ -358,7 +357,7 @@ import { UpdateArduinoState } from './contributions/update-arduino-state';
358357
import { TerminalWidgetImpl } from './theia/terminal/terminal-widget-impl';
359358
import { TerminalWidget } from '@theia/terminal/lib/browser/base/terminal-widget';
360359
import { TerminalFrontendContribution } from './theia/terminal/terminal-frontend-contribution';
361-
import { TerminalFrontendContribution as TheiaTerminalFrontendContribution } from '@theia/terminal/lib/browser/terminal-frontend-contribution'
360+
import { TerminalFrontendContribution as TheiaTerminalFrontendContribution } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
362361

363362
// Hack to fix copy/cut/paste issue after electron version update in Theia.
364363
// https://github.com/eclipse-theia/theia/issues/12487
@@ -480,7 +479,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
480479
bind(OpenHandler).toService(BoardsListWidgetFrontendContribution);
481480

482481
// Board select dialog
483-
bind(BoardsConfigDialogWidget).toSelf().inSingletonScope();
484482
bind(BoardsConfigDialog).toSelf().inSingletonScope();
485483
bind(BoardsConfigDialogProps).toConstantValue({
486484
title: nls.localize(
@@ -1034,5 +1032,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
10341032
// Patch terminal issues.
10351033
rebind(TerminalWidget).to(TerminalWidgetImpl).inTransientScope();
10361034
bind(TerminalFrontendContribution).toSelf().inSingletonScope();
1037-
rebind(TheiaTerminalFrontendContribution).toService(TerminalFrontendContribution);
1035+
rebind(TheiaTerminalFrontendContribution).toService(
1036+
TerminalFrontendContribution
1037+
);
10381038
});

Diff for: arduino-ide-extension/src/browser/boards/boards-auto-installer.ts

+25-55
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
BoardsService,
66
BoardsPackage,
77
Board,
8-
Port,
8+
isBoardIdentifierChangeEvent,
9+
BoardIdentifier,
910
} from '../../common/protocol/boards-service';
1011
import { BoardsServiceProvider } from './boards-service-provider';
1112
import { Installable, ResponseServiceClient } from '../../common/protocol';
@@ -24,7 +25,7 @@ interface AutoInstallPromptAction {
2425
type AutoInstallPromptActions = AutoInstallPromptAction[];
2526

2627
/**
27-
* Listens on `BoardsConfig.Config` changes, if a board is selected which does not
28+
* Listens on `BoardList` changes, if a board is selected which does not
2829
* have the corresponding core installed, it proposes the user to install the core.
2930
*/
3031

@@ -44,7 +45,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
4445
protected readonly boardsService: BoardsService;
4546

4647
@inject(BoardsServiceProvider)
47-
protected readonly boardsServiceClient: BoardsServiceProvider;
48+
protected readonly boardsServiceProvider: BoardsServiceProvider;
4849

4950
@inject(ResponseServiceClient)
5051
protected readonly responseService: ResponseServiceClient;
@@ -53,34 +54,28 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
5354
protected readonly boardsManagerFrontendContribution: BoardsListWidgetFrontendContribution;
5455

5556
// Workaround for https://github.com/eclipse-theia/theia/issues/9349
56-
protected notifications: Board[] = [];
57+
protected notifications: BoardIdentifier[] = [];
5758

5859
// * "refusal" meaning a "prompt action" not accepting the auto-install offer ("X" or "install manually")
5960
// we can use "portSelectedOnLastRefusal" to deduce when a board is unplugged after a user has "refused"
6061
// an auto-install prompt. Important to know as we do not want "an unplug" to trigger a "refused" prompt
6162
// showing again
62-
private portSelectedOnLastRefusal: Port | undefined;
63+
// private portSelectedOnLastRefusal: PortIdentifier | undefined;
6364
private lastRefusedPackageId: string | undefined;
6465

6566
onStart(): void {
6667
const setEventListeners = () => {
67-
this.boardsServiceClient.onBoardsConfigChanged((config) => {
68-
const { selectedBoard, selectedPort } = config;
69-
70-
const boardWasUnplugged =
71-
!selectedPort && this.portSelectedOnLastRefusal;
72-
73-
this.clearLastRefusedPromptInfo();
74-
75-
if (
76-
boardWasUnplugged ||
77-
!selectedBoard ||
78-
this.promptAlreadyShowingForBoard(selectedBoard)
79-
) {
68+
this.boardsServiceProvider.onBoardsConfigDidChange((config) => {
69+
if (!isBoardIdentifierChangeEvent(config)) {
70+
return;
71+
}
72+
const { selectedBoard } = config;
73+
const fqbn = selectedBoard?.fqbn;
74+
if (!fqbn) {
8075
return;
8176
}
8277

83-
this.ensureCoreExists(selectedBoard, selectedPort);
78+
this.ensureCoreExists(selectedBoard);
8479
});
8580

8681
// we "clearRefusedPackageInfo" if a "refused" package is eventually
@@ -94,23 +89,16 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
9489
});
9590
};
9691

97-
// we should invoke this.ensureCoreExists only once we're sure
98-
// everything has been reconciled
99-
this.boardsServiceClient.reconciled.then(() => {
100-
const { selectedBoard, selectedPort } =
101-
this.boardsServiceClient.boardsConfig;
102-
103-
if (selectedBoard) {
104-
this.ensureCoreExists(selectedBoard, selectedPort);
105-
}
106-
107-
setEventListeners();
108-
});
92+
setEventListeners(); // TODO: after onDidStart
93+
// });
10994
}
11095

111-
private removeNotificationByBoard(selectedBoard: Board): void {
96+
private removeNotificationByBoard(selectedBoard: BoardIdentifier): void {
11297
const index = this.notifications.findIndex((notification) =>
113-
Board.sameAs(notification, selectedBoard)
98+
Board.sameAs(
99+
{ name: notification.name, fqbn: notification.fqbn },
100+
selectedBoard
101+
)
114102
);
115103
if (index !== -1) {
116104
this.notifications.splice(index, 1);
@@ -119,32 +107,15 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
119107

120108
private clearLastRefusedPromptInfo(): void {
121109
this.lastRefusedPackageId = undefined;
122-
this.portSelectedOnLastRefusal = undefined;
123-
}
124-
125-
private setLastRefusedPromptInfo(
126-
packageId: string,
127-
selectedPort?: Port
128-
): void {
129-
this.lastRefusedPackageId = packageId;
130-
this.portSelectedOnLastRefusal = selectedPort;
131-
}
132-
133-
private promptAlreadyShowingForBoard(board: Board): boolean {
134-
return Boolean(
135-
this.notifications.find((notification) =>
136-
Board.sameAs(notification, board)
137-
)
138-
);
139110
}
140111

141-
protected ensureCoreExists(selectedBoard: Board, selectedPort?: Port): void {
112+
protected ensureCoreExists(selectedBoard: BoardIdentifier): void {
142113
this.notifications.push(selectedBoard);
143114
this.boardsService.search({}).then((packages) => {
144115
const candidate = this.getInstallCandidate(packages, selectedBoard);
145116

146117
if (candidate) {
147-
this.showAutoInstallPrompt(candidate, selectedBoard, selectedPort);
118+
this.showAutoInstallPrompt(candidate, selectedBoard);
148119
} else {
149120
this.removeNotificationByBoard(selectedBoard);
150121
}
@@ -182,8 +153,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
182153

183154
private showAutoInstallPrompt(
184155
candidate: BoardsPackage,
185-
selectedBoard: Board,
186-
selectedPort?: Port
156+
selectedBoard: BoardIdentifier
187157
): void {
188158
const candidateName = candidate.name;
189159
const version = candidate.availableVersions[0]
@@ -199,7 +169,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
199169
const actions = this.createPromptActions(candidate);
200170

201171
const onRefuse = () => {
202-
this.setLastRefusedPromptInfo(candidate.id, selectedPort);
172+
// this.setLastRefusedPromptInfo(candidate.id, selectedPort); TODO: probably noop but let's revisit it.
203173
};
204174
const handleAction = this.createOnAnswerHandler(actions, onRefuse);
205175

0 commit comments

Comments
 (0)