Skip to content

Commit 29a4ed4

Browse files
author
Alberto Iannaccone
committed
reset serial monitor when port changes
1 parent 7daad3b commit 29a4ed4

File tree

3 files changed

+76
-22
lines changed

3 files changed

+76
-22
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import '../../src/browser/style/index.css';
22
import { ContainerModule } from 'inversify';
33
import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
4-
import { CommandContribution } from '@theia/core/lib/common/command';
4+
import {
5+
CommandContribution,
6+
CommandRegistry,
7+
} from '@theia/core/lib/common/command';
58
import { bindViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
69
import {
710
TabBarToolbarContribution,
@@ -152,7 +155,14 @@ import {
152155
OutputChannelRegistryMainImpl as TheiaOutputChannelRegistryMainImpl,
153156
OutputChannelRegistryMainImpl,
154157
} from './theia/plugin-ext/output-channel-registry-main';
155-
import { ExecutableService, ExecutableServicePath, MonitorManagerProxy, MonitorManagerProxyClient, MonitorManagerProxyFactory, MonitorManagerProxyPath } from '../common/protocol';
158+
import {
159+
ExecutableService,
160+
ExecutableServicePath,
161+
MonitorManagerProxy,
162+
MonitorManagerProxyClient,
163+
MonitorManagerProxyFactory,
164+
MonitorManagerProxyPath,
165+
} from '../common/protocol';
156166
import { MonacoTextModelService as TheiaMonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
157167
import { MonacoTextModelService } from './theia/monaco/monaco-text-model-service';
158168
import { ResponseServiceImpl } from './response-service-impl';
@@ -411,21 +421,35 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
411421
createWidget: () => {
412422
return new MonitorWidget(
413423
context.container.get<MonitorModel>(MonitorModel),
414-
context.container.get<MonitorManagerProxyClient>(MonitorManagerProxyClient),
424+
context.container.get<MonitorManagerProxyClient>(
425+
MonitorManagerProxyClient
426+
),
415427
context.container.get<BoardsServiceProvider>(BoardsServiceProvider),
428+
context.container.get<CommandRegistry>(CommandRegistry)
416429
);
417-
}
430+
},
418431
}));
419432

420-
bind(MonitorManagerProxyFactory).toFactory((context) => () => context.container.get<MonitorManagerProxy>(MonitorManagerProxy))
433+
bind(MonitorManagerProxyFactory).toFactory(
434+
(context) => () =>
435+
context.container.get<MonitorManagerProxy>(MonitorManagerProxy)
436+
);
421437

422-
bind(MonitorManagerProxy).toDynamicValue((context) =>
423-
WebSocketConnectionProvider.createProxy(context.container, MonitorManagerProxyPath, context.container.get(MonitorManagerProxyClient))
424-
).inSingletonScope();
438+
bind(MonitorManagerProxy)
439+
.toDynamicValue((context) =>
440+
WebSocketConnectionProvider.createProxy(
441+
context.container,
442+
MonitorManagerProxyPath,
443+
context.container.get(MonitorManagerProxyClient)
444+
)
445+
)
446+
.inSingletonScope();
425447

426448
// Monitor manager proxy client to receive and delegate pluggable monitors
427449
// notifications from the backend
428-
bind(MonitorManagerProxyClient).to(MonitorManagerProxyClientImpl).inSingletonScope();
450+
bind(MonitorManagerProxyClient)
451+
.to(MonitorManagerProxyClientImpl)
452+
.inSingletonScope();
429453

430454
bind(WorkspaceService).toSelf().inSingletonScope();
431455
rebind(TheiaWorkspaceService).toService(WorkspaceService);
@@ -482,11 +506,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
482506
.inSingletonScope();
483507
rebind(TheiaEditorWidgetFactory).to(EditorWidgetFactory).inSingletonScope();
484508
rebind(TabBarToolbarFactory).toFactory(
485-
({ container: parentContainer }) => () => {
486-
const container = parentContainer.createChild();
487-
container.bind(TabBarToolbar).toSelf().inSingletonScope();
488-
return container.get(TabBarToolbar);
489-
}
509+
({ container: parentContainer }) =>
510+
() => {
511+
const container = parentContainer.createChild();
512+
container.bind(TabBarToolbar).toSelf().inSingletonScope();
513+
return container.get(TabBarToolbar);
514+
}
490515
);
491516
bind(OutputWidget).toSelf().inSingletonScope();
492517
rebind(TheiaOutputWidget).toService(OutputWidget);
@@ -651,15 +676,13 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
651676

