Skip to content

Commit cc12bc0

Browse files
author
Alberto Iannaccone
committed
avoid starting monitor when upload is in progress
1 parent fff6075 commit cc12bc0

File tree

5 files changed

+20
-41
lines changed

5 files changed

+20
-41
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/upload-sketch.ts

-8
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,6 @@ export class UploadSketch extends SketchContribution {
219219
}
220220

221221
try {
222-
// here we inform the "monitorManagerProxyClient" an upload is in progress,
223-
// setting a boolean flag, this is to prevent triggering of the
224-
// "usual side effects" if a serial port change occurs during upload
225-
// (expected on windows for some boards)
226-
this.monitorManagerProxyClient.setUploadInProgress(true);
227-
228222
const { boardsConfig } = this.boardsServiceClientImpl;
229223
const [fqbn, { selectedProgrammer }, verify, verbose, sourceOverride] =
230224
await Promise.all([
@@ -305,8 +299,6 @@ export class UploadSketch extends SketchContribution {
305299
} finally {
306300
this.uploadInProgress = false;
307301

308-
this.monitorManagerProxyClient.setUploadInProgress(false);
309-
310302
this.onDidChangeEmitter.fire();
311303
}
312304
}

Diff for: arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts

-14
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export class MonitorManagerProxyClientImpl
4747
private lastConnectedBoard: BoardsConfig.Config;
4848
private onBoardsConfigChanged: Disposable | undefined;
4949

50-
private uploadInProgress = false;
51-
5250
getWebSocketPort(): number | undefined {
5351
return this.wsPort;
5452
}
@@ -137,14 +135,6 @@ export class MonitorManagerProxyClientImpl
137135
this.onBoardsConfigChanged =
138136
this.boardsServiceProvider.onBoardsConfigChanged(
139137
async ({ selectedBoard, selectedPort }) => {
140-
const changeTriggeredDuringUpload = this.uploadInProgress;
141-
if (
142-
changeTriggeredDuringUpload ||
143-
typeof selectedBoard === 'undefined' ||
144-
typeof selectedPort === 'undefined'
145-
)
146-
return;
147-
148138
// a board is plugged and it's different from the old connected board
149139
if (
150140
selectedBoard?.fqbn !==
@@ -200,8 +190,4 @@ export class MonitorManagerProxyClientImpl
200190
})
201191
);
202192
}
203-
204-
public setUploadInProgress(value: boolean): void {
205-
this.uploadInProgress = value;
206-
}
207193
}

Diff for: arduino-ide-extension/src/common/protocol/monitor-service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export interface MonitorManagerProxyClient {
3939
getCurrentSettings(board: Board, port: Port): Promise<MonitorSettings>;
4040
send(message: string): void;
4141
changeSettings(settings: MonitorSettings): void;
42-
setUploadInProgress(value: boolean): void;
4342
}
4443

4544
export interface PluggableMonitorSetting {

Diff for: arduino-ide-extension/src/node/monitor-manager.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export class MonitorManager extends CoreClientAware {
2020
// If either the board or port managed changes, a new service must
2121
// be started.
2222
private monitorServices = new Map<MonitorID, MonitorService>();
23+
private isUploadInProgress: boolean;
24+
25+
private startMonitorPendingRequests: Array<MonitorID> = [];
2326

2427
@inject(MonitorServiceFactory)
2528
private monitorServiceFactory: MonitorServiceFactory;
@@ -62,7 +65,11 @@ export class MonitorManager extends CoreClientAware {
6265
if (!monitor) {
6366
monitor = this.createMonitor(board, port);
6467
}
65-
return await monitor.start();
68+
if (this.isUploadInProgress) {
69+
this.startMonitorPendingRequests.push(monitorID);
70+
return Status.UPLOAD_IN_PROGRESS;
71+
}
72+
return monitor.start();
6673
}
6774

6875
/**
@@ -117,7 +124,7 @@ export class MonitorManager extends CoreClientAware {
117124
// There's no monitor running there, bail
118125
return;
119126
}
120-
monitor.setUploadInProgress(true);
127+
this.isUploadInProgress = true;
121128
return await monitor.pause();
122129
}
123130

@@ -130,6 +137,14 @@ export class MonitorManager extends CoreClientAware {
130137
* started or if there have been errors.
131138
*/
132139
async notifyUploadFinished(board?: Board, port?: Port): Promise<Status> {
140+
try {
141+
for (const id of this.startMonitorPendingRequests) {
142+
const m = this.monitorServices.get(id);
143+
if (m) m.start();
144+
}
145+
} finally {
146+
this.startMonitorPendingRequests = [];
147+
}
133148
if (!board || !port) {
134149
// We have no way of knowing which monitor
135150
// to retrieve if we don't have this information.
@@ -141,8 +156,9 @@ export class MonitorManager extends CoreClientAware {
141156
// There's no monitor running there, bail
142157
return Status.NOT_CONNECTED;
143158
}
144-
monitor.setUploadInProgress(false);
145-
return await monitor.start();
159+
this.isUploadInProgress = false;
160+
161+
return monitor.start();
146162
}
147163

148164
/**

Diff for: arduino-ide-extension/src/node/monitor-service.ts

-14
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export class MonitorService extends CoreClientAware implements Disposable {
6060
protected readonly onDisposeEmitter = new Emitter<void>();
6161
readonly onDispose = this.onDisposeEmitter.event;
6262

63-
protected uploadInProgress = false;
6463
protected _initialized = new Deferred<void>();
6564
protected creating: Deferred<Status>;
6665

@@ -114,10 +113,6 @@ export class MonitorService extends CoreClientAware implements Disposable {
114113
return this._initialized.promise;
115114
}
116115

117-
setUploadInProgress(status: boolean): void {
118-
this.uploadInProgress = status;
119-
}
120-
121116
getWebsocketAddressPort(): number {
122117
return this.webSocketProvider.getAddress().port;
123118
}
@@ -161,15 +156,6 @@ export class MonitorService extends CoreClientAware implements Disposable {
161156
return this.creating.promise;
162157
}
163158

164-
if (this.uploadInProgress) {
165-
this.updateClientsSettings({
166-
monitorUISettings: { connected: false, serialPort: this.port.address },
167-
});
168-
169-
this.creating.resolve(Status.UPLOAD_IN_PROGRESS);
170-
return this.creating.promise;
171-
}
172-
173159
this.logger.info('starting monitor');
174160

175161
// get default monitor settings from the CLI

0 commit comments

Comments
 (0)