Skip to content

Commit 557ec2a

Browse files
author
Akos Kitta
committed
Wait until the boards config has been reset
from the local storage, then start the monitor connection. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 8c49c04 commit 557ec2a

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
119119
}).inSingletonScope();
120120
// Boards service client to receive and delegate notifications from the backend.
121121
bind(BoardsServiceClientImpl).toSelf().inSingletonScope();
122+
bind(FrontendApplicationContribution).toService(BoardsServiceClientImpl);
122123
bind(BoardsServiceClient).toDynamicValue(context => {
123124
const client = context.container.get(BoardsServiceClientImpl);
124125
WebSocketConnectionProvider.createProxy(context.container, BoardsServicePath, client);

arduino-ide-extension/src/browser/boards/boards-service-client-impl.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { injectable, inject, postConstruct } from 'inversify';
1+
import { injectable, inject } from 'inversify';
22
import { Emitter } from '@theia/core/lib/common/event';
33
import { ILogger } from '@theia/core/lib/common/logger';
4+
import { MessageService } from '@theia/core/lib/common/message-service';
45
import { LocalStorageService } from '@theia/core/lib/browser/storage-service';
6+
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
57
import { RecursiveRequired } from '../../common/types';
68
import { BoardsServiceClient, AttachedBoardsChangeEvent, BoardInstalledEvent, AttachedSerialBoard, Board, Port, BoardUninstalledEvent } from '../../common/protocol/boards-service';
79
import { BoardsConfig } from './boards-config';
8-
import { MessageService } from '@theia/core';
910

1011
@injectable()
11-
export class BoardsServiceClientImpl implements BoardsServiceClient {
12+
export class BoardsServiceClientImpl implements BoardsServiceClient, FrontendApplicationContribution {
1213

1314
@inject(ILogger)
1415
protected logger: ILogger;
@@ -39,9 +40,8 @@ export class BoardsServiceClientImpl implements BoardsServiceClient {
3940
readonly onBoardUninstalled = this.onBoardUninstalledEmitter.event;
4041
readonly onBoardsConfigChanged = this.onSelectedBoardsConfigChangedEmitter.event;
4142

42-
@postConstruct()
43-
protected init(): void {
44-
this.loadState();
43+
async onStart(): Promise<void> {
44+
return this.loadState();
4545
}
4646

4747
notifyAttachedBoardsChanged(event: AttachedBoardsChangeEvent): void {
@@ -124,7 +124,7 @@ export class BoardsServiceClientImpl implements BoardsServiceClient {
124124

125125
if (!config.selectedBoard) {
126126
if (!options.silent) {
127-
this.messageService.warn('No boards selected.');
127+
this.messageService.warn('No boards selected.', { timeout: 3000 });
128128
}
129129
return false;
130130
}
@@ -146,14 +146,14 @@ export class BoardsServiceClientImpl implements BoardsServiceClient {
146146
const { name } = config.selectedBoard;
147147
if (!config.selectedPort) {
148148
if (!options.silent) {
149-
this.messageService.warn(`No ports selected for board: '${name}'.`);
149+
this.messageService.warn(`No ports selected for board: '${name}'.`, { timeout: 3000 });
150150
}
151151
return false;
152152
}
153153

154154
if (!config.selectedBoard.fqbn) {
155155
if (!options.silent) {
156-
this.messageService.warn(`The FQBN is not available for the selected board ${name}. Do you have the corresponding core installed?`);
156+
this.messageService.warn(`The FQBN is not available for the selected board ${name}. Do you have the corresponding core installed?`, { timeout: 3000 });
157157
}
158158
return false;
159159
}
@@ -169,6 +169,9 @@ export class BoardsServiceClientImpl implements BoardsServiceClient {
169169
const storedValidBoardsConfig = await this.storageService.getData<RecursiveRequired<BoardsConfig.Config>>('latest-valid-boards-config');
170170
if (storedValidBoardsConfig) {
171171
this.latestValidBoardsConfig = storedValidBoardsConfig;
172+
if (this.canUploadTo(this.latestValidBoardsConfig)) {
173+
this.boardsConfig = this.latestValidBoardsConfig;
174+
}
172175
}
173176
}
174177

arduino-ide-extension/src/browser/monitor/monitor-connection.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { injectable, inject, postConstruct } from 'inversify';
22
import { Emitter, Event } from '@theia/core/lib/common/event';
33
// import { ConnectionStatusService } from '@theia/core/lib/browser/connection-status-service';
44
import { MessageService } from '@theia/core/lib/common/message-service';
5+
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
56
import { MonitorService, MonitorConfig, MonitorError, Status } from '../../common/protocol/monitor-service';
67
import { BoardsServiceClientImpl } from '../boards/boards-service-client-impl';
78
import { Port, Board, BoardsService, AttachedSerialBoard, AttachedBoardsChangeEvent } from '../../common/protocol/boards-service';
@@ -33,6 +34,9 @@ export class MonitorConnection {
3334
// @inject(ConnectionStatusService)
3435
// protected readonly connectionStatusService: ConnectionStatusService;
3536

37+
@inject(FrontendApplicationStateService)
38+
protected readonly applicationState: FrontendApplicationStateService;
39+
3640
protected state: MonitorConnection.State | undefined;
3741
/**
3842
* Note: The idea is to toggle this property from the UI (`Monitor` view)
@@ -120,8 +124,12 @@ export class MonitorConnection {
120124
this._autoConnect = value;
121125
// When we enable the auto-connect, we have to connect
122126
if (!oldValue && value) {
123-
const { boardsConfig } = this.boardsServiceClient;
124-
this.handleBoardConfigChange(boardsConfig);
127+
// We have to make sure the previous boards config has been restored.
128+
// Otherwise, we might start the auto-connection without configured boards.
129+
this.applicationState.reachedState('started_contributions').then(() => {
130+
const { boardsConfig } = this.boardsServiceClient;
131+
this.handleBoardConfigChange(boardsConfig);
132+
});
125133
}
126134
}
127135

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ export class MonitorViewContribution extends AbstractViewContribution<MonitorWid
5959
id: 'monitor-autoscroll',
6060
render: () => this.renderAutoScrollButton(),
6161
isVisible: widget => widget instanceof MonitorWidget,
62-
onDidChange: this.model.onChange as any // TODO: https://github.com/eclipse-theia/theia/pull/6696/
62+
onDidChange: this.model.onChange as any // XXX: it's a hack. See: https://github.com/eclipse-theia/theia/pull/6696/
6363
});
6464
registry.registerItem({
6565
id: 'monitor-timestamp',
6666
render: () => this.renderTimestampButton(),
6767
isVisible: widget => widget instanceof MonitorWidget,
68-
onDidChange: this.model.onChange as any // TODO: https://github.com/eclipse-theia/theia/pull/6696/
68+
onDidChange: this.model.onChange as any // XXX: it's a hack. See: https://github.com/eclipse-theia/theia/pull/6696/
6969
});
7070
registry.registerItem({
7171
id: SerialMonitor.Commands.CLEAR_OUTPUT.id,

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

+13-15
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,29 @@ export namespace SerialMonitorSendInput {
169169
readonly resolveFocus: (element: HTMLElement | undefined) => void;
170170
}
171171
export interface State {
172-
value: string;
172+
text: string;
173173
}
174174
}
175175

176176
export class SerialMonitorSendInput extends React.Component<SerialMonitorSendInput.Props, SerialMonitorSendInput.State> {
177177

178178
constructor(props: Readonly<SerialMonitorSendInput.Props>) {
179179
super(props);
180-
this.state = { value: '' };
180+
this.state = { text: '' };
181181
this.onChange = this.onChange.bind(this);
182182
this.onSend = this.onSend.bind(this);
183183
this.onKeyDown = this.onKeyDown.bind(this);
184184
}
185185

186186
render(): React.ReactNode {
187-
return <React.Fragment>
188-
<input
189-
ref={this.setRef}
190-
type='text'
191-
className={this.props.monitorConfig ? '' : 'not-connected'}
192-
placeholder={this.placeholder}
193-
value={this.state.value}
194-
onChange={this.onChange}
195-
onKeyDown={this.onKeyDown} />
196-
</React.Fragment>
187+
return <input
188+
ref={this.setRef}
189+
type='text'
190+
className={this.props.monitorConfig ? '' : 'not-connected'}
191+
placeholder={this.placeholder}
192+
value={this.state.text}
193+
onChange={this.onChange}
194+
onKeyDown={this.onKeyDown} />
197195
}
198196

199197
protected get placeholder(): string {
@@ -212,12 +210,12 @@ export class SerialMonitorSendInput extends React.Component<SerialMonitorSendInp
212210
}
213211

214212
protected onChange(event: React.ChangeEvent<HTMLInputElement>): void {
215-
this.setState({ value: event.target.value });
213+
this.setState({ text: event.target.value });
216214
}
217215

218216
protected onSend(): void {
219-
this.props.onSend(this.state.value);
220-
this.setState({ value: '' });
217+
this.props.onSend(this.state.text);
218+
this.setState({ text: '' });
221219
}
222220

223221
protected onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {

0 commit comments

Comments
 (0)