From 1982609c87dfcdd6d9fe70b24c803516d04ac50c Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Thu, 12 May 2022 15:28:13 +0200 Subject: [PATCH] fix upload when monitor is open --- .../src/common/protocol/monitor-service.ts | 3 +++ .../src/node/monitor-manager.ts | 4 +++- .../src/node/monitor-service.ts | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arduino-ide-extension/src/common/protocol/monitor-service.ts b/arduino-ide-extension/src/common/protocol/monitor-service.ts index f33ac10a..765b7dc2 100644 --- a/arduino-ide-extension/src/common/protocol/monitor-service.ts +++ b/arduino-ide-extension/src/common/protocol/monitor-service.ts @@ -84,4 +84,7 @@ export namespace Status { export const CONFIG_MISSING: ErrorStatus = { message: 'Serial Config missing.', }; + export const UPLOAD_IN_PROGRESS: ErrorStatus = { + message: 'Upload in progress.', + }; } diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index fa8b708f..e1370818 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -12,7 +12,7 @@ export const MonitorManagerName = 'monitor-manager'; export class MonitorManager extends CoreClientAware { // Map of monitor services that manage the running pluggable monitors. // Each service handles the lifetime of one, and only one, monitor. - // If either the board or port managed changes a new service must + // If either the board or port managed changes, a new service must // be started. private monitorServices = new Map(); @@ -109,6 +109,7 @@ export class MonitorManager extends CoreClientAware { // There's no monitor running there, bail return; } + monitor.setUploadInProgress(true); return await monitor.pause(); } @@ -132,6 +133,7 @@ export class MonitorManager extends CoreClientAware { // There's no monitor running there, bail return Status.NOT_CONNECTED; } + monitor.setUploadInProgress(false); return await monitor.start(); } diff --git a/arduino-ide-extension/src/node/monitor-service.ts b/arduino-ide-extension/src/node/monitor-service.ts index eabc3915..94b980b4 100644 --- a/arduino-ide-extension/src/node/monitor-service.ts +++ b/arduino-ide-extension/src/node/monitor-service.ts @@ -53,6 +53,8 @@ export class MonitorService extends CoreClientAware implements Disposable { protected readonly webSocketProvider: WebSocketProvider = new WebSocketProviderImpl(); + protected uploadInProgress = false; + constructor( @inject(ILogger) @named(MonitorServiceName) @@ -80,6 +82,10 @@ export class MonitorService extends CoreClientAware implements Disposable { ); } + setUploadInProgress(status: boolean): void { + this.uploadInProgress = status; + } + getWebsocketAddressPort(): number { return this.webSocketProvider.getAddress().port; } @@ -113,11 +119,14 @@ export class MonitorService extends CoreClientAware implements Disposable { return Status.CONFIG_MISSING; } + if (this.uploadInProgress) { + return Status.UPLOAD_IN_PROGRESS; + } + this.logger.info('starting monitor'); await this.coreClientProvider.initialized; const coreClient = await this.coreClient(); const { client, instance } = coreClient; - this.duplex = client.monitor(); this.duplex .on('close', () => { @@ -205,7 +214,7 @@ export class MonitorService extends CoreClientAware implements Disposable { * Pauses the currently running monitor, it still closes the gRPC connection * with the underlying monitor process but it doesn't stop the message handlers * currently running. - * This is mainly used to handle upload when to the board/port combination + * This is mainly used to handle upload with the board/port combination * the monitor is listening to. * @returns */ @@ -223,7 +232,8 @@ export class MonitorService extends CoreClientAware implements Disposable { this.logger.info( `stopped monitor to ${this.port?.address} using ${this.port?.protocol}` ); - resolve(); + + this.duplex.on('end', resolve); }); }