Skip to content

Commit 02da1c6

Browse files
author
Akos Kitta
committed
fix: monitor widget unnecessary updates
Signed-off-by: Akos Kitta <[email protected]>
1 parent 607b97d commit 02da1c6

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -496,15 +496,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
496496
bind(TabBarToolbarContribution).toService(MonitorViewContribution);
497497
bind(WidgetFactory).toDynamicValue((context) => ({
498498
id: MonitorWidget.ID,
499-
createWidget: () => {
500-
return new MonitorWidget(
501-
context.container.get<MonitorModel>(MonitorModel),
502-
context.container.get<MonitorManagerProxyClient>(
503-
MonitorManagerProxyClient
504-
),
505-
context.container.get<BoardsServiceProvider>(BoardsServiceProvider)
506-
);
507-
},
499+
createWidget: () => context.container.get(MonitorWidget),
508500
}));
509501

510502
bind(MonitorManagerProxyFactory).toFactory(

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class MonitorManagerProxyClientImpl
3939
readonly onMonitorSettingsDidChange =
4040
this.onMonitorSettingsDidChangeEmitter.event;
4141

42-
protected readonly onMonitorShouldResetEmitter = new Emitter();
42+
protected readonly onMonitorShouldResetEmitter = new Emitter<void>();
4343
readonly onMonitorShouldReset = this.onMonitorShouldResetEmitter.event;
4444

4545
// WebSocket used to handle pluggable monitor communication between
@@ -132,6 +132,7 @@ export class MonitorManagerProxyClientImpl
132132
}
133133

134134
async startMonitor(settings?: PluggableMonitorSettings): Promise<void> {
135+
await this.boardsServiceProvider.reconciled;
135136
this.lastConnectedBoard = {
136137
selectedBoard: this.boardsServiceProvider.boardsConfig.selectedBoard,
137138
selectedPort: this.boardsServiceProvider.boardsConfig.selectedPort,
@@ -156,7 +157,7 @@ export class MonitorManagerProxyClientImpl
156157
? Port.keyOf(this.lastConnectedBoard.selectedPort)
157158
: undefined)
158159
) {
159-
this.onMonitorShouldResetEmitter.fire(null);
160+
this.onMonitorShouldResetEmitter.fire();
160161
this.lastConnectedBoard = {
161162
selectedBoard: selectedBoard,
162163
selectedPort: selectedPort,

Diff for: arduino-ide-extension/src/browser/serial/monitor/monitor-widget.tsx

+41-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as React from '@theia/core/shared/react';
2-
import { injectable, inject } from '@theia/core/shared/inversify';
2+
import {
3+
injectable,
4+
inject,
5+
postConstruct,
6+
} from '@theia/core/shared/inversify';
37
import { Emitter } from '@theia/core/lib/common/event';
48
import { Disposable } from '@theia/core/lib/common/disposable';
59
import {
@@ -19,6 +23,7 @@ import {
1923
} from '../../../common/protocol';
2024
import { MonitorModel } from '../../monitor-model';
2125
import { MonitorSettings } from '../../../node/monitor-settings/monitor-settings-provider';
26+
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
2227

2328
@injectable()
2429
export class MonitorWidget extends ReactWidget {
@@ -43,40 +48,38 @@ export class MonitorWidget extends ReactWidget {
4348
protected closing = false;
4449
protected readonly clearOutputEmitter = new Emitter<void>();
4550

46-
constructor(
47-
@inject(MonitorModel)
48-
protected readonly monitorModel: MonitorModel,
49-
50-
@inject(MonitorManagerProxyClient)
51-
protected readonly monitorManagerProxy: MonitorManagerProxyClient,
51+
@inject(MonitorModel)
52+
private readonly monitorModel: MonitorModel;
53+
@inject(MonitorManagerProxyClient)
54+
private readonly monitorManagerProxy: MonitorManagerProxyClient;
55+
@inject(BoardsServiceProvider)
56+
private readonly boardsServiceProvider: BoardsServiceProvider;
57+
@inject(FrontendApplicationStateService)
58+
private readonly appStateService: FrontendApplicationStateService;
5259

53-
@inject(BoardsServiceProvider)
54-
protected readonly boardsServiceProvider: BoardsServiceProvider
55-
) {
60+
constructor() {
5661
super();
5762
this.id = MonitorWidget.ID;
5863
this.title.label = MonitorWidget.LABEL;
5964
this.title.iconClass = 'monitor-tab-icon';
6065
this.title.closable = true;
6166
this.scrollOptions = undefined;
6267
this.toDispose.push(this.clearOutputEmitter);
63-
this.toDispose.push(
64-
Disposable.create(() => this.monitorManagerProxy.disconnect())
65-
);
6668
}
6769

68-
protected override onBeforeAttach(msg: Message): void {
69-
this.update();
70-
this.toDispose.push(this.monitorModel.onChange(() => this.update()));
71-
this.getCurrentSettings().then(this.onMonitorSettingsDidChange.bind(this));
72-
this.monitorManagerProxy.onMonitorSettingsDidChange(
73-
this.onMonitorSettingsDidChange.bind(this)
74-
);
75-
76-
this.monitorManagerProxy.startMonitor();
70+
@postConstruct()
71+
protected init(): void {
72+
this.toDispose.pushAll([
73+
Disposable.create(() => this.monitorManagerProxy.disconnect()),
74+
this.monitorModel.onChange(() => this.update()),
75+
this.monitorManagerProxy.onMonitorSettingsDidChange((event) =>
76+
this.updateSettings(event)
77+
),
78+
]);
79+
this.startMonitor();
7780
}
7881

79-
onMonitorSettingsDidChange(settings: MonitorSettings): void {
82+
private updateSettings(settings: MonitorSettings): void {
8083
this.settings = {
8184
...this.settings,
8285
pluggableMonitorSettings: {
@@ -92,10 +95,6 @@ export class MonitorWidget extends ReactWidget {
9295
this.update();
9396
}
9497

95-
override dispose(): void {
96-
super.dispose();
97-
}
98-
9998
protected override onCloseRequest(msg: Message): void {
10099
this.closing = true;
101100
super.onCloseRequest(msg);
@@ -125,7 +124,7 @@ export class MonitorWidget extends ReactWidget {
125124
this.update();
126125
}
127126

128-
protected onFocusResolved = (element: HTMLElement | undefined) => {
127+
protected onFocusResolved = (element: HTMLElement | undefined): void => {
129128
if (this.closing || !this.isAttached) {
130129
return;
131130
}
@@ -159,17 +158,28 @@ export class MonitorWidget extends ReactWidget {
159158
];
160159
}
161160

162-
private getCurrentSettings(): Promise<MonitorSettings> {
161+
private async startMonitor(): Promise<void> {
162+
await this.appStateService.reachedState('ready');
163+
await this.boardsServiceProvider.reconciled;
164+
await this.syncSettings();
165+
await this.monitorManagerProxy.startMonitor();
166+
}
167+
168+
private async syncSettings(): Promise<void> {
169+
const settings = await this.getCurrentSettings();
170+
this.updateSettings(settings);
171+
}
172+
173+
private async getCurrentSettings(): Promise<MonitorSettings> {
163174
const board = this.boardsServiceProvider.boardsConfig.selectedBoard;
164175
const port = this.boardsServiceProvider.boardsConfig.selectedPort;
165176
if (!board || !port) {
166-
return Promise.resolve(this.settings || {});
177+
return this.settings || {};
167178
}
168179
return this.monitorManagerProxy.getCurrentSettings(board, port);
169180
}
170181

171182
protected render(): React.ReactNode {
172-
debugger;
173183
const baudrate = this.settings?.pluggableMonitorSettings
174184
? this.settings.pluggableMonitorSettings.baudrate
175185
: undefined;

0 commit comments

Comments
 (0)