Skip to content

Commit 195c57b

Browse files
author
Akos Kitta
committed
fix: file > examples and sketch > include menus
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent ae5c890 commit 195c57b

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

arduino-ide-extension/src/browser/contributions/examples.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,22 @@ export abstract class Examples extends SketchContribution {
4848
@inject(BoardsServiceProvider)
4949
protected readonly boardsServiceClient: BoardsServiceProvider;
5050

51+
@inject(NotificationCenter)
52+
protected readonly notificationCenter: NotificationCenter;
53+
5154
protected readonly toDispose = new DisposableCollection();
5255

5356
protected override init(): void {
5457
super.init();
5558
this.boardsServiceClient.onBoardsConfigChanged(({ selectedBoard }) =>
5659
this.handleBoardChanged(selectedBoard)
5760
);
61+
this.notificationCenter.onDidReinitialize(() =>
62+
this.update({
63+
board: this.boardsServiceClient.boardsConfig.selectedBoard,
64+
// No force refresh. The core client was already refreshed.
65+
})
66+
);
5867
}
5968

6069
// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
@@ -245,9 +254,6 @@ export class BuiltInExamples extends Examples {
245254

246255
@injectable()
247256
export class LibraryExamples extends Examples {
248-
@inject(NotificationCenter)
249-
private readonly notificationCenter: NotificationCenter;
250-
251257
private readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
252258

253259
override onStart(): void {

arduino-ide-extension/src/browser/contributions/include-library.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class IncludeLibrary extends SketchContribution {
5353
this.notificationCenter.onLibraryDidUninstall(() =>
5454
this.updateMenuActions()
5555
);
56+
this.notificationCenter.onDidReinitialize(() => this.updateMenuActions());
5657
}
5758

5859
override async onReady(): Promise<void> {

arduino-ide-extension/src/browser/notification-center.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class NotificationCenter
3737
@inject(FrontendApplicationStateService)
3838
private readonly appStateService: FrontendApplicationStateService;
3939

40+
private readonly didReinitializeEmitter = new Emitter<void>();
4041
private readonly indexUpdateDidCompleteEmitter =
4142
new Emitter<IndexUpdateDidCompleteParams>();
4243
private readonly indexUpdateWillStartEmitter =
@@ -69,6 +70,7 @@ export class NotificationCenter
6970
new Emitter<FrontendApplicationState>();
7071

7172
private readonly toDispose = new DisposableCollection(
73+
this.didReinitializeEmitter,
7274
this.indexUpdateWillStartEmitter,
7375
this.indexUpdateDidProgressEmitter,
7476
this.indexUpdateDidCompleteEmitter,
@@ -83,6 +85,7 @@ export class NotificationCenter
8385
this.attachedBoardsDidChangeEmitter
8486
);
8587

88+
readonly onDidReinitialize = this.didReinitializeEmitter.event;
8689
readonly onIndexUpdateDidComplete = this.indexUpdateDidCompleteEmitter.event;
8790
readonly onIndexUpdateWillStart = this.indexUpdateWillStartEmitter.event;
8891
readonly onIndexUpdateDidProgress = this.indexUpdateDidProgressEmitter.event;
@@ -113,6 +116,10 @@ export class NotificationCenter
113116
this.toDispose.dispose();
114117
}
115118

119+
notifyDidReinitialize(): void {
120+
this.didReinitializeEmitter.fire();
121+
}
122+
116123
notifyIndexUpdateWillStart(params: IndexUpdateWillStartParams): void {
117124
this.indexUpdateWillStartEmitter.fire(params);
118125
}

arduino-ide-extension/src/common/protocol/notification-service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export interface IndexUpdateDidFailParams extends IndexUpdateParams {
3939
}
4040

4141
export interface NotificationServiceClient {
42+
// The cached state of the core client. Libraries, examples, etc. has been updated.
43+
// This can happen without an index update. For example, changing the `directories.user` location.
44+
// An index update always implicitly involves a re-initialization without notifying via this method.
45+
notifyDidReinitialize(): void;
46+
4247
// Index
4348
notifyIndexUpdateWillStart(params: IndexUpdateWillStartParams): void;
4449
notifyIndexUpdateDidProgress(progressMessage: ProgressMessage): void;

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,26 @@ export class CoreClientProvider {
7676
});
7777
this.daemon.onDaemonStarted((port) => this.create(port));
7878
this.daemon.onDaemonStopped(() => this.closeClient());
79-
this.configService.onConfigChange(({ oldState, newState }) => {
79+
this.configService.onConfigChange(async ({ oldState, newState }) => {
8080
if (
8181
!AdditionalUrls.sameAs(
8282
oldState.config?.additionalUrls,
8383
newState.config?.additionalUrls
8484
)
85-
)
86-
this.client.then((client) => this.updateIndex(client, ['platform']));
85+
) {
86+
const client = await this.client;
87+
this.updateIndex(client, ['platform']);
88+
} else if (
89+
!!newState.config?.sketchDirUri &&
90+
oldState.config?.sketchDirUri !== newState.config.sketchDirUri
91+
) {
92+
// If the sketchbook location has changed, the custom libraries has changed.
93+
// Reinitialize the core client and fire an event so that the frontend can refresh.
94+
// https://github.com/arduino/arduino-ide/issues/796 (see the file > examples and sketch > include examples)
95+
const client = await this.client;
96+
await this.initInstance(client);
97+
this.notificationService.notifyDidReinitialize();
98+
}
8799
});
88100
}
89101

arduino-ide-extension/src/node/notification-service-server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export class NotificationServiceServerImpl
1919
{
2020
private readonly clients: NotificationServiceClient[] = [];
2121

22+
notifyDidReinitialize(): void {
23+
this.clients.forEach((client) => client.notifyDidReinitialize());
24+
}
25+
2226
notifyIndexUpdateWillStart(params: IndexUpdateWillStartParams): void {
2327
this.clients.forEach((client) => client.notifyIndexUpdateWillStart(params));
2428
}

0 commit comments

Comments
 (0)