From cc12bc00567b79cfd225a1a63504f0c9c849a000 Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Tue, 14 Jun 2022 13:13:37 +0200 Subject: [PATCH] avoid starting monitor when upload is in progress --- .../browser/contributions/upload-sketch.ts | 8 ------- .../monitor-manager-proxy-client-impl.ts | 14 ----------- .../src/common/protocol/monitor-service.ts | 1 - .../src/node/monitor-manager.ts | 24 +++++++++++++++---- .../src/node/monitor-service.ts | 14 ----------- 5 files changed, 20 insertions(+), 41 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index 6198ee802..e673fcde0 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -219,12 +219,6 @@ export class UploadSketch extends SketchContribution { } try { - // here we inform the "monitorManagerProxyClient" an upload is in progress, - // setting a boolean flag, this is to prevent triggering of the - // "usual side effects" if a serial port change occurs during upload - // (expected on windows for some boards) - this.monitorManagerProxyClient.setUploadInProgress(true); - const { boardsConfig } = this.boardsServiceClientImpl; const [fqbn, { selectedProgrammer }, verify, verbose, sourceOverride] = await Promise.all([ @@ -305,8 +299,6 @@ export class UploadSketch extends SketchContribution { } finally { this.uploadInProgress = false; - this.monitorManagerProxyClient.setUploadInProgress(false); - this.onDidChangeEmitter.fire(); } } diff --git a/arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts b/arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts index e3dfbdfac..8205b4b25 100644 --- a/arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts +++ b/arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts @@ -47,8 +47,6 @@ export class MonitorManagerProxyClientImpl private lastConnectedBoard: BoardsConfig.Config; private onBoardsConfigChanged: Disposable | undefined; - private uploadInProgress = false; - getWebSocketPort(): number | undefined { return this.wsPort; } @@ -137,14 +135,6 @@ export class MonitorManagerProxyClientImpl this.onBoardsConfigChanged = this.boardsServiceProvider.onBoardsConfigChanged( async ({ selectedBoard, selectedPort }) => { - const changeTriggeredDuringUpload = this.uploadInProgress; - if ( - changeTriggeredDuringUpload || - typeof selectedBoard === 'undefined' || - typeof selectedPort === 'undefined' - ) - return; - // a board is plugged and it's different from the old connected board if ( selectedBoard?.fqbn !== @@ -200,8 +190,4 @@ export class MonitorManagerProxyClientImpl }) ); } - - public setUploadInProgress(value: boolean): void { - this.uploadInProgress = value; - } } diff --git a/arduino-ide-extension/src/common/protocol/monitor-service.ts b/arduino-ide-extension/src/common/protocol/monitor-service.ts index 5f1a8f06a..7374951db 100644 --- a/arduino-ide-extension/src/common/protocol/monitor-service.ts +++ b/arduino-ide-extension/src/common/protocol/monitor-service.ts @@ -39,7 +39,6 @@ export interface MonitorManagerProxyClient { getCurrentSettings(board: Board, port: Port): Promise; send(message: string): void; changeSettings(settings: MonitorSettings): void; - setUploadInProgress(value: boolean): void; } export interface PluggableMonitorSetting { diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 5b5669059..e4fa1fb52 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -20,6 +20,9 @@ export class MonitorManager extends CoreClientAware { // If either the board or port managed changes, a new service must // be started. private monitorServices = new Map(); + private isUploadInProgress: boolean; + + private startMonitorPendingRequests: Array = []; @inject(MonitorServiceFactory) private monitorServiceFactory: MonitorServiceFactory; @@ -62,7 +65,11 @@ export class MonitorManager extends CoreClientAware { if (!monitor) { monitor = this.createMonitor(board, port); } - return await monitor.start(); + if (this.isUploadInProgress) { + this.startMonitorPendingRequests.push(monitorID); + return Status.UPLOAD_IN_PROGRESS; + } + return monitor.start(); } /** @@ -117,7 +124,7 @@ export class MonitorManager extends CoreClientAware { // There's no monitor running there, bail return; } - monitor.setUploadInProgress(true); + this.isUploadInProgress = true; return await monitor.pause(); } @@ -130,6 +137,14 @@ export class MonitorManager extends CoreClientAware { * started or if there have been errors. */ async notifyUploadFinished(board?: Board, port?: Port): Promise { + try { + for (const id of this.startMonitorPendingRequests) { + const m = this.monitorServices.get(id); + if (m) m.start(); + } + } finally { + this.startMonitorPendingRequests = []; + } if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. @@ -141,8 +156,9 @@ export class MonitorManager extends CoreClientAware { // There's no monitor running there, bail return Status.NOT_CONNECTED; } - monitor.setUploadInProgress(false); - return await monitor.start(); + this.isUploadInProgress = false; + + return monitor.start(); } /** diff --git a/arduino-ide-extension/src/node/monitor-service.ts b/arduino-ide-extension/src/node/monitor-service.ts index 086e98de7..a0ab86f6f 100644 --- a/arduino-ide-extension/src/node/monitor-service.ts +++ b/arduino-ide-extension/src/node/monitor-service.ts @@ -60,7 +60,6 @@ export class MonitorService extends CoreClientAware implements Disposable { protected readonly onDisposeEmitter = new Emitter(); readonly onDispose = this.onDisposeEmitter.event; - protected uploadInProgress = false; protected _initialized = new Deferred(); protected creating: Deferred; @@ -114,10 +113,6 @@ export class MonitorService extends CoreClientAware implements Disposable { return this._initialized.promise; } - setUploadInProgress(status: boolean): void { - this.uploadInProgress = status; - } - getWebsocketAddressPort(): number { return this.webSocketProvider.getAddress().port; } @@ -161,15 +156,6 @@ export class MonitorService extends CoreClientAware implements Disposable { return this.creating.promise; } - if (this.uploadInProgress) { - this.updateClientsSettings({ - monitorUISettings: { connected: false, serialPort: this.port.address }, - }); - - this.creating.resolve(Status.UPLOAD_IN_PROGRESS); - return this.creating.promise; - } - this.logger.info('starting monitor'); // get default monitor settings from the CLI