8000 add "uploadInProgress" prop to boards change event · arduino/arduino-ide@e9137f7 · GitHub
[go: up one dir, main page]

Skip to content
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 e9137f7

Browse files
add "uploadInProgress" prop to boards change event
1 parent 09534c6 commit e9137f7

File tree

6 files changed

+19
-21
lines changed

6 files changed

+19
-21
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
6565
protected _availablePorts: Port[] = [];
6666
protected _availableBoards: AvailableBoard[] = [];
6767

68-
private uploadAttemptInProgress = false;
69-
7068
private lastItemRemovedForUpload: { board: Board; port: Port } | undefined;
7169
// "lastPersistingUploadPort", is a port created during an upload, that persisted after
7270
// the upload finished, it's "substituting" the port selected when the user invoked the upload
@@ -87,9 +85,6 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
8785
private readonly _reconciled = new Deferred<void>();
8886

8987
onStart(): void {
90-
this.notificationCenter.onUploadAttemptInProgress(
91-
this.onUploadAttemptEventReceived.bind(this)
92-
);
9388
this.notificationCenter.onAttachedBoardsDidChange(
9489
this.notifyAttachedBoardsChanged.bind(this)
9590
);
@@ -121,10 +116,6 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
121116
return this._reconciled.promise;
122117
}
123118

