Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 79cc20a

Browse files
Fix board list dialog not showing any port
1 parent b5af7ab commit 79cc20a

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class BoardDiscovery extends CoreClientAware {
4141

4242
@postConstruct()
4343
protected async init(): Promise<void> {
44+
await this.coreClientProvider.initialized;
4445
const coreClient = await this.coreClient();
4546
const { client, instance } = coreClient;
4647
const req = new BoardListWatchRequest();

‎arduino-ide-extension/src/node/boards-service-impl.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class BoardsServiceImpl extends CoreClientAware implements BoardsService
4949
}
5050

5151
async getBoardDetails(options: { fqbn: string }): Promise<BoardDetails | undefined> {
52+
await this.coreClientProvider.initialized;
5253
const coreClient = await this.coreClient();
5354
const { client, instance } = coreClient;
5455
const { fqbn } = options;
@@ -152,6 +153,7 @@ export class BoardsServiceImpl extends CoreClientAware implements BoardsService
152153
}
153154

154155
async searchBoards({ query }: { query?: string }): Promise<BoardWithPackage[]> {
156+
await this.coreClientProvider.initialized;
155157
const { instance, client } = await this.coreClient();
156158
const req = new BoardSearchRequest();
157159
req.setSearchArgs(query || '');
@@ -181,6 +183,7 @@ export class BoardsServiceImpl extends CoreClientAware implements BoardsService
181183
}
182184

183185
async search(options: { query?: string }): Promise<BoardsPackage[]> {
186+
await this.coreClientProvider.initialized;
184187
const coreClient = await this.coreClient();
185188
const { client, instance } = coreClient;
186189

@@ -263,6 +266,7 @@ export class BoardsServiceImpl extends CoreClientAware implements BoardsService
263266
async install(options: { item: BoardsPackage, progressId?: string, version?: Installable.Version }): Promise<void> {
264267
const item = options.item;
265268
const version = !!options.version ? options.version : item.availableVersions[0];
269+
await this.coreClientProvider.initialized;
266270
const coreClient = await this.coreClient();
267271
const { client, instance } = coreClient;
268272

@@ -294,6 +298,7 @@ export class BoardsServiceImpl extends CoreClientAware implements BoardsService
294298

295299
async uninstall(options: { item: BoardsPackage, progressId?: string }): Promise<void> {
296300
const { item, progressId } = options;
301+
await this.coreClientProvider.initialized;
297302
const coreClient = await this.coreClient();
298303
const { client, instance } = coreClient;
299304

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

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
import * as grpc from '@grpc/grpc-js';
22
import { inject, injectable, postConstruct } from 'inversify';
3-
import { Event, Emitter } from '@theia/core/lib/common/event';
4-
import { DisposableCollection } from '@theia/core/lib/common/disposable';
53
import { GrpcClientProvider } from './grpc-client-provider';
64
import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
75
import { Instance } from './cli-protocol/cc/arduino/cli/commands/v1/common_pb';
86
import { CreateRequest, CreateResponse, InitRequest, InitResponse, UpdateIndexRequest, UpdateIndexResponse, UpdateLibrariesIndexRequest, UpdateLibrariesIndexResponse } from './cli-protocol/cc/arduino/cli/commands/v1/commands_pb';
97
import * as commandsGrpcPb from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
108
import { NotificationServiceServer } from '../common/protocol';
9+
import { Deferred } from '@theia/core/lib/common/promise-util';
1110

1211
@injectable()
1312
export class CoreClientProvider extends GrpcClientProvider<CoreClientProvider.Client> {
1413

1514
@inject(NotificationServiceServer)
1615
protected readonly notificationService: NotificationServiceServer;
1716

18-
protected readonly onClientReadyEmitter = new Emitter<void>();
17+
protected _created = new Deferred<void>();
18+
protected _initialized = new Deferred<void>();
1919

20-
get onClientReady(): Event<void> {
21-
return this.onClientReadyEmitter.event;
20+
get created(): Promise<void> {
21+
return this._created.promise;
22+
}
23+
24+
get initialized(): Promise<void> {
25+
return this._initialized.promise
2226
}
2327

2428
close(client: CoreClientProvider.Client): void {
2529
client.client.close();
30+
this._created.reject();
31+
this._initialized.reject();
32+
this._created = new Deferred<void>();
33+
this._initialized = new Deferred<void>();
2634
}
2735

2836
@postConstruct()
@@ -33,13 +41,14 @@ export class CoreClientProvider extends GrpcClientProvider<CoreClientProvider.Cl
3341
// and notify client is ready.
3442
// TODO: Creation failure should probably be handled here
3543
await this.reconcileClient(cliConfig ? cliConfig.daemon.port : undefined)
36-
.then(() => { this.onClientReadyEmitter.fire(); });
44+
.then(() => { this._created.resolve() });
3745

3846
// If client has been created correctly update indexes and initialize
3947
// its instance by loading platforms and cores.
4048
if (this._client && !(this._client instanceof Error)) {
4149
await this.updateIndexes(this._client)
42-
.then(this.initInstance);
50+
.then(this.initInstance)
51+
.then(() => { this._initialized.resolve(); });
4352
}
4453
});
4554

@@ -219,29 +228,13 @@ export abstract class CoreClientAware {
219228
protected readonly coreClientProvider: CoreClientProvider;
220229

221230
protected async coreClient(): Promise<CoreClientProvider.Client> {
222-
const coreClient = await new Promise<CoreClientProvider.Client>(async (resolve, reject) => {
223-
const handle = (c: CoreClientProvider.Client | Error) => {
224-
if (c instanceof Error) {
225-
reject(c);
226-
} else {
227-
resolve(c);
228-
}
231+
return await new Promise<CoreClientProvider.Client>(async (resolve, reject) => {
232+
const client = await this.coreClientProvider.client()
233+
if (client && client instanceof Error) {
234+
reject(client)
235+
} else if (client) {
236+
return resolve(client);
229237
}
230-
const client = await this.coreClientProvider.client();
231-
if (client) {
232-
handle(client);
233-
return;
234-
}
235-
const toDispose = new DisposableCollection();
236-
toDispose.push(this.coreClientProvider.onClientReady(async () => {
237-
const client = await this.coreClientProvider.client();
238-
if (client) {
239-
handle(client);
240-
}
241-
toDispose.dispose();
242-
}));
243238
});
244-
return coreClient;
245239
}
246-
247240
}

‎arduino-ide-extension/src/node/core-service-impl.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
2626
const { sketchUri, fqbn, compilerWarnings } = options;
2727
const sketchPath = FileUri.fsPath(sketchUri);
2828

29+
await this.coreClientProvider.initialized;
2930
const coreClient = await this.coreClient();
3031
const { client, instance } = coreClient;
3132

@@ -85,6 +86,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
8586
const { sketchUri, fqbn, port, programmer } = options;
8687
const sketchPath = FileUri.fsPath(sketchUri);
8788

89+
await this.coreClientProvider.initialized;
8890
const coreClient = await this.coreClient();
8991
const { client, instance } = coreClient;
9092

@@ -121,6 +123,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
121123
}
122124

123125
async burnBootloader(options: CoreService.Bootloader.Options): Promise<void> {
126+
await this.coreClientProvider.initialized;
124127
const coreClient = await this.coreClient();
125128
const { client, instance } = coreClient;
126129
const { fqbn, port, programmer } = options;

‎arduino-ide-extension/src/node/library-service-server-impl.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
2525
protected readonly notificationServer: NotificationServiceServer;
2626

2727
async search(options: { query?: string }): Promise<LibraryPackage[]> {
28+
await this.coreClientProvider.initialized;
2829
const coreClient = await this.coreClient();
2930
const { client, instance } = coreClient;
3031

@@ -68,6 +69,7 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
6869
}
6970

7071
async list({ fqbn }: { fqbn?: string | undefined }): Promise<LibraryPackage[]> {
72+
await this.coreClientProvider.initialized;
7173
const coreClient = await this.coreClient();
7274
const { client, instance } = coreClient;
7375
const req = new LibraryListRequest();
@@ -143,6 +145,7 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
143145
}
144146

145147
async listDependencies({ item, version, filterSelf }: { item: LibraryPackage, version: Installable.Version, filterSelf?: boolean }): Promise<LibraryDependency[]> {
148+
await this.coreClientProvider.initialized;
146149
const coreClient = await this.coreClient();
147150
const { client, instance } = coreClient;
148151
const req = new LibraryResolveDependenciesRequest();
@@ -168,6 +171,7 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
168171
async install(options: { item: LibraryPackage, progressId?: string, version?: Installable.Version, installDependencies?: boolean }): Promise<void> {
169172
const item = options.item;
170173
const version = !!options.version ? options.version : item.availableVersions[0];
174+
await this.coreClientProvider.initialized;
171175
const coreClient = await this.coreClient();
172176
const { client, instance } = coreClient;
173177

@@ -198,6 +202,7 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
198202
}
199203

200204
async installZip({ zipUri, progressId, overwrite }: { zipUri: string, progressId?: string, overwrite?: boolean }): Promise<void> {
205+
await this.coreClientProvider.created;
201206
const coreClient = await this.coreClient();
202207
const { client, instance } = coreClient;
203208
const req = new ZipLibraryInstallRequest();
@@ -216,6 +221,7 @@ export class LibraryServiceImpl extends CoreClientAware implements LibraryServic
216221

217222
async uninstall(options: { item: LibraryPackage, progressId?: string }): Promise<void> {
218223
const { item, progressId } = options;
224+
await this.coreClientProvider.initialized;
219225
const coreClient = await this.coreClient();
220226
const { client, instance } = coreClient;
221227

‎arduino-ide-extension/src/node/sketches-service-impl.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class SketchesServiceImpl extends CoreClientAware implements SketchesServ
107107
}
108108

109109
async loadSketch(uri: string): Promise<SketchWithDetails> {
110+
await this.coreClientProvider.initialized;
110111
const { client, instance } = await this.coreClient();
111112
const req = new LoadSketchRequest();
112113
req.setSketchPath(FileUri.fsPath(uri));
@@ -378,6 +379,7 @@ void loop() {
378379

379380
async archive(sketch: Sketch, destinationUri: string): Promise<string> {
380381
await this.loadSketch(sketch.uri); // sanity check
382+
await this.coreClientProvider.initialized;
381383
const { client } = await this.coreClient();
382384
const archivePath = FileUri.fsPath(destinationUri);
383385
// The CLI cannot override existing archives, so we have to wipe it manually: https://github.com/arduino/arduino-cli/issues/1160

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /