Skip to content

Commit 431c3bd

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Restart discovery after re-initializing client.
Otherwise, board discovery stops working after indexes update. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent c51b201 commit 431c3bd

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

arduino-ide-extension/src/node/board-discovery.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export class BoardDiscovery extends CoreClientAware {
5656
@postConstruct()
5757
protected async init(): Promise<void> {
5858
this.coreClient.then((client) => this.startBoardListWatch(client));
59+
this.onClientDidRefresh((client) =>
60+
this.stopBoardListWatch(client).then(() =>
61+
this.startBoardListWatch(client)
62+
)
63+
);
5964
}
6065

6166
stopBoardListWatch(coreClient: CoreClientProvider.Client): Promise<void> {
@@ -79,7 +84,7 @@ export class BoardDiscovery extends CoreClientAware {
7984
startBoardListWatch(coreClient: CoreClientProvider.Client): void {
8085
if (this.watching) {
8186
// We want to avoid starting the board list watch process multiple
82-
// times to meet unforseen consequences
87+
// times to meet unforeseen consequences
8388
return;
8489
}
8590
this.watching = true;

arduino-ide-extension/src/node/core-client-provider.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
injectable,
66
postConstruct,
77
} from '@theia/core/shared/inversify';
8-
import { Emitter } from '@theia/core/lib/common/event';
8+
import { Emitter, Event } from '@theia/core/lib/common/event';
99
import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
1010
import { Instance } from './cli-protocol/cc/arduino/cli/commands/v1/common_pb';
1111
import {
@@ -53,6 +53,8 @@ export class CoreClientProvider {
5353
private readonly onClientReadyEmitter =
5454
new Emitter<CoreClientProvider.Client>();
5555
private readonly onClientReady = this.onClientReadyEmitter.event;
56+
private readonly onClientDidRefreshEmitter =
57+
new Emitter<CoreClientProvider.Client>();
5658

5759
@postConstruct()
5860
protected init(): void {
@@ -88,6 +90,10 @@ export class CoreClientProvider {
8890
return this.pending.promise;
8991
}
9092

93+
get onClientDidRefresh(): Event<CoreClientProvider.Client> {
94+
return this.onClientDidRefreshEmitter.event;
95+
}
96+
9197
/**
9298
* Encapsulates both the gRPC core client creation (`CreateRequest`) and initialization (`InitRequest`).
9399
*/
@@ -253,6 +259,7 @@ export class CoreClientProvider {
253259
await this.initInstance(client);
254260
// notify clients about the index update only after the client has been "re-initialized" and the new content is available.
255261
progressHandler.reportEnd();
262+
this.onClientDidRefreshEmitter.fire(client);
256263
} catch (err) {
257264
console.error('Failed to update indexes', err);
258265
progressHandler.reportError(
@@ -404,6 +411,10 @@ export abstract class CoreClientAware {
404411
protected get coreClient(): Promise<CoreClientProvider.Client> {
405412
return this.coreClientProvider.client;
406413
}
414+
415+
protected get onClientDidRefresh(): Event<CoreClientProvider.Client> {
416+
return this.coreClientProvider.onClientDidRefresh;
417+
}
407418
}
408419

409420
class IndexUpdateRequiredBeforeInitError extends Error {

0 commit comments

Comments
 (0)