124-
private onUploadAttemptEventReceived(uploadAttemptInProgress: boolean): void {
125-
this.uploadAttemptInProgress = uploadAttemptInProgress;
126-
}
127-
128119
private checkForItemRemoved(event: AttachedBoardsChangeEvent): void {
129120
if (!this.lastItemRemovedForUpload) {
130121
const {
@@ -192,7 +183,9 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
192183
this.logger.info('------------------------------------------');
193184
}
194185

195-
if (this.uploadAttemptInProgress) {
186+
const { uploadInProgress } = event;
187+
188+
if (uploadInProgress) {
196189
this.checkForItemRemoved(event);
197190
} else {
198191
this.checkForPersistingPort(event);
@@ -202,7 +195,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
202195
this._availablePorts = event.newState.ports;
203196
this.onAvailablePortsChangedEmitter.fire(this._availablePorts);
204197
this.reconcileAvailableBoards().then(() => {
205-
if (!this.uploadAttemptInProgress) {
198+
if (!uploadInProgress) {
206199
this.tryReconnect();
207200
}
208201
});

arduino-ide-extension/src/browser/notification-center.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export class NotificationCenter
6666
}>();
6767
private readonly onAppStateDidChangeEmitter =
6868
new Emitter<FrontendApplicationState>();
69-
private readonly onUploadAttemptInProgressEmitter = new Emitter<boolean>();
7069

7170
protected readonly toDispose = new DisposableCollection(
7271
this.indexWillUpdateEmitter,
@@ -80,8 +79,7 @@ export class NotificationCenter
8079
this.platformDidUninstallEmitter,
8180
this.libraryDidInstallEmitter,
8281
this.libraryDidUninstallEmitter,
83-
this.attachedBoardsDidChangeEmitter,
84-
this.onUploadAttemptInProgressEmitter
82+
this.attachedBoardsDidChangeEmitter
8583
);
8684

8785
readonly onIndexDidUpdate = this.indexDidUpdateEmitter.event;
@@ -99,8 +97,6 @@ export class NotificationCenter
9997
this.attachedBoardsDidChangeEmitter.event;
10098
readonly onRecentSketchesDidChange = this.recentSketchesChangedEmitter.event;
10199
readonly onAppStateDidChange = this.onAppStateDidChangeEmitter.event;
102-
readonly onUploadAttemptInProgress =
103-
this.onUploadAttemptInProgressEmitter.event;
104100

105101
@postConstruct()
106102
protected init(): void {
@@ -173,8 +169,4 @@ export class NotificationCenter
173169
notifyRecentSketchesDidChange(event: { sketches: Sketch[] }): void {
174170
this.recentSketchesChangedEmitter.fire(event);
175171
}
176-
177-
notifyUploadAttemptInProgress(event: boolean): void {
178-
this.onUploadAttemptInProgressEmitter.fire(event);
179-
}
180172
}

arduino-ide-extension/src/common/protocol/boards-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export namespace AvailablePorts {
2525
export interface AttachedBoardsChangeEvent {
2626
readonly oldState: Readonly<{ boards: Board[]; ports: Port[] }>;
2727
readonly newState: Readonly<{ boards: Board[]; ports: Port[] }>;
28+
readonly uploadInProgress: boolean;
2829
}
2930
export namespace AttachedBoardsChangeEvent {
3031
export function isEmpty(event: AttachedBoardsChangeEvent): boolean {

arduino-ide-extension/src/common/protocol/notification-service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export interface NotificationServiceClient {
2828
notifyLibraryDidUninstall(event: { item: LibraryPackage }): void;
2929
notifyAttachedBoardsDidChange(event: AttachedBoardsChangeEvent): void;
3030
notifyRecentSketchesDidChange(event: { sketches: Sketch[] }): void;
31-
notifyUploadAttemptInProgress(event: boolean): void;
3231
}
3332

3433
export const NotificationServicePath = '/services/notification-service';

arduino-ide-extension/src/node/board-discovery.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export class BoardDiscovery
5454
private readonly onStreamDidCancelEmitter = new Emitter<void>(); // when the watcher is canceled by the IDE2
5555
private readonly toDisposeOnStopWatch = new DisposableCollection();
5656

57+
private uploadInProgress = false;
58+
5759
/**
5860
* Keys are the `address` of the ports.
5961
*
@@ -123,6 +125,10 @@ export class BoardDiscovery
123125
});
124126
}
125127

128+
public setUploadInProgress(uploadAttemptInProgress: boolean): void {
129+
this.uploadInProgress = uploadAttemptInProgress;
130+
}
131+
126132
private createTimeout(
127133
after: number,
128134
onTimeout: (error: Error) => void
@@ -318,6 +324,7 @@ export class BoardDiscovery
318324
ports: newAvailablePorts,
319325
boards: newAttachedBoards,
320326
},
327+
uploadInProgress: this.uploadInProgress,
321328
};
322329

323330
this._availablePorts = newState;

arduino-ide-extension/src/node/core-service-impl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { Instance } from './cli-protocol/cc/arduino/cli/commands/v1/common_pb';
3434
import { firstToUpperCase, notEmpty } from '../common/utils';
3535
import { ServiceError } from './service-error';
3636
import { ExecuteWithProgress, ProgressResponse } from './grpc-progressible';
37+
import { BoardDiscovery } from './board-discovery';
3738

3839
namespace Uploadable {
3940
export type Request = UploadRequest | UploadUsingProgrammerRequest;
@@ -51,6 +52,9 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
5152
@inject(CommandService)
5253
private readonly commandService: CommandService;
5354

55+
@inject(BoardDiscovery)
56+
protected readonly boardDiscovery: BoardDiscovery;
57+
5458
async compile(options: CoreService.Options.Compile): Promise<void> {
5559
const coreClient = await this.coreClient;
5660
const { client, instance } = coreClient;
@@ -378,6 +382,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
378382
fqbn?: string | undefined;
379383
port?: Port | undefined;
380384
}): Promise<void> {
385+
this.boardDiscovery.setUploadInProgress(true);
381386
return this.monitorManager.notifyUploadStarted(fqbn, port);
382387
}
383388

@@ -388,6 +393,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
388393
fqbn?: string | undefined;
389394
port?: Port | undefined;
390395
}): Promise<Status> {
396+
this.boardDiscovery.setUploadInProgress(false);
391397
return this.monitorManager.notifyUploadFinished(fqbn, port);
392398
}
393399

0 commit comments

Comments
 (0)
0