652677
// Enable the dirty indicator on uncloseable widgets.
653678
rebind(TabBarRendererFactory).toFactory((context) => () => {
654-
const contextMenuRenderer = context.container.get<ContextMenuRenderer>(
655-
ContextMenuRenderer
656-
);
679+
const contextMenuRenderer =
680+
context.container.get<ContextMenuRenderer>(ContextMenuRenderer);
657681
const decoratorService = context.container.get<TabBarDecoratorService>(
658682
TabBarDecoratorService
659683
);
660-
const iconThemeService = context.container.get<IconThemeService>(
661-
IconThemeService
662-
);
684+
const iconThemeService =
685+
context.container.get<IconThemeService>(IconThemeService);
663686
return new TabBarRenderer(
664687
contextMenuRenderer,
665688
decoratorService,

arduino-ide-extension/src/browser/serial/monitor/monitor-view-contribution.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class MonitorViewContribution
4747
static readonly TOGGLE_SERIAL_MONITOR = MonitorWidget.ID + ':toggle';
4848
static readonly TOGGLE_SERIAL_MONITOR_TOOLBAR =
4949
MonitorWidget.ID + ':toggle-toolbar';
50+
static readonly RESET_SERIAL_MONITOR = MonitorWidget.ID + ':reset';
5051

5152
@inject(MonitorModel)
5253
protected readonly model: MonitorModel;
@@ -119,6 +120,10 @@ export class MonitorViewContribution
119120
}
120121
);
121122
}
123+
commands.registerCommand(
124+
{ id: MonitorViewContribution.RESET_SERIAL_MONITOR },
125+
{ execute: () => this.reset() }
126+
);
122127
}
123128

124129
protected async toggle(): Promise<void> {
@@ -130,6 +135,12 @@ export class MonitorViewContribution
130135
}
131136
}
132137

138+
protected async reset(): Promise<void> {
139+
const widget = this.tryGetWidget();
140+
if (widget) widget.dispose();
141+
await this.openView({ activate: true, reveal: true });
142+
}
143+
133144
protected renderAutoScrollButton(): React.ReactNode {
134145
return (
135146
<React.Fragment key="autoscroll-toolbar-item">

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import { ArduinoSelect } from '../../widgets/arduino-select';
1313
import { SerialMonitorSendInput } from './serial-monitor-send-input';
1414
import { SerialMonitorOutput } from './serial-monitor-send-output';
1515
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
16-
import { nls } from '@theia/core/lib/common';
16+
import { CommandRegistry, nls } from '@theia/core/lib/common';
1717
import { MonitorManagerProxyClient } from '../../../common/protocol';
1818
import { MonitorModel } from '../../monitor-model';
1919
import { MonitorSettings } from '../../../node/monitor-settings/monitor-settings-provider';
20+
import { MonitorViewContribution } from './monitor-view-contribution';
21+
import { BoardsConfig } from '../../boards/boards-config';
2022

2123
@injectable()
2224
export class MonitorWidget extends ReactWidget {
@@ -41,6 +43,8 @@ export class MonitorWidget extends ReactWidget {
4143
protected closing = false;
4244
protected readonly clearOutputEmitter = new Emitter<void>();
4345

46+
protected lastConnectedBoard: BoardsConfig.Config;
47+
4448
constructor(
4549
@inject(MonitorModel)
4650
protected readonly monitorModel: MonitorModel,
@@ -49,7 +53,10 @@ export class MonitorWidget extends ReactWidget {
4953
protected readonly monitorManagerProxy: MonitorManagerProxyClient,
5054

5155
@inject(BoardsServiceProvider)
52-
protected readonly boardsServiceProvider: BoardsServiceProvider
56+
protected readonly boardsServiceProvider: BoardsServiceProvider,
57+
58+
@inject(CommandRegistry)
59+
protected readonly commandRegistry: CommandRegistry
5360
) {
5461
super();
5562
this.id = MonitorWidget.ID;
@@ -77,6 +84,19 @@ export class MonitorWidget extends ReactWidget {
7784
selectedBoard,
7885
selectedPort
7986
);
87+
88+
if (
89+
selectedBoard.fqbn !==
90+
this.lastConnectedBoard?.selectedBoard?.fqbn ||
91+
selectedPort.id !== this.lastConnectedBoard?.selectedPort?.id
92+
)
93+
await this.commandRegistry.executeCommand(
94+
MonitorViewContribution.RESET_SERIAL_MONITOR
95+
);
96+
this.lastConnectedBoard = {
97+
selectedBoard,
98+
selectedPort,
99+
};
80100
this.update();
81101
}
82102
}

0 commit comments

Comments
 (0)