-
-
Notifications
You must be signed in to change notification settings - Fork 448
#854 fix platform installation only offered if port is selected #1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+259
−97
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import { NotificationCenter } from '../notification-center'; | |
import { ArduinoCommands } from '../arduino-commands'; | ||
import { StorageWrapper } from '../storage-wrapper'; | ||
import { nls } from '@theia/core/lib/common'; | ||
import { Deferred } from '@theia/core/lib/common/promise-util'; | ||
|
||
@injectable() | ||
export class BoardsServiceProvider implements FrontendApplicationContribution { | ||
|
@@ -73,6 +74,8 @@ export class BoardsServiceProvider implements FrontendApplicationContribution { | |
this.onAvailableBoardsChangedEmitter.event; | ||
readonly onAvailablePortsChanged = this.onAvailablePortsChangedEmitter.event; | ||
|
||
private readonly _reconciled = new Deferred<void>(); | ||
|
||
onStart(): void { | ||
this.notificationCenter.onAttachedBoardsChanged( | ||
this.notifyAttachedBoardsChanged.bind(this) | ||
|
@@ -88,14 +91,22 @@ export class BoardsServiceProvider implements FrontendApplicationContribution { | |
this.boardsService.getAttachedBoards(), | ||
this.boardsService.getAvailablePorts(), | ||
this.loadState(), | ||
]).then(([attachedBoards, availablePorts]) => { | ||
]).then(async ([attachedBoards, availablePorts]) => { | ||
this._attachedBoards = attachedBoards; | ||
this._availablePorts = availablePorts; | ||
this.onAvailablePortsChangedEmitter.fire(this._availablePorts); | ||
this.reconcileAvailableBoards().then(() => this.tryReconnect()); | ||
|
||
await this.reconcileAvailableBoards(); | ||
|
||
this.tryReconnect(); | ||
this._reconciled.resolve(); | ||
}); | ||
} | ||
|
||
get reconciled(): Promise<void> { | ||
return this._reconciled.promise; | ||
} | ||
|
||
protected notifyAttachedBoardsChanged( | ||
event: AttachedBoardsChangeEvent | ||
): void { | ||
|
@@ -185,8 +196,8 @@ export class BoardsServiceProvider implements FrontendApplicationContribution { | |
const selectedAvailableBoard = AvailableBoard.is(selectedBoard) | ||
? selectedBoard | ||
: this._availableBoards.find((availableBoard) => | ||
Board.sameAs(availableBoard, selectedBoard) | ||
); | ||
Board.sameAs(availableBoard, selectedBoard) | ||
); | ||
if ( | ||
selectedAvailableBoard && | ||
selectedAvailableBoard.selected && | ||
|
@@ -209,7 +220,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution { | |
} | ||
} | ||
|
||
protected async tryReconnect(): Promise<boolean> { | ||
protected tryReconnect(): boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. couldn't see a reason for this to be async, it's not called across the wire either |
||
if (this.latestValidBoardsConfig && !this.canUploadTo(this.boardsConfig)) { | ||
for (const board of this.availableBoards.filter( | ||
({ state }) => state !== AvailableBoard.State.incomplete | ||
|
@@ -231,7 +242,8 @@ export class BoardsServiceProvider implements FrontendApplicationContribution { | |
if ( | ||
this.latestValidBoardsConfig.selectedBoard.fqbn === board.fqbn && | ||
this.latestValidBoardsConfig.selectedBoard.name === board.name && | ||
this.latestValidBoardsConfig.selectedPort.protocol === board.port?.protocol | ||
this.latestValidBoardsConfig.selectedPort.protocol === | ||
board.port?.protocol | ||
) { | ||
this.boardsConfig = { | ||
...this.latestValidBoardsConfig, | ||
|
@@ -376,14 +388,14 @@ export class BoardsServiceProvider implements FrontendApplicationContribution { | |
const timeoutTask = | ||
!!timeout && timeout > 0 | ||
? new Promise<void>((_, reject) => | ||
setTimeout( | ||
() => reject(new Error(`Timeout after ${timeout} ms.`)), | ||
timeout | ||
setTimeout( | ||
() => reject(new Error(`Timeout after ${timeout} ms.`)), | ||
timeout | ||
) | ||
) | ||
) | ||
: new Promise<void>(() => { | ||
/* never */ | ||
}); | ||
/* never */ | ||
}); | ||
const waitUntilTask = new Promise<void>((resolve) => { | ||
let candidate = find(what, this.availableBoards); | ||
if (candidate) { | ||
|
@@ -534,8 +546,9 @@ export class BoardsServiceProvider implements FrontendApplicationContribution { | |
|
||
protected getLastSelectedBoardOnPortKey(port: Port | string): string { | ||
// TODO: we lose the port's `protocol` info (`serial`, `network`, etc.) here if the `port` is a `string`. | ||
return `last-selected-board-on-port:${typeof port === 'string' ? port : port.address | ||
}`; | ||
return `last-selected-board-on-port:${ | ||
typeof port === 'string' ? port : port.address | ||
}`; | ||
} | ||
|
||
protected async loadState(): Promise<void> { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.