Skip to content

Commit eed8a69

Browse files
move upload failure fix logic to frontend
1 parent d10181b commit eed8a69

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { inject, injectable } from '@theia/core/shared/inversify';
22
import { Emitter } from '@theia/core/lib/common/event';
3-
import { BoardUserField, CoreService } from '../../common/protocol';
3+
import {
4+
BoardUserField,
5+
CoreService,
6+
MonitorManagerProxyClient,
7+
} from '../../common/protocol';
48
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
59
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
610
import { BoardsDataStore } from '../boards/boards-data-store';
@@ -34,6 +38,9 @@ export class UploadSketch extends SketchContribution {
3438
@inject(UserFieldsDialog)
3539
protected readonly userFieldsDialog: UserFieldsDialog;
3640

41+
@inject(MonitorManagerProxyClient)
42+
protected readonly monitorManagerProxyClient: MonitorManagerProxyClient;
43+
3744
protected cachedUserFields: Map<string, BoardUserField[]> = new Map();
3845

3946
protected readonly onDidChangeEmitter = new Emitter<Readonly<void>>();
@@ -204,6 +211,13 @@ export class UploadSketch extends SketchContribution {
204211
// toggle the toolbar button and menu item state.
205212
// uploadInProgress will be set to false whether the upload fails or not
206213
this.uploadInProgress = true;
214+
215+
// here we inform the "monitorManagerProxyClient" an upload is in progress,
216+
// setting a boolean flag, this is to prevent triggering of the
217+
// "usual side effects" if a serial port change occurs during upload
218+
// (expected on windows for some boards)
219+
this.monitorManagerProxyClient.setUploadInProgress(true);
220+
207221
this.onDidChangeEmitter.fire();
208222
const sketch = await this.sketchServiceClient.currentSketch();
209223
if (!CurrentSketch.isValid(sketch)) {
@@ -227,7 +241,7 @@ export class UploadSketch extends SketchContribution {
227241
...boardsConfig.selectedBoard,
228242
name: boardsConfig.selectedBoard?.name || '',
229243
fqbn,
230-
}
244+
};
231245
let options: CoreService.Upload.Options | undefined = undefined;
232246
const sketchUri = sketch.uri;
233247
const optimizeForDebug = this.editorMode.compileForDebug;
@@ -290,6 +304,9 @@ export class UploadSketch extends SketchContribution {
290304
this.messageService.error(errorMessage);
291305
} finally {
292306
this.uploadInProgress = false;
307+
308+
this.monitorManagerProxyClient.setUploadInProgress(false);
309+
293310
this.onDidChangeEmitter.fire();
294311
}
295312
}

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

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

50+
private uploadInProgress = false;
51+
5052
getWebSocketPort(): number | undefined {
5153
return this.wsPort;
5254
}
@@ -135,7 +137,9 @@ export class MonitorManagerProxyClientImpl
135137
this.onBoardsConfigChanged =
136138
this.boardsServiceProvider.onBoardsConfigChanged(
137139
async ({ selectedBoard, selectedPort }) => {
140+
const changeTriggeredDuringUpload = this.uploadInProgress;
138141
if (
142+
changeTriggeredDuringUpload ||
139143
typeof selectedBoard === 'undefined' ||
140144
typeof selectedPort === 'undefined'
141145
)
@@ -196,4 +200,8 @@ export class MonitorManagerProxyClientImpl
196200
})
197201
);
198202
}
203+
204+
public setUploadInProgress(value: boolean): void {
205+
this.uploadInProgress = value;
206+
}
199207
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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;
4243
}
4344

4445
export interface PluggableMonitorSetting {

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export class MonitorManager extends CoreClientAware {
2424
@inject(MonitorServiceFactory)
2525
private monitorServiceFactory: MonitorServiceFactory;
2626

27-
uploading = false;
28-
2927
constructor(
3028
@inject(ILogger)
3129
@named(MonitorManagerName)
@@ -59,9 +57,6 @@ export class MonitorManager extends CoreClientAware {
5957
* started or if there have been errors.
6058
*/
6159
async startMonitor(board: Board, port: Port): Promise<Status> {
62-
if (this.uploading) {
63-
return Status.UPLOAD_IN_PROGRESS;
64-
}
6560
const monitorID = this.monitorID(board, port);
6661
let monitor = this.monitorServices.get(monitorID);
6762
if (!monitor) {
@@ -111,7 +106,6 @@ export class MonitorManager extends CoreClientAware {
111106
* @param port port to monitor
112107
*/
113108
async notifyUploadStarted(board?: Board, port?: Port): Promise<void> {
114-
this.uploading = true;
115109
if (!board || !port) {
116110
// We have no way of knowing which monitor
117111
// to retrieve if we don't have this information.
@@ -136,7 +130,6 @@ export class MonitorManager extends CoreClientAware {
136130
* started or if there have been errors.
137131
*/
138132
async notifyUploadFinished(board?: Board, port?: Port): Promise<Status> {
139-
this.uploading = false;
140133
if (!board || !port) {
141134
// We have no way of knowing which monitor
142135
// to retrieve if we don't have this information.

0 commit comments

Comments
 (0)