Skip to content

Commit 1982609

Browse files
author
Alberto Iannaccone
committed
fix upload when monitor is open
1 parent 62eaeb1 commit 1982609

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,7 @@ export namespace Status {
8484
export const CONFIG_MISSING: ErrorStatus = {
8585
message: 'Serial Config missing.',
8686
};
87+
export const UPLOAD_IN_PROGRESS: ErrorStatus = {
88+
message: 'Upload in progress.',
89+
};
8790
}

arduino-ide-extension/src/node/monitor-manager.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const MonitorManagerName = 'monitor-manager';
1212
export class MonitorManager extends CoreClientAware {
1313
// Map of monitor services that manage the running pluggable monitors.
1414
// Each service handles the lifetime of one, and only one, monitor.
15-
// If either the board or port managed changes a new service must
15+
// If either the board or port managed changes, a new service must
1616
// be started.
1717
private monitorServices = new Map<MonitorID, MonitorService>();
1818

@@ -109,6 +109,7 @@ export class MonitorManager extends CoreClientAware {
109109
// There's no monitor running there, bail
110110
return;
111111
}
112+
monitor.setUploadInProgress(true);
112113
return await monitor.pause();
113114
}
114115

@@ -132,6 +133,7 @@ export class MonitorManager extends CoreClientAware {
132133
// There's no monitor running there, bail
133134
return Status.NOT_CONNECTED;
134135
}
136+
monitor.setUploadInProgress(false);
135137
return await monitor.start();
136138
}
137139

arduino-ide-extension/src/node/monitor-service.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export class MonitorService extends CoreClientAware implements Disposable {
5353
protected readonly webSocketProvider: WebSocketProvider =
5454
new WebSocketProviderImpl();
5555

56+
protected uploadInProgress = false;
57+
5658
constructor(
5759
@inject(ILogger)
5860
@named(MonitorServiceName)
@@ -80,6 +82,10 @@ export class MonitorService extends CoreClientAware implements Disposable {
8082
);
8183
}
8284

85+
setUploadInProgress(status: boolean): void {
86+
this.uploadInProgress = status;
87+
}
88+
8389
getWebsocketAddressPort(): number {
8490
return this.webSocketProvider.getAddress().port;
8591
}
@@ -113,11 +119,14 @@ export class MonitorService extends CoreClientAware implements Disposable {
113119
return Status.CONFIG_MISSING;
114120
}
115121

122+
if (this.uploadInProgress) {
123+
return Status.UPLOAD_IN_PROGRESS;
124+
}
125+
116126
this.logger.info('starting monitor');
117127
await this.coreClientProvider.initialized;
118128
const coreClient = await this.coreClient();
119129
const { client, instance } = coreClient;
120-
121130
this.duplex = client.monitor();
122131
this.duplex
123132
.on('close', () => {
@@ -205,7 +214,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
205214
* Pauses the currently running monitor, it still closes the gRPC connection
206215
* with the underlying monitor process but it doesn't stop the message handlers
207216
* currently running.
208-
* This is mainly used to handle upload when to the board/port combination
217+
* This is mainly used to handle upload with the board/port combination
209218
* the monitor is listening to.
210219
* @returns
211220
*/
@@ -223,7 +232,8 @@ export class MonitorService extends CoreClientAware implements Disposable {
223232
this.logger.info(
224233
`stopped monitor to ${this.port?.address} using ${this.port?.protocol}`
225234
);
226-
resolve();
235+
236+
this.duplex.on('end', resolve);
227237
});
228238
}
229239

0 commit comments

Comments
 (0)