Skip to content

Restart discovery after re-initializing client. #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion arduino-ide-extension/src/node/board-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export class BoardDiscovery extends CoreClientAware {
@postConstruct()
protected async init(): Promise<void> {
this.coreClient.then((client) => this.startBoardListWatch(client));
this.onClientDidRefresh((client) =>
this.stopBoardListWatch(client).then(() =>
this.startBoardListWatch(client)
)
);
}

stopBoardListWatch(coreClient: CoreClientProvider.Client): Promise<void> {
Expand All @@ -79,7 +84,7 @@ export class BoardDiscovery extends CoreClientAware {
startBoardListWatch(coreClient: CoreClientProvider.Client): void {
if (this.watching) {
// We want to avoid starting the board list watch process multiple
// times to meet unforseen consequences
// times to meet unforeseen consequences
return;
}
this.watching = true;
Expand Down
13 changes: 12 additions & 1 deletion arduino-ide-extension/src/node/core-client-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
injectable,
postConstruct,
} from '@theia/core/shared/inversify';
import { Emitter } from '@theia/core/lib/common/event';
import { Emitter, Event } from '@theia/core/lib/common/event';
import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
import { Instance } from './cli-protocol/cc/arduino/cli/commands/v1/common_pb';
import {
Expand Down Expand Up @@ -53,6 +53,8 @@ export class CoreClientProvider {
private readonly onClientReadyEmitter =
new Emitter<CoreClientProvider.Client>();
private readonly onClientReady = this.onClientReadyEmitter.event;
private readonly onClientDidRefreshEmitter =
new Emitter<CoreClientProvider.Client>();

@postConstruct()
protected init(): void {
Expand Down Expand Up @@ -88,6 +90,10 @@ export class CoreClientProvider {
return this.pending.promise;
}

get onClientDidRefresh(): Event<CoreClientProvider.Client> {
return this.onClientDidRefreshEmitter.event;
}

/**
* Encapsulates both the gRPC core client creation (`CreateRequest`) and initialization (`InitRequest`).
*/
Expand Down Expand Up @@ -253,6 +259,7 @@ export class CoreClientProvider {
await this.initInstance(client);
// notify clients about the index update only after the client has been "re-initialized" and the new content is available.
progressHandler.reportEnd();
this.onClientDidRefreshEmitter.fire(client);
} catch (err) {
console.error('Failed to update indexes', err);
progressHandler.reportError(
Expand Down Expand Up @@ -404,6 +411,10 @@ export abstract class CoreClientAware {
protected get coreClient(): Promise<CoreClientProvider.Client> {
return this.coreClientProvider.client;
}

protected get onClientDidRefresh(): Event<CoreClientProvider.Client> {
return this.coreClientProvider.onClientDidRefresh;
}
}

class IndexUpdateRequiredBeforeInitError extends Error {
Expand Down