From d10181bd7d5a23a858e1445864d13a9e34bb746b Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 10 Jun 2022 19:06:01 +0200 Subject: [PATCH 01/24] 1032 failing upload flag for monitor mgr --- arduino-ide-extension/src/node/monitor-manager.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 5b5669059..a04ace640 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -24,6 +24,8 @@ export class MonitorManager extends CoreClientAware { @inject(MonitorServiceFactory) private monitorServiceFactory: MonitorServiceFactory; + uploading = false; + constructor( @inject(ILogger) @named(MonitorManagerName) @@ -57,6 +59,9 @@ export class MonitorManager extends CoreClientAware { * started or if there have been errors. */ async startMonitor(board: Board, port: Port): Promise { + if (this.uploading) { + return Status.UPLOAD_IN_PROGRESS; + } const monitorID = this.monitorID(board, port); let monitor = this.monitorServices.get(monitorID); if (!monitor) { @@ -106,6 +111,7 @@ export class MonitorManager extends CoreClientAware { * @param port port to monitor */ async notifyUploadStarted(board?: Board, port?: Port): Promise { + this.uploading = true; if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. @@ -130,6 +136,7 @@ export class MonitorManager extends CoreClientAware { * started or if there have been errors. */ async notifyUploadFinished(board?: Board, port?: Port): Promise { + this.uploading = false; if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. From eed8a694094693908d03fbc3abae9c286e394eef Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Mon, 13 Jun 2022 13:54:08 +0200 Subject: [PATCH 02/24] move upload failure fix logic to frontend --- .../browser/contributions/upload-sketch.ts | 21 +++++++++++++++++-- .../monitor-manager-proxy-client-impl.ts | 8 +++++++ .../src/common/protocol/monitor-service.ts | 1 + .../src/node/monitor-manager.ts | 7 ------- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index 76a8f4973..a68d6ebf9 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -1,6 +1,10 @@ import { inject, injectable } from '@theia/core/shared/inversify'; import { Emitter } from '@theia/core/lib/common/event'; -import { BoardUserField, CoreService } from '../../common/protocol'; +import { + BoardUserField, + CoreService, + MonitorManagerProxyClient, +} from '../../common/protocol'; import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus'; import { ArduinoToolbar } from '../toolbar/arduino-toolbar'; import { BoardsDataStore } from '../boards/boards-data-store'; @@ -34,6 +38,9 @@ export class UploadSketch extends SketchContribution { @inject(UserFieldsDialog) protected readonly userFieldsDialog: UserFieldsDialog; + @inject(MonitorManagerProxyClient) + protected readonly monitorManagerProxyClient: MonitorManagerProxyClient; + protected cachedUserFields: Map = new Map(); protected readonly onDidChangeEmitter = new Emitter>(); @@ -204,6 +211,13 @@ export class UploadSketch extends SketchContribution { // toggle the toolbar button and menu item state. // uploadInProgress will be set to false whether the upload fails or not this.uploadInProgress = true; + + // 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); + this.onDidChangeEmitter.fire(); const sketch = await this.sketchServiceClient.currentSketch(); if (!CurrentSketch.isValid(sketch)) { @@ -227,7 +241,7 @@ export class UploadSketch extends SketchContribution { ...boardsConfig.selectedBoard, name: boardsConfig.selectedBoard?.name || '', fqbn, - } + }; let options: CoreService.Upload.Options | undefined = undefined; const sketchUri = sketch.uri; const optimizeForDebug = this.editorMode.compileForDebug; @@ -290,6 +304,9 @@ export class UploadSketch extends SketchContribution { this.messageService.error(errorMessage); } 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 5519057aa..e3dfbdfac 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,6 +47,8 @@ export class MonitorManagerProxyClientImpl private lastConnectedBoard: BoardsConfig.Config; private onBoardsConfigChanged: Disposable | undefined; + private uploadInProgress = false; + getWebSocketPort(): number | undefined { return this.wsPort; } @@ -135,7 +137,9 @@ export class MonitorManagerProxyClientImpl this.onBoardsConfigChanged = this.boardsServiceProvider.onBoardsConfigChanged( async ({ selectedBoard, selectedPort }) => { + const changeTriggeredDuringUpload = this.uploadInProgress; if ( + changeTriggeredDuringUpload || typeof selectedBoard === 'undefined' || typeof selectedPort === 'undefined' ) @@ -196,4 +200,8 @@ 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 7374951db..5f1a8f06a 100644 --- a/arduino-ide-extension/src/common/protocol/monitor-service.ts +++ b/arduino-ide-extension/src/common/protocol/monitor-service.ts @@ -39,6 +39,7 @@ 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 a04ace640..5b5669059 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -24,8 +24,6 @@ export class MonitorManager extends CoreClientAware { @inject(MonitorServiceFactory) private monitorServiceFactory: MonitorServiceFactory; - uploading = false; - constructor( @inject(ILogger) @named(MonitorManagerName) @@ -59,9 +57,6 @@ export class MonitorManager extends CoreClientAware { * started or if there have been errors. */ async startMonitor(board: Board, port: Port): Promise { - if (this.uploading) { - return Status.UPLOAD_IN_PROGRESS; - } const monitorID = this.monitorID(board, port); let monitor = this.monitorServices.get(monitorID); if (!monitor) { @@ -111,7 +106,6 @@ export class MonitorManager extends CoreClientAware { * @param port port to monitor */ async notifyUploadStarted(board?: Board, port?: Port): Promise { - this.uploading = true; if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. @@ -136,7 +130,6 @@ export class MonitorManager extends CoreClientAware { * started or if there have been errors. */ async notifyUploadFinished(board?: Board, port?: Port): Promise { - this.uploading = false; if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. From fff607551fba7f1ec2aca5ba2abeba9ee4af072e Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Mon, 13 Jun 2022 15:41:38 +0200 Subject: [PATCH 03/24] misc corrections --- .../src/browser/contributions/upload-sketch.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index a68d6ebf9..6198ee802 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -212,12 +212,6 @@ export class UploadSketch extends SketchContribution { // uploadInProgress will be set to false whether the upload fails or not this.uploadInProgress = true; - // 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); - this.onDidChangeEmitter.fire(); const sketch = await this.sketchServiceClient.currentSketch(); if (!CurrentSketch.isValid(sketch)) { @@ -225,6 +219,12 @@ 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([ From cc12bc00567b79cfd225a1a63504f0c9c849a000 Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Tue, 14 Jun 2022 13:13:37 +0200 Subject: [PATCH 04/24] 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 From 209ac696865e6bbd71c62f6621085e3d3bdd422b Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Tue, 14 Jun 2022 13:13:37 +0200 Subject: [PATCH 05/24] avoid starting monitor when upload is in progress --- .../browser/contributions/upload-sketch.ts | 8 ------- .../monitor-manager-proxy-client-impl.ts | 8 ------- .../src/common/protocol/monitor-service.ts | 1 - .../src/node/monitor-manager.ts | 24 +++++++++++++++---- .../src/node/monitor-service.ts | 14 ----------- 5 files changed, 20 insertions(+), 35 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..5519057aa 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,9 +135,7 @@ export class MonitorManagerProxyClientImpl this.onBoardsConfigChanged = this.boardsServiceProvider.onBoardsConfigChanged( async ({ selectedBoard, selectedPort }) => { - const changeTriggeredDuringUpload = this.uploadInProgress; if ( - changeTriggeredDuringUpload || typeof selectedBoard === 'undefined' || typeof selectedPort === 'undefined' ) @@ -200,8 +196,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 From 48b9c4d16baa95d9fce27242684b848f77e4413f Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Wed, 15 Jun 2022 13:41:27 +0200 Subject: [PATCH 06/24] prevent monitor side effects on upload (WIP) --- .../src/node/core-service-impl.ts | 6 +- .../src/node/monitor-manager-proxy-impl.ts | 13 ++-- .../src/node/monitor-manager.ts | 67 ++++++++++++++----- 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 00d6ca5ed..25f81e871 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -140,7 +140,6 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { this.uploading = true; const { sketchUri, board, port, programmer } = options; - await this.monitorManager.notifyUploadStarted(board, port); const sketchPath = FileUri.fsPath(sketchUri); @@ -175,6 +174,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { const result = responseHandler(client, req); try { + await this.monitorManager.notifyUploadStarted(board, port); + await new Promise((resolve, reject) => { result.on('data', (resp: UploadResponse) => { this.responseService.appendToOutput({ @@ -207,7 +208,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { throw new Error(errorMessage); } finally { this.uploading = false; - this.monitorManager.notifyUploadFinished(board, port); + await this.monitorManager.notifyUploadFinished(board, port); + await this.monitorManager.startQueuedServices(); } } diff --git a/arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts b/arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts index c4e9d59d5..f71f6c345 100644 --- a/arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts +++ b/arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts @@ -40,11 +40,14 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy { if (settings) { await this.changeMonitorSettings(board, port, settings); } - const status = await this.manager.startMonitor(board, port); - if (status === Status.ALREADY_CONNECTED || status === Status.OK) { - // Monitor started correctly, connect it with the frontend - this.client.connect(this.manager.getWebsocketAddressPort(board, port)); - } + + const onFinish = (status: Status) => { + if (status === Status.ALREADY_CONNECTED || status === Status.OK) { + // Monitor started correctly, connect it with the frontend + this.client.connect(this.manager.getWebsocketAddressPort(board, port)); + } + }; + return this.manager.startMonitor(board, port, onFinish); } /** diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index e4fa1fb52..4adad2881 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -1,6 +1,6 @@ import { ILogger } from '@theia/core'; import { inject, injectable, named } from '@theia/core/shared/inversify'; -import { Board, Port, Status } from '../common/protocol'; +import { Board, BoardsService, Port, Status } from '../common/protocol'; import { CoreClientAware } from './core-client-provider'; import { MonitorService } from './monitor-service'; import { MonitorServiceFactory } from './monitor-service-factory'; @@ -15,6 +15,9 @@ export const MonitorManagerName = 'monitor-manager'; @injectable() export class MonitorManager extends CoreClientAware { + @inject(BoardsService) + protected boardsService: BoardsService; + // 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 @@ -22,7 +25,10 @@ export class MonitorManager extends CoreClientAware { private monitorServices = new Map(); private isUploadInProgress: boolean; - private startMonitorPendingRequests: Array = []; + private startMonitorPendingRequests: [ + [Board, Port], + (status: Status) => void + ][] = []; @inject(MonitorServiceFactory) private monitorServiceFactory: MonitorServiceFactory; @@ -59,17 +65,25 @@ export class MonitorManager extends CoreClientAware { * @returns a Status object to know if the process has been * started or if there have been errors. */ - async startMonitor(board: Board, port: Port): Promise { + async startMonitor( + board: Board, + port: Port, + postStartCallback: (status: Status) => void + ): Promise { const monitorID = this.monitorID(board, port); + let monitor = this.monitorServices.get(monitorID); if (!monitor) { monitor = this.createMonitor(board, port); } + if (this.isUploadInProgress) { - this.startMonitorPendingRequests.push(monitorID); - return Status.UPLOAD_IN_PROGRESS; + this.startMonitorPendingRequests.push([[board, port], postStartCallback]); + return; } - return monitor.start(); + + const result = await monitor.start(); + postStartCallback(result); } /** @@ -113,6 +127,8 @@ export class MonitorManager extends CoreClientAware { * @param port port to monitor */ async notifyUploadStarted(board?: Board, port?: Port): Promise { + this.isUploadInProgress = true; + if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. @@ -124,8 +140,7 @@ export class MonitorManager extends CoreClientAware { // There's no monitor running there, bail return; } - this.isUploadInProgress = true; - return await monitor.pause(); + return monitor.pause(); } /** @@ -137,14 +152,8 @@ 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 = []; - } + this.isUploadInProgress = false; + if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. @@ -156,11 +165,35 @@ export class MonitorManager extends CoreClientAware { // There's no monitor running there, bail return Status.NOT_CONNECTED; } - this.isUploadInProgress = false; return monitor.start(); } + async startQueuedServices(): Promise { + const queued = this.startMonitorPendingRequests; + this.startMonitorPendingRequests = []; + + for (const [[board, port], onFinish] of queued) { + const boardsState = await this.boardsService.getState(); + const boardIsStillOnPort = Object.keys(boardsState) + .map((connection: string) => { + const portAddress = connection.split('|')[0]; + return portAddress; + }) + .some((portAddress: string) => port.address === portAddress); + + if (boardIsStillOnPort) { + const monitorID = this.monitorID(board, port); + const monitorService = this.monitorServices.get(monitorID); + + if (monitorService) { + const result = await monitorService.start(); + onFinish(result); + } + } + } + } + /** * Changes the settings of a pluggable monitor even if it's running. * If monitor is not running they're going to be used as soon as it's started. From 01604ee2b39a0ae8bb3cbadd6be4aaf7b22f592f Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Wed, 15 Jun 2022 15:29:39 +0200 Subject: [PATCH 07/24] send upload req after notifying mgr --- arduino-ide-extension/src/node/core-service-impl.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 25f81e871..b5272d83b 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -171,11 +171,11 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { req.getUserFieldsMap().set(e.name, e.value); }); - const result = responseHandler(client, req); - try { await this.monitorManager.notifyUploadStarted(board, port); + const result = responseHandler(client, req); + await new Promise((resolve, reject) => { result.on('data', (resp: UploadResponse) => { this.responseService.appendToOutput({ From 2d5dff2a2d85754467470b5973b7ecac8017aa58 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Wed, 15 Jun 2022 19:38:59 +0200 Subject: [PATCH 08/24] dispose instead of pause on upld (code not final) --- .../src/node/core-service-impl.ts | 12 ++++- .../src/node/monitor-manager.ts | 45 +++++++++++++------ .../src/node/monitor-service.ts | 4 +- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 14b6d3007..f8df42fdb 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -180,8 +180,12 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { req.getUserFieldsMap().set(e.name, e.value); }); + let reconnectMonitorCallback; try { - await this.monitorManager.notifyUploadStarted(board, port); + reconnectMonitorCallback = await this.monitorManager.notifyUploadStarted( + board, + port + ); const result = responseHandler(client, req); @@ -224,7 +228,11 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { throw new Error(errorMessage); } finally { this.uploading = false; - await this.monitorManager.notifyUploadFinished(board, port); + await this.monitorManager.notifyUploadFinished( + board, + port, + reconnectMonitorCallback + ); await this.monitorManager.startQueuedServices(); } } diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 4adad2881..3636ae5b0 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -23,6 +23,10 @@ export class MonitorManager extends CoreClientAware { // If either the board or port managed changes, a new service must // be started. private monitorServices = new Map(); + private reconnectServiceCallbacks = new Map< + MonitorID, + (status: Status) => void + >(); private isUploadInProgress: boolean; private startMonitorPendingRequests: [ @@ -84,6 +88,7 @@ export class MonitorManager extends CoreClientAware { const result = await monitor.start(); postStartCallback(result); + this.reconnectServiceCallbacks.set(monitorID, postStartCallback); } /** @@ -126,21 +131,29 @@ export class MonitorManager extends CoreClientAware { * @param board board connected to port * @param port port to monitor */ - async notifyUploadStarted(board?: Board, port?: Port): Promise { + async notifyUploadStarted( + board?: Board, + port?: Port + ): Promise<((status: Status) => void) | undefined> { this.isUploadInProgress = true; if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. - return; + return undefined; } const monitorID = this.monitorID(board, port); const monitor = this.monitorServices.get(monitorID); if (!monitor) { // There's no monitor running there, bail - return; + return undefined; + } + + const reconnectCallback = this.reconnectServiceCallbacks.get(monitorID); + await monitor.dispose(); + if (reconnectCallback) { + return reconnectCallback; } - return monitor.pause(); } /** @@ -151,22 +164,27 @@ export class MonitorManager extends CoreClientAware { * @returns a Status object to know if the process has been * started or if there have been errors. */ - async notifyUploadFinished(board?: Board, port?: Port): Promise { + async notifyUploadFinished( + board?: Board, + port?: Port, + postStartCallback?: (status: Status) => void + ): Promise { this.isUploadInProgress = false; if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. - return Status.NOT_CONNECTED; - } - const monitorID = this.monitorID(board, port); - const monitor = this.monitorServices.get(monitorID); - if (!monitor) { - // There's no monitor running there, bail - return Status.NOT_CONNECTED; + return; } - return monitor.start(); + const monitor = this.createMonitor(board, port); + const restartServiceResult = await monitor.start(); + if (postStartCallback) { + postStartCallback(restartServiceResult); + + const monitorID = this.monitorID(board, port); + this.reconnectServiceCallbacks.set(monitorID, postStartCallback); + } } async startQueuedServices(): Promise { @@ -252,6 +270,7 @@ export class MonitorManager extends CoreClientAware { monitor.onDispose( (() => { this.monitorServices.delete(monitorID); + this.reconnectServiceCallbacks.delete(monitorID); }).bind(this) ); return monitor; diff --git a/arduino-ide-extension/src/node/monitor-service.ts b/arduino-ide-extension/src/node/monitor-service.ts index a0ab86f6f..774ae5d2f 100644 --- a/arduino-ide-extension/src/node/monitor-service.ts +++ b/arduino-ide-extension/src/node/monitor-service.ts @@ -117,8 +117,8 @@ export class MonitorService extends CoreClientAware implements Disposable { return this.webSocketProvider.getAddress().port; } - dispose(): void { - this.stop(); + async dispose(): Promise { + await this.stop(); this.onDisposeEmitter.fire(); this.onWSClientsNumberChanged?.dispose(); } From 89e51cbd56df7b8c1d8d232b82e9ca4fe041380f Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Thu, 16 Jun 2022 07:48:05 +0200 Subject: [PATCH 09/24] Revert "dispose instead of pause on upld (code not final)" This reverts commit 2d5dff2a2d85754467470b5973b7ecac8017aa58. --- .../src/node/core-service-impl.ts | 12 +---- .../src/node/monitor-manager.ts | 45 ++++++------------- .../src/node/monitor-service.ts | 4 +- 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index f8df42fdb..14b6d3007 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -180,12 +180,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { req.getUserFieldsMap().set(e.name, e.value); }); - let reconnectMonitorCallback; try { - reconnectMonitorCallback = await this.monitorManager.notifyUploadStarted( - board, - port - ); + await this.monitorManager.notifyUploadStarted(board, port); const result = responseHandler(client, req); @@ -228,11 +224,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { throw new Error(errorMessage); } finally { this.uploading = false; - await this.monitorManager.notifyUploadFinished( - board, - port, - reconnectMonitorCallback - ); + await this.monitorManager.notifyUploadFinished(board, port); await this.monitorManager.startQueuedServices(); } } diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 3636ae5b0..4adad2881 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -23,10 +23,6 @@ export class MonitorManager extends CoreClientAware { // If either the board or port managed changes, a new service must // be started. private monitorServices = new Map(); - private reconnectServiceCallbacks = new Map< - MonitorID, - (status: Status) => void - >(); private isUploadInProgress: boolean; private startMonitorPendingRequests: [ @@ -88,7 +84,6 @@ export class MonitorManager extends CoreClientAware { const result = await monitor.start(); postStartCallback(result); - this.reconnectServiceCallbacks.set(monitorID, postStartCallback); } /** @@ -131,29 +126,21 @@ export class MonitorManager extends CoreClientAware { * @param board board connected to port * @param port port to monitor */ - async notifyUploadStarted( - board?: Board, - port?: Port - ): Promise<((status: Status) => void) | undefined> { + async notifyUploadStarted(board?: Board, port?: Port): Promise { this.isUploadInProgress = true; if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. - return undefined; + return; } const monitorID = this.monitorID(board, port); const monitor = this.monitorServices.get(monitorID); if (!monitor) { // There's no monitor running there, bail - return undefined; - } - - const reconnectCallback = this.reconnectServiceCallbacks.get(monitorID); - await monitor.dispose(); - if (reconnectCallback) { - return reconnectCallback; + return; } + return monitor.pause(); } /** @@ -164,27 +151,22 @@ export class MonitorManager extends CoreClientAware { * @returns a Status object to know if the process has been * started or if there have been errors. */ - async notifyUploadFinished( - board?: Board, - port?: Port, - postStartCallback?: (status: Status) => void - ): Promise { + async notifyUploadFinished(board?: Board, port?: Port): Promise { this.isUploadInProgress = false; if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. - return; + return Status.NOT_CONNECTED; } - - const monitor = this.createMonitor(board, port); - const restartServiceResult = await monitor.start(); - if (postStartCallback) { - postStartCallback(restartServiceResult); - - const monitorID = this.monitorID(board, port); - this.reconnectServiceCallbacks.set(monitorID, postStartCallback); + const monitorID = this.monitorID(board, port); + const monitor = this.monitorServices.get(monitorID); + if (!monitor) { + // There's no monitor running there, bail + return Status.NOT_CONNECTED; } + + return monitor.start(); } async startQueuedServices(): Promise { @@ -270,7 +252,6 @@ export class MonitorManager extends CoreClientAware { monitor.onDispose( (() => { this.monitorServices.delete(monitorID); - this.reconnectServiceCallbacks.delete(monitorID); }).bind(this) ); return monitor; diff --git a/arduino-ide-extension/src/node/monitor-service.ts b/arduino-ide-extension/src/node/monitor-service.ts index 774ae5d2f..a0ab86f6f 100644 --- a/arduino-ide-extension/src/node/monitor-service.ts +++ b/arduino-ide-extension/src/node/monitor-service.ts @@ -117,8 +117,8 @@ export class MonitorService extends CoreClientAware implements Disposable { return this.webSocketProvider.getAddress().port; } - async dispose(): Promise { - await this.stop(); + dispose(): void { + this.stop(); this.onDisposeEmitter.fire(); this.onWSClientsNumberChanged?.dispose(); } From a9d968c440b1fc88bd1dab60ea71e2648db6dca3 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Thu, 16 Jun 2022 08:41:21 +0200 Subject: [PATCH 10/24] force wait before upload (test) --- arduino-ide-extension/src/node/core-service-impl.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 14b6d3007..1db421966 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -183,6 +183,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { try { await this.monitorManager.notifyUploadStarted(board, port); + await new Promise((r) => setTimeout(r, 10000)); + const result = responseHandler(client, req); const uploadBuffer = new SimpleBuffer( From bd02a19c9a3ab754a8e7a33398c6441f69ffaec5 Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Thu, 16 Jun 2022 11:22:48 +0200 Subject: [PATCH 11/24] always start queued services after uplaod finishes --- .../src/node/core-service-impl.ts | 16 ++++++------- .../src/node/monitor-manager.ts | 23 +++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 1db421966..2fa7ebc1f 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -182,7 +182,6 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { try { await this.monitorManager.notifyUploadStarted(board, port); - await new Promise((r) => setTimeout(r, 10000)); const result = responseHandler(client, req); @@ -227,14 +226,12 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { } finally { this.uploading = false; await this.monitorManager.notifyUploadFinished(board, port); - await this.monitorManager.startQueuedServices(); } } async burnBootloader(options: CoreService.Bootloader.Options): Promise { this.uploading = true; const { board, port, programmer } = options; - await this.monitorManager.notifyUploadStarted(board, port); await this.coreClientProvider.initialized; const coreClient = await this.coreClient(); @@ -257,13 +254,14 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { } burnReq.setVerify(options.verify); burnReq.setVerbose(options.verbose); - const result = client.burnBootloader(burnReq); - - const bootloaderBuffer = new SimpleBuffer( - this.flushOutputPanelMessages.bind(this), - FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS - ); try { + await this.monitorManager.notifyUploadStarted(board, port); + const result = client.burnBootloader(burnReq); + + const bootloaderBuffer = new SimpleBuffer( + this.flushOutputPanelMessages.bind(this), + FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS + ); await new Promise((resolve, reject) => { result.on('data', (resp: BurnBootloaderResponse) => { bootloaderBuffer.addChunk(resp.getOutStream_asU8()); diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 4adad2881..09ac4f191 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -153,20 +153,19 @@ export class MonitorManager extends CoreClientAware { */ async notifyUploadFinished(board?: Board, port?: Port): Promise { this.isUploadInProgress = false; - - if (!board || !port) { - // We have no way of knowing which monitor - // to retrieve if we don't have this information. - return Status.NOT_CONNECTED; - } - const monitorID = this.monitorID(board, port); - const monitor = this.monitorServices.get(monitorID); - if (!monitor) { + let status: Status = Status.NOT_CONNECTED; + // We have no way of knowing which monitor + // to retrieve if we don't have this information. + if (board && port) { + const monitorID = this.monitorID(board, port); + const monitor = this.monitorServices.get(monitorID); // There's no monitor running there, bail - return Status.NOT_CONNECTED; + if (monitor) { + status = await monitor.start(); + } } - - return monitor.start(); + await this.startQueuedServices(); + return status; } async startQueuedServices(): Promise { From 97bdb78674a5459aef5d610f5ba75f6e98d681a5 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Thu, 16 Jun 2022 15:05:40 +0200 Subject: [PATCH 12/24] test cli with monitor close delay --- arduino-ide-extension/package.json | 6 +++++- arduino-ide-extension/src/node/core-service-impl.ts | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arduino-ide-extension/package.json b/arduino-ide-extension/package.json index 143c7d6c5..7e989e976 100644 --- a/arduino-ide-extension/package.json +++ b/arduino-ide-extension/package.json @@ -155,7 +155,11 @@ ], "arduino": { "cli": { - "version": "0.23.0" + "version": { + "owner": "cmaglie", + "repo": "arduino-cli", + "commitish": "small_delay_monitor_close" + } }, "fwuploader": { "version": "2.2.0" diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 2fa7ebc1f..2936f451d 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -182,7 +182,6 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { try { await this.monitorManager.notifyUploadStarted(board, port); - await new Promise((r) => setTimeout(r, 10000)); const result = responseHandler(client, req); From a562f0cbc415ff5234d126479ea80868e684d385 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:29:47 +0200 Subject: [PATCH 13/24] clean up unnecessary await(s) --- arduino-ide-extension/src/node/core-service-impl.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 2936f451d..3643c9060 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -112,8 +112,8 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { } } - async upload(options: CoreService.Upload.Options): Promise { - await this.doUpload( + upload(options: CoreService.Upload.Options): Promise { + return this.doUpload( options, () => new UploadRequest(), (client, req) => client.upload(req) @@ -123,7 +123,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { async uploadUsingProgrammer( options: CoreService.Upload.Options ): Promise { - await this.doUpload( + return this.doUpload( options, () => new UploadUsingProgrammerRequest(), (client, req) => client.uploadUsingProgrammer(req), @@ -224,7 +224,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { throw new Error(errorMessage); } finally { this.uploading = false; - await this.monitorManager.notifyUploadFinished(board, port); + this.monitorManager.notifyUploadFinished(board, port); } } @@ -288,7 +288,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { throw new Error(errorMessage); } finally { this.uploading = false; - await this.monitorManager.notifyUploadFinished(board, port); + this.monitorManager.notifyUploadFinished(board, port); } } From 725c0fbc959c3c84ecb01d9abdd473b80a7aaea6 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:50:50 +0200 Subject: [PATCH 14/24] remove unused dependency --- .../src/browser/contributions/upload-sketch.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index e673fcde0..6afeda21b 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -1,10 +1,6 @@ import { inject, injectable } from '@theia/core/shared/inversify'; import { Emitter } from '@theia/core/lib/common/event'; -import { - BoardUserField, - CoreService, - MonitorManagerProxyClient, -} from '../../common/protocol'; +import { BoardUserField, CoreService } from '../../common/protocol'; import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus'; import { ArduinoToolbar } from '../toolbar/arduino-toolbar'; import { BoardsDataStore } from '../boards/boards-data-store'; @@ -38,9 +34,6 @@ export class UploadSketch extends SketchContribution { @inject(UserFieldsDialog) protected readonly userFieldsDialog: UserFieldsDialog; - @inject(MonitorManagerProxyClient) - protected readonly monitorManagerProxyClient: MonitorManagerProxyClient; - protected cachedUserFields: Map = new Map(); protected readonly onDidChangeEmitter = new Emitter>(); From 6710f352c3c2f219e1c76315f550b2c148eb54f5 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 17 Jun 2022 14:48:27 +0200 Subject: [PATCH 15/24] revert CLI to 0.23 --- arduino-ide-extension/package.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arduino-ide-extension/package.json b/arduino-ide-extension/package.json index 7e989e976..143c7d6c5 100644 --- a/arduino-ide-extension/package.json +++ b/arduino-ide-extension/package.json @@ -155,11 +155,7 @@ ], "arduino": { "cli": { - "version": { - "owner": "cmaglie", - "repo": "arduino-cli", - "commitish": "small_delay_monitor_close" - } + "version": "0.23.0" }, "fwuploader": { "version": "2.2.0" From 5260a07979da6cda6b7c4545f62fcfdf392e4e32 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 17 Jun 2022 15:44:10 +0200 Subject: [PATCH 16/24] use master cli for testing, await in upload finish --- arduino-ide-extension/package.json | 6 +++++- .../src/node/arduino-firmware-uploader-impl.ts | 2 +- arduino-ide-extension/src/node/core-service-impl.ts | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arduino-ide-extension/package.json b/arduino-ide-extension/package.json index 143c7d6c5..76eada975 100644 --- a/arduino-ide-extension/package.json +++ b/arduino-ide-extension/package.json @@ -155,7 +155,11 @@ ], "arduino": { "cli": { - "version": "0.23.0" + "version": { + "owner": "arduino", + "repo": "arduino-cli", + "commitish": "master" + } }, "fwuploader": { "version": "2.2.0" diff --git a/arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts b/arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts index 78f444fe8..d693ce758 100644 --- a/arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts +++ b/arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts @@ -90,7 +90,7 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader { } catch (e) { throw e; } finally { - this.monitorManager.notifyUploadFinished(board, port); + await this.monitorManager.notifyUploadFinished(board, port); return output; } } diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 3643c9060..696eca7db 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -224,7 +224,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { throw new Error(errorMessage); } finally { this.uploading = false; - this.monitorManager.notifyUploadFinished(board, port); + await this.monitorManager.notifyUploadFinished(board, port); } } @@ -288,7 +288,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { throw new Error(errorMessage); } finally { this.uploading = false; - this.monitorManager.notifyUploadFinished(board, port); + await this.monitorManager.notifyUploadFinished(board, port); } } From 1678da744d8b2b35d34a375afca5e751e7dc483c Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 17 Jun 2022 17:08:08 +0200 Subject: [PATCH 17/24] remove upload port from pending monitor requests --- arduino-ide-extension/src/node/monitor-manager.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 09ac4f191..b000b940f 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -169,7 +169,9 @@ export class MonitorManager extends CoreClientAware { } async startQueuedServices(): Promise { - const queued = this.startMonitorPendingRequests; + // here we remove the first item as in all likelihood it's + // probably the port we used to perform an upload + const queued = this.startMonitorPendingRequests.slice(1); this.startMonitorPendingRequests = []; for (const [[board, port], onFinish] of queued) { From 37f731163d495280b6a368f906f734c32c0c4585 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 17 Jun 2022 18:23:37 +0200 Subject: [PATCH 18/24] fix startQueuedServices --- .../src/node/monitor-manager.ts | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index b000b940f..25e19f82a 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -154,24 +154,38 @@ export class MonitorManager extends CoreClientAware { async notifyUploadFinished(board?: Board, port?: Port): Promise { this.isUploadInProgress = false; let status: Status = Status.NOT_CONNECTED; + let monitorID; // We have no way of knowing which monitor // to retrieve if we don't have this information. if (board && port) { - const monitorID = this.monitorID(board, port); + monitorID = this.monitorID(board, port); const monitor = this.monitorServices.get(monitorID); // There's no monitor running there, bail if (monitor) { status = await monitor.start(); } } - await this.startQueuedServices(); + await this.startQueuedServices(monitorID); return status; } - async startQueuedServices(): Promise { - // here we remove the first item as in all likelihood it's - // probably the port we used to perform an upload - const queued = this.startMonitorPendingRequests.slice(1); + async startQueuedServices( + monitorIDRelatedToUploadBoard?: string // when upload initially requested + ): Promise { + let portDidChangeOnUpload = false; + if (monitorIDRelatedToUploadBoard) { + portDidChangeOnUpload = ![...this.monitorServices.keys()].includes( + monitorIDRelatedToUploadBoard + ); + } + // if we no longer have a monitor service for the "board, port" + // combination with which we called "notifyUploadStarted", we know + // the port changed during upload, hence in our "startMonitorPendingRequests" + // we'll have our "upload port', most likely at index 0. + // We remove it, as there will no longer be a board using this "upload port" + const queued = portDidChangeOnUpload + ? this.startMonitorPendingRequests.slice(1) + : this.startMonitorPendingRequests; this.startMonitorPendingRequests = []; for (const [[board, port], onFinish] of queued) { From 99dfd4e16ce14f2ad7a8dc2f5851fb3bcbdb0cb6 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 17 Jun 2022 20:09:45 +0200 Subject: [PATCH 19/24] refinements queued monitors --- .../src/node/monitor-manager.ts | 60 +++++++++++++------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 25e19f82a..3ec53d5c3 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -25,6 +25,9 @@ export class MonitorManager extends CoreClientAware { private monitorServices = new Map(); private isUploadInProgress: boolean; + private servicesPausedForUpload: MonitorID[] = []; + private servicesDisposedForUpload: MonitorID[] = []; + private startMonitorPendingRequests: [ [Board, Port], (status: Status) => void @@ -140,6 +143,8 @@ export class MonitorManager extends CoreClientAware { // There's no monitor running there, bail return; } + + this.servicesPausedForUpload.push(monitorID); return monitor.pause(); } @@ -154,35 +159,41 @@ export class MonitorManager extends CoreClientAware { async notifyUploadFinished(board?: Board, port?: Port): Promise { this.isUploadInProgress = false; let status: Status = Status.NOT_CONNECTED; - let monitorID; + let portDidChangeOnUpload = false; + // We have no way of knowing which monitor // to retrieve if we don't have this information. if (board && port) { - monitorID = this.monitorID(board, port); + const monitorID = this.monitorID(board, port); const monitor = this.monitorServices.get(monitorID); - // There's no monitor running there, bail if (monitor) { status = await monitor.start(); } + + // this monitorID will only be present in "servicesDisposedForUpload" + // if the upload changed the board port + portDidChangeOnUpload = + this.servicesDisposedForUpload.includes(monitorID); + if (portDidChangeOnUpload) { + this.servicesDisposedForUpload = this.servicesDisposedForUpload.filter( + (id) => id !== monitorID + ); + } + + // in case a service was paused but not disposed + this.servicesPausedForUpload = this.servicesPausedForUpload.filter( + (id) => id !== monitorID + ); } - await this.startQueuedServices(monitorID); + + await this.startQueuedServices(portDidChangeOnUpload); return status; } - async startQueuedServices( - monitorIDRelatedToUploadBoard?: string // when upload initially requested - ): Promise { - let portDidChangeOnUpload = false; - if (monitorIDRelatedToUploadBoard) { - portDidChangeOnUpload = ![...this.monitorServices.keys()].includes( - monitorIDRelatedToUploadBoard - ); - } - // if we no longer have a monitor service for the "board, port" - // combination with which we called "notifyUploadStarted", we know - // the port changed during upload, hence in our "startMonitorPendingRequests" - // we'll have our "upload port', most likely at index 0. - // We remove it, as there will no longer be a board using this "upload port" + async startQueuedServices(portDidChangeOnUpload: boolean): Promise { + // if the port changed during upload with the monitor open, "startMonitorPendingRequests" + // will include a request for our "upload port', most likely at index 0. + // We remove it, as this port was to be used exclusively for the upload const queued = portDidChangeOnUpload ? this.startMonitorPendingRequests.slice(1) : this.startMonitorPendingRequests; @@ -266,6 +277,19 @@ export class MonitorManager extends CoreClientAware { this.monitorServices.set(monitorID, monitor); monitor.onDispose( (() => { + // if a service is disposed during upload and + // we paused it beforehand we know it was disposed + // of because the upload changed the board port + if ( + this.isUploadInProgress && + this.servicesPausedForUpload.includes(monitorID) + ) { + this.servicesPausedForUpload = this.servicesPausedForUpload.filter( + (id) => id !== monitorID + ); + this.servicesDisposedForUpload.push(monitorID); + } + this.monitorServices.delete(monitorID); }).bind(this) ); From 6e264a6bcba30bdba3ac9ffb1df5355517598d35 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Fri, 17 Jun 2022 23:24:40 +0200 Subject: [PATCH 20/24] clean up monitor mgr state --- .../src/node/monitor-manager.ts | 95 ++++++++++++------- 1 file changed, 62 insertions(+), 33 deletions(-) diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 3ec53d5c3..f1cfea0c0 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -11,6 +11,9 @@ import { type MonitorID = string; +type UploadState = 'uploadInProgress' | 'pausedForUpload' | 'disposedForUpload'; +type MonitorIDsByUploadState = Record; + export const MonitorManagerName = 'monitor-manager'; @injectable() @@ -23,15 +26,17 @@ 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 servicesPausedForUpload: MonitorID[] = []; - private servicesDisposedForUpload: MonitorID[] = []; + private monitorIDsByUploadState: MonitorIDsByUploadState = { + uploadInProgress: [], + pausedForUpload: [], + disposedForUpload: [], + }; - private startMonitorPendingRequests: [ - [Board, Port], - (status: Status) => void - ][] = []; + private startMonitor_PendingRequests: { + requestFor: [Board, Port]; + postStartCallback: (status: Status) => void; + }[] = []; @inject(MonitorServiceFactory) private monitorServiceFactory: MonitorServiceFactory; @@ -60,6 +65,25 @@ export class MonitorManager extends CoreClientAware { return false; } + uploadIsInProgress(): boolean { + return this.monitorIDsByUploadState.uploadInProgress.length > 0; + } + + addToMonitorIDsByUploadState(state: UploadState, monitorID: string): void { + this.monitorIDsByUploadState[state].push(monitorID); + } + + removeFromMonitorIDsByUploadState( + state: UploadState, + monitorID: string + ): void { + this.monitorIDsByUploadState[state].filter((id) => id !== monitorID); + } + + monitorIDIsInUploadState(state: UploadState, monitorID: string): boolean { + return this.monitorIDsByUploadState[state].includes(monitorID); + } + /** * Start a pluggable monitor that receives and sends messages * to the specified board and port combination. @@ -80,8 +104,11 @@ export class MonitorManager extends CoreClientAware { monitor = this.createMonitor(board, port); } - if (this.isUploadInProgress) { - this.startMonitorPendingRequests.push([[board, port], postStartCallback]); + if (this.uploadIsInProgress()) { + this.startMonitor_PendingRequests.push({ + requestFor: [board, port], + postStartCallback, + }); return; } @@ -130,21 +157,22 @@ export class MonitorManager extends CoreClientAware { * @param port port to monitor */ async notifyUploadStarted(board?: Board, port?: Port): Promise { - this.isUploadInProgress = true; - if (!board || !port) { // We have no way of knowing which monitor // to retrieve if we don't have this information. return; } + const monitorID = this.monitorID(board, port); + this.addToMonitorIDsByUploadState('uploadInProgress', monitorID); + const monitor = this.monitorServices.get(monitorID); if (!monitor) { // There's no monitor running there, bail return; } - this.servicesPausedForUpload.push(monitorID); + this.addToMonitorIDsByUploadState('pausedForUpload', monitorID); return monitor.pause(); } @@ -157,7 +185,6 @@ export class MonitorManager extends CoreClientAware { * started or if there have been errors. */ async notifyUploadFinished(board?: Board, port?: Port): Promise { - this.isUploadInProgress = false; let status: Status = Status.NOT_CONNECTED; let portDidChangeOnUpload = false; @@ -165,25 +192,25 @@ export class MonitorManager extends CoreClientAware { // to retrieve if we don't have this information. if (board && port) { const monitorID = this.monitorID(board, port); + this.removeFromMonitorIDsByUploadState('uploadInProgress', monitorID); + const monitor = this.monitorServices.get(monitorID); if (monitor) { status = await monitor.start(); } - // this monitorID will only be present in "servicesDisposedForUpload" + // this monitorID will only be present in "disposedForUpload" // if the upload changed the board port - portDidChangeOnUpload = - this.servicesDisposedForUpload.includes(monitorID); + portDidChangeOnUpload = this.monitorIDIsInUploadState( + 'disposedForUpload', + monitorID + ); if (portDidChangeOnUpload) { - this.servicesDisposedForUpload = this.servicesDisposedForUpload.filter( - (id) => id !== monitorID - ); + this.removeFromMonitorIDsByUploadState('disposedForUpload', monitorID); } // in case a service was paused but not disposed - this.servicesPausedForUpload = this.servicesPausedForUpload.filter( - (id) => id !== monitorID - ); + this.removeFromMonitorIDsByUploadState('pausedForUpload', monitorID); } await this.startQueuedServices(portDidChangeOnUpload); @@ -195,11 +222,14 @@ export class MonitorManager extends CoreClientAware { // will include a request for our "upload port', most likely at index 0. // We remove it, as this port was to be used exclusively for the upload const queued = portDidChangeOnUpload - ? this.startMonitorPendingRequests.slice(1) - : this.startMonitorPendingRequests; - this.startMonitorPendingRequests = []; - - for (const [[board, port], onFinish] of queued) { + ? this.startMonitor_PendingRequests.slice(1) + : this.startMonitor_PendingRequests; + this.startMonitor_PendingRequests = []; + + for (const { + requestFor: [board, port], + postStartCallback: onFinish, + } of queued) { const boardsState = await this.boardsService.getState(); const boardIsStillOnPort = Object.keys(boardsState) .map((connection: string) => { @@ -281,13 +311,12 @@ export class MonitorManager extends CoreClientAware { // we paused it beforehand we know it was disposed // of because the upload changed the board port if ( - this.isUploadInProgress && - this.servicesPausedForUpload.includes(monitorID) + this.uploadIsInProgress() && + this.monitorIDIsInUploadState('pausedForUpload', monitorID) ) { - this.servicesPausedForUpload = this.servicesPausedForUpload.filter( - (id) => id !== monitorID - ); - this.servicesDisposedForUpload.push(monitorID); + this.removeFromMonitorIDsByUploadState('pausedForUpload', monitorID); + + this.addToMonitorIDsByUploadState('disposedForUpload', monitorID); } this.monitorServices.delete(monitorID); From c892ce3df2c2b07b8dbc6e20f9c0b0383b098660 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Sun, 19 Jun 2022 07:01:33 +0200 Subject: [PATCH 21/24] fix typo from prev cleanup --- arduino-ide-extension/src/node/monitor-manager.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index f1cfea0c0..0302bbac8 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -77,7 +77,9 @@ export class MonitorManager extends CoreClientAware { state: UploadState, monitorID: string ): void { - this.monitorIDsByUploadState[state].filter((id) => id !== monitorID); + this.monitorIDsByUploadState[state] = this.monitorIDsByUploadState[ + state + ].filter((id) => id !== monitorID); } monitorIDIsInUploadState(state: UploadState, monitorID: string): boolean { From a7c8806da1ee2a30e346a71212bbdd8d73b907c8 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Sun, 19 Jun 2022 07:42:35 +0200 Subject: [PATCH 22/24] avoid dupl queued monitor services --- arduino-ide-extension/src/node/monitor-manager.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index 0302bbac8..d012ac93c 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -34,6 +34,7 @@ export class MonitorManager extends CoreClientAware { }; private startMonitor_PendingRequests: { + monitorID: string; requestFor: [Board, Port]; postStartCallback: (status: Status) => void; }[] = []; @@ -107,10 +108,17 @@ export class MonitorManager extends CoreClientAware { } if (this.uploadIsInProgress()) { + this.startMonitor_PendingRequests = + this.startMonitor_PendingRequests.filter( + (request) => request.monitorID !== monitorID + ); + this.startMonitor_PendingRequests.push({ + monitorID, requestFor: [board, port], postStartCallback, }); + return; } @@ -229,7 +237,8 @@ export class MonitorManager extends CoreClientAware { this.startMonitor_PendingRequests = []; for (const { - requestFor: [board, port], + monitorID, + requestFor: [_, port], postStartCallback: onFinish, } of queued) { const boardsState = await this.boardsService.getState(); @@ -241,7 +250,6 @@ export class MonitorManager extends CoreClientAware { .some((portAddress: string) => port.address === portAddress); if (boardIsStillOnPort) { - const monitorID = this.monitorID(board, port); const monitorService = this.monitorServices.get(monitorID); if (monitorService) { From 3830ba2112d4245ed41b2fc1f1f7cf5c3e97c82c Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Tue, 21 Jun 2022 17:00:22 +0200 Subject: [PATCH 23/24] variable name changes --- .../src/node/monitor-manager-proxy-impl.ts | 4 +- .../src/node/monitor-manager.ts | 49 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts b/arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts index f71f6c345..7f284ac3f 100644 --- a/arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts +++ b/arduino-ide-extension/src/node/monitor-manager-proxy-impl.ts @@ -41,13 +41,13 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy { await this.changeMonitorSettings(board, port, settings); } - const onFinish = (status: Status) => { + const connectToClient = (status: Status) => { if (status === Status.ALREADY_CONNECTED || status === Status.OK) { // Monitor started correctly, connect it with the frontend this.client.connect(this.manager.getWebsocketAddressPort(board, port)); } }; - return this.manager.startMonitor(board, port, onFinish); + return this.manager.startMonitor(board, port, connectToClient); } /** diff --git a/arduino-ide-extension/src/node/monitor-manager.ts b/arduino-ide-extension/src/node/monitor-manager.ts index d012ac93c..fc458a49c 100644 --- a/arduino-ide-extension/src/node/monitor-manager.ts +++ b/arduino-ide-extension/src/node/monitor-manager.ts @@ -33,10 +33,10 @@ export class MonitorManager extends CoreClientAware { disposedForUpload: [], }; - private startMonitor_PendingRequests: { + private monitorServiceStartQueue: { monitorID: string; - requestFor: [Board, Port]; - postStartCallback: (status: Status) => void; + serviceStartParams: [Board, Port]; + connectToClient: (status: Status) => void; }[] = []; @inject(MonitorServiceFactory) @@ -66,15 +66,18 @@ export class MonitorManager extends CoreClientAware { return false; } - uploadIsInProgress(): boolean { + private uploadIsInProgress(): boolean { return this.monitorIDsByUploadState.uploadInProgress.length > 0; } - addToMonitorIDsByUploadState(state: UploadState, monitorID: string): void { + private addToMonitorIDsByUploadState( + state: UploadState, + monitorID: string + ): void { this.monitorIDsByUploadState[state].push(monitorID); } - removeFromMonitorIDsByUploadState( + private removeFromMonitorIDsByUploadState( state: UploadState, monitorID: string ): void { @@ -83,7 +86,10 @@ export class MonitorManager extends CoreClientAware { ].filter((id) => id !== monitorID); } - monitorIDIsInUploadState(state: UploadState, monitorID: string): boolean { + private monitorIDIsInUploadState( + state: UploadState, + monitorID: string + ): boolean { return this.monitorIDsByUploadState[state].includes(monitorID); } @@ -98,7 +104,7 @@ export class MonitorManager extends CoreClientAware { async startMonitor( board: Board, port: Port, - postStartCallback: (status: Status) => void + connectToClient: (status: Status) => void ): Promise { const monitorID = this.monitorID(board, port); @@ -108,22 +114,21 @@ export class MonitorManager extends CoreClientAware { } if (this.uploadIsInProgress()) { - this.startMonitor_PendingRequests = - this.startMonitor_PendingRequests.filter( - (request) => request.monitorID !== monitorID - ); + this.monitorServiceStartQueue = this.monitorServiceStartQueue.filter( + (request) => request.monitorID !== monitorID + ); - this.startMonitor_PendingRequests.push({ + this.monitorServiceStartQueue.push({ monitorID, - requestFor: [board, port], - postStartCallback, + serviceStartParams: [board, port], + connectToClient, }); return; } const result = await monitor.start(); - postStartCallback(result); + connectToClient(result); } /** @@ -232,14 +237,14 @@ export class MonitorManager extends CoreClientAware { // will include a request for our "upload port', most likely at index 0. // We remove it, as this port was to be used exclusively for the upload const queued = portDidChangeOnUpload - ? this.startMonitor_PendingRequests.slice(1) - : this.startMonitor_PendingRequests; - this.startMonitor_PendingRequests = []; + ? this.monitorServiceStartQueue.slice(1) + : this.monitorServiceStartQueue; + this.monitorServiceStartQueue = []; for (const { monitorID, - requestFor: [_, port], - postStartCallback: onFinish, + serviceStartParams: [_, port], + connectToClient, } of queued) { const boardsState = await this.boardsService.getState(); const boardIsStillOnPort = Object.keys(boardsState) @@ -254,7 +259,7 @@ export class MonitorManager extends CoreClientAware { if (monitorService) { const result = await monitorService.start(); - onFinish(result); + connectToClient(result); } } } From 095bbd9545853df96e5f2b6329677068f275b535 Mon Sep 17 00:00:00 2001 From: David Simpson <45690499+davegarthsimpson@users.noreply.github.com> Date: Tue, 21 Jun 2022 18:16:09 +0200 Subject: [PATCH 24/24] reference latest cli commit in package.json --- arduino-ide-extension/package.json | 2 +- .../src/browser/contributions/upload-sketch.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arduino-ide-extension/package.json b/arduino-ide-extension/package.json index 76eada975..5361bcb30 100644 --- a/arduino-ide-extension/package.json +++ b/arduino-ide-extension/package.json @@ -158,7 +158,7 @@ "version": { "owner": "arduino", "repo": "arduino-cli", - "commitish": "master" + "commitish": "c1b10f562f1e1a112e215a69b84e2f2b69e3af2d" } }, "fwuploader": { diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index b1ca556af..ebfd02c6d 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -281,7 +281,6 @@ export class UploadSketch extends CoreServiceContribution { this.handleError(e); } finally { this.uploadInProgress = false; - this.onDidChangeEmitter.fire(); } }