Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 474d5e5

Browse filesBrowse files
Akos Kittakittaakos
authored andcommitted
Added a workaround for missing port#properties.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent f7f644c commit 474d5e5
Copy full SHA for 474d5e5

File tree

Expand file treeCollapse file tree

2 files changed

+36
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+36
-4
lines changed

‎arduino-ide-extension/src/browser/boards/boards-service-provider.ts

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/browser/boards/boards-service-provider.ts
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,16 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
462462
return this._availableBoards;
463463
}
464464

465+
/**
466+
* @deprecated Do not use this API, it will be removed. This is a hack to be able to set the missing port `properties` before an upload.
467+
*
468+
* See: https://github.com/arduino/arduino-ide/pull/1335#issuecomment-1224355236.
469+
*/
470+
// TODO: remove this API and fix the selected board config store/restore correctly.
471+
get availablePorts(): Port[] {
472+
return this._availablePorts.slice();
473+
}
474+
465475
async waitUntilAvailable(
466476
what: Board & { port: Port },
467477
timeout?: number

‎arduino-ide-extension/src/browser/contributions/upload-sketch.ts

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/browser/contributions/upload-sketch.ts
+26-4Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { inject, injectable } from '@theia/core/shared/inversify';
22
import { Emitter } from '@theia/core/lib/common/event';
3-
import { BoardUserField, CoreService } from '../../common/protocol';
3+
import { BoardUserField, CoreService, Port } from '../../common/protocol';
44
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
55
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
66
import {
@@ -12,7 +12,7 @@ import {
1212
CoreServiceContribution,
1313
} from './contribution';
1414
import { UserFieldsDialog } from '../dialogs/user-fields/user-fields-dialog';
15-
import { DisposableCollection, nls } from '@theia/core/lib/common';
15+
import { deepClone, DisposableCollection, nls } from '@theia/core/lib/common';
1616
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1717
import type { VerifySketchParams } from './verify-sketch';
1818

@@ -266,7 +266,7 @@ export class UploadSketch extends CoreServiceContribution {
266266
this.preferences.get('arduino.upload.verify'),
267267
this.preferences.get('arduino.upload.verbose'),
268268
]);
269-
const port = boardsConfig.selectedPort;
269+
const port = this.maybeUpdatePortProperties(boardsConfig.selectedPort);
270270
return {
271271
sketch,
272272
fqbn,
@@ -278,7 +278,29 @@ export class UploadSketch extends CoreServiceContribution {
278278
};
279279
}
280280

281-
private userFields() {
281+
/**
282+
* This is a hack to ensure that the port object has the `properties` when uploading.(https://github.com/arduino/arduino-ide/issues/740)
283+
* This method works around a bug when restoring a `port` persisted by an older version of IDE2. See the bug [here](https://github.com/arduino/arduino-ide/pull/1335#issuecomment-1224355236).
284+
*
285+
* Before the upload, this method checks the available ports and makes sure that the `properties` of an available port, and the port selected by the user have the same `properties`.
286+
* This method does not update any state (for example, the `BoardsConfig.Config`) but uses the correct `properties` for the `upload`.
287+
*/
288+
private maybeUpdatePortProperties(port: Port | undefined): Port | undefined {
289+
if (port) {
290+
const key = Port.keyOf(port);
291+
for (const candidate of this.boardsServiceProvider.availablePorts) {
292+
if (key === Port.keyOf(candidate) && candidate.properties) {
293+
return {
294+
...port,
295+
properties: deepClone(candidate.properties),
296+
};
297+
}
298+
}
299+
}
300+
return port;
301+
}
302+
303+
private userFields(): BoardUserField[] {
282304
return this.cachedUserFields.get(this.selectedFqbnAddress()) ?? [];
283305
}
284306

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.