Skip to content

Commit bd399eb

Browse files
author
Akos Kitta
committed
Update package index on 3rd party URLs change.
Closes #637 Closes #906 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 5499c25 commit bd399eb

32 files changed

+639
-453
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ import { CoreErrorHandler } from './contributions/core-error-handler';
302302
import { CompilerErrors } from './contributions/compiler-errors';
303303
import { WidgetManager } from './theia/core/widget-manager';
304304
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
305+
import { IndexesUpdateProgress } from './contributions/indexes-update-progress';
305306

306307
MonacoThemingService.register({
307308
id: 'arduino-theme',
@@ -698,6 +699,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
698699
Contribution.configure(bind, PlotterFrontendContribution);
699700
Contribution.configure(bind, Format);
700701
Contribution.configure(bind, CompilerErrors);
702+
Contribution.configure(bind, IndexesUpdateProgress);
701703

702704
// Disabled the quick-pick customization from Theia when multiple formatters are available.
703705
// Use the default VS Code behavior, and pick the first one. In the IDE2, clang-format has `exclusive` selectors.

arduino-ide-extension/src/browser/boards/boards-config.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class BoardsConfig extends React.Component<
113113
);
114114
}
115115
}),
116-
this.props.notificationCenter.onAttachedBoardsChanged((event) =>
116+
this.props.notificationCenter.onAttachedBoardsDidChange((event) =>
117117
this.updatePorts(
118118
event.newState.ports,
119119
AttachedBoardsChangeEvent.diff(event).detached.ports
@@ -126,19 +126,19 @@ export class BoardsConfig extends React.Component<
126126
);
127127
}
128128
),
129-
this.props.notificationCenter.onPlatformInstalled(() =>
129+
this.props.notificationCenter.onPlatformDidInstall(() =>
130130
this.updateBoards(this.state.query)
131131
),
132-
this.props.notificationCenter.onPlatformUninstalled(() =>
132+
this.props.notificationCenter.onPlatformDidUninstall(() =>
133133
this.updateBoards(this.state.query)
134134
),
135-
this.props.notificationCenter.onIndexUpdated(() =>
135+
this.props.notificationCenter.onIndexDidUpdate(() =>
136136
this.updateBoards(this.state.query)
137137
),
138-
this.props.notificationCenter.onDaemonStarted(() =>
138+
this.props.notificationCenter.onDaemonDidStart(() =>
139139
this.updateBoards(this.state.query)
140140
),
141-
this.props.notificationCenter.onDaemonStopped(() =>
141+
this.props.notificationCenter.onDaemonDidStop(() =>
142142
this.setState({ searchResults: [] })
143143
),
144144
this.props.onFilteredTextDidChangeEvent((query) =>

arduino-ide-extension/src/browser/boards/boards-data-store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class BoardsDataStore implements FrontendApplicationContribution {
3333
protected readonly onChangedEmitter = new Emitter<void>();
3434

3535
onStart(): void {
36-
this.notificationCenter.onPlatformInstalled(async ({ item }) => {
36+
this.notificationCenter.onPlatformDidInstall(async ({ item }) => {
3737
let shouldFireChanged = false;
3838
for (const fqbn of item.boards
3939
.map(({ fqbn }) => fqbn)

arduino-ide-extension/src/browser/boards/boards-list-widget.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export class BoardsListWidget extends ListWidget<BoardsPackage> {
3333
protected override init(): void {
3434
super.init();
3535
this.toDispose.pushAll([
36-
this.notificationCenter.onPlatformInstalled(() =>
36+
this.notificationCenter.onPlatformDidInstall(() =>
3737
this.refresh(undefined)
3838
),
39-
this.notificationCenter.onPlatformUninstalled(() =>
39+
this.notificationCenter.onPlatformDidUninstall(() =>
4040
this.refresh(undefined)
4141
),
4242
]);

arduino-ide-extension/src/browser/boards/boards-service-provider.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
7474
readonly onAvailablePortsChanged = this.onAvailablePortsChangedEmitter.event;
7575

7676
onStart(): void {
77-
this.notificationCenter.onAttachedBoardsChanged(
77+
this.notificationCenter.onAttachedBoardsDidChange(
7878
this.notifyAttachedBoardsChanged.bind(this)
7979
);
80-
this.notificationCenter.onPlatformInstalled(
80+
this.notificationCenter.onPlatformDidInstall(
8181
this.notifyPlatformInstalled.bind(this)
8282
);
83-
this.notificationCenter.onPlatformUninstalled(
83+
this.notificationCenter.onPlatformDidUninstall(
8484
this.notifyPlatformUninstalled.bind(this)
8585
);
8686

arduino-ide-extension/src/browser/contributions/board-selection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ PID: ${PID}`;
101101
}
102102

103103
override onStart(): void {
104-
this.notificationCenter.onPlatformInstalled(() => this.updateMenus());
105-
this.notificationCenter.onPlatformUninstalled(() => this.updateMenus());
104+
this.notificationCenter.onPlatformDidInstall(() => this.updateMenus());
105+
this.notificationCenter.onPlatformDidUninstall(() => this.updateMenus());
106106
this.boardsServiceProvider.onBoardsConfigChanged(() => this.updateMenus());
107107
this.boardsServiceProvider.onAvailableBoardsChanged(() =>
108108
this.updateMenus()

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export class Debug extends SketchContribution {
8383
this.boardsServiceProvider.onBoardsConfigChanged(({ selectedBoard }) =>
8484
this.refreshState(selectedBoard)
8585
);
86-
this.notificationCenter.onPlatformInstalled(() => this.refreshState());
87-
this.notificationCenter.onPlatformUninstalled(() => this.refreshState());
86+
this.notificationCenter.onPlatformDidInstall(() => this.refreshState());
87+
this.notificationCenter.onPlatformDidUninstall(() => this.refreshState());
8888
}
8989

9090
override onReady(): MaybePromise<void> {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ export class LibraryExamples extends Examples {
202202
protected readonly queue = new PQueue({ autoStart: true, concurrency: 1 });
203203

204204
override onStart(): void {
205-
this.notificationCenter.onLibraryInstalled(() => this.register());
206-
this.notificationCenter.onLibraryUninstalled(() => this.register());
205+
this.notificationCenter.onLibraryDidInstall(() => this.register());
206+
this.notificationCenter.onLibraryDidUninstall(() => this.register());
207207
}
208208

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export class IncludeLibrary extends SketchContribution {
4949
this.boardsServiceClient.onBoardsConfigChanged(() =>
5050
this.updateMenuActions()
5151
);
52-
this.notificationCenter.onLibraryInstalled(() => this.updateMenuActions());
53-
this.notificationCenter.onLibraryUninstalled(() =>
52+
this.notificationCenter.onLibraryDidInstall(() => this.updateMenuActions());
53+
this.notificationCenter.onLibraryDidUninstall(() =>
5454
this.updateMenuActions()
5555
);
5656
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Progress } from '@theia/core/lib/common/message-service-protocol';
2+
import { ProgressService } from '@theia/core/lib/common/progress-service';
3+
import { inject, injectable } from '@theia/core/shared/inversify';
4+
import { ProgressMessage } from '../../common/protocol';
5+
import { NotificationCenter } from '../notification-center';
6+
import { Contribution } from './contribution';
7+
8+
@injectable()
9+
export class IndexesUpdateProgress extends Contribution {
10+
@inject(NotificationCenter)
11+
private readonly notificationCenter: NotificationCenter;
12+
@inject(ProgressService)
13+
private readonly progressService: ProgressService;
14+
private currentProgress:
15+
| (Progress & Readonly<{ progressId: string }>)
16+
| undefined;
17+
18+
override onStart(): void {
19+
this.notificationCenter.onIndexWillUpdate((progressId) =>
20+
this.getOrCreateProgress(progressId)
21+
);
22+
this.notificationCenter.onIndexUpdateDidProgress((progress) => {
23+
this.getOrCreateProgress(progress).then((delegate) =>
24+
delegate.report(progress)
25+
);
26+
});
27+
this.notificationCenter.onIndexDidUpdate((progressId) => {
28+
if (this.currentProgress) {
29+
if (this.currentProgress.progressId !== progressId) {
30+
console.warn(
31+
`Mismatching progress IDs. Expected ${progressId}, got ${this.currentProgress.progressId}. Canceling anyway.`
32+
);
33+
}
34+
this.currentProgress.cancel();
35+
this.currentProgress = undefined;
36+
}
37+
});
38+
}
39+
40+
private async getOrCreateProgress(
41+
progressOrId: ProgressMessage | string
42+
): Promise<Progress & { progressId: string }> {
43+
const progressId = ProgressMessage.is(progressOrId)
44+
? progressOrId.progressId
45+
: progressOrId;
46+
if (
47+
this.currentProgress &&
48+
this.currentProgress.progressId === progressId
49+
) {
50+
return this.currentProgress;
51+
}
52+
if (this.currentProgress) {
53+
this.currentProgress.cancel();
54+
}
55+
this.currentProgress = undefined;
56+
const progress = await this.progressService.showProgress({
57+
text: 'Arduino',
58+
// TODO: IDE2 could show the progress in `notification`, like the platform/library install and uninstall.
59+
// However, the index update progress responses are not much helpful. They cannot provide a fine-grain progress.
60+
// So IDE2 could report two total works only: index update and library index update.
61+
// See here an example: https://github.com/arduino/arduino-ide/issues/906#issuecomment-1171145630
62+
// Due to this, IDE2 shows a spinner on the status bar.
63+
options: { location: 'window' },
64+
});
65+
if (ProgressMessage.is(progressOrId)) {
66+
progress.report(progressOrId); // if the client has missed the `willStart` event, report the progress immediately.
67+
}
68+
this.currentProgress = { ...progress, progressId };
69+
return this.currentProgress;
70+
}
71+
}

arduino-ide-extension/src/browser/contributions/open-recent-sketch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class OpenRecentSketch extends SketchContribution {
3636
protected toDisposeBeforeRegister = new Map<string, DisposableCollection>();
3737

3838
override onStart(): void {
39-
this.notificationCenter.onRecentSketchesChanged(({ sketches }) =>
39+
this.notificationCenter.onRecentSketchesDidChange(({ sketches }) =>
4040
this.refreshMenu(sketches)
4141
);
4242
}

arduino-ide-extension/src/browser/library/library-list-widget.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export class LibraryListWidget extends ListWidget<LibraryPackage> {
4141
protected override init(): void {
4242
super.init();
4343
this.toDispose.pushAll([
44-
this.notificationCenter.onLibraryInstalled(() => this.refresh(undefined)),
45-
this.notificationCenter.onLibraryUninstalled(() =>
44+
this.notificationCenter.onLibraryDidInstall(() => this.refresh(undefined)),
45+
this.notificationCenter.onLibraryDidUninstall(() =>
4646
this.refresh(undefined)
4747
),
4848
]);

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

+64-47
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
LibraryPackage,
1818
Config,
1919
Sketch,
20+
ProgressMessage,
2021
} from '../common/protocol';
2122
import {
2223
FrontendApplicationStateService,
@@ -33,25 +34,28 @@ export class NotificationCenter
3334
@inject(FrontendApplicationStateService)
3435
private readonly appStateService: FrontendApplicationStateService;
3536

36-
protected readonly indexUpdatedEmitter = new Emitter<void>();
37-
protected readonly daemonStartedEmitter = new Emitter<string>();
38-
protected readonly daemonStoppedEmitter = new Emitter<void>();
39-
protected readonly configChangedEmitter = new Emitter<{
37+
protected readonly indexDidUpdateEmitter = new Emitter<string>();
38+
protected readonly indexWillUpdateEmitter = new Emitter<string>();
39+
protected readonly indexUpdateDidProgressEmitter =
40+
new Emitter<ProgressMessage>();
41+
protected readonly daemonDidStartEmitter = new Emitter<string>();
42+
protected readonly daemonDidStopEmitter = new Emitter<void>();
43+
protected readonly configDidChangeEmitter = new Emitter<{
4044
config: Config | undefined;
4145
}>();
42-
protected readonly platformInstalledEmitter = new Emitter<{
46+
protected readonly platformDidInstallEmitter = new Emitter<{
4347
item: BoardsPackage;
4448
}>();
45-
protected readonly platformUninstalledEmitter = new Emitter<{
49+
protected readonly platformDidUninstallEmitter = new Emitter<{
4650
item: BoardsPackage;
4751
}>();
48-
protected readonly libraryInstalledEmitter = new Emitter<{
52+
protected readonly libraryDidInstallEmitter = new Emitter<{
4953
item: LibraryPackage;
5054
}>();
51-
protected readonly libraryUninstalledEmitter = new Emitter<{
55+
protected readonly libraryDidUninstallEmitter = new Emitter<{
5256
item: LibraryPackage;
5357
}>();
54-
protected readonly attachedBoardsChangedEmitter =
58+
protected readonly attachedBoardsDidChangeEmitter =
5559
new Emitter<AttachedBoardsChangeEvent>();
5660
protected readonly recentSketchesChangedEmitter = new Emitter<{
5761
sketches: Sketch[];
@@ -60,27 +64,32 @@ export class NotificationCenter
6064
new Emitter<FrontendApplicationState>();
6165

6266
protected readonly toDispose = new DisposableCollection(
63-
this.indexUpdatedEmitter,
64-
this.daemonStartedEmitter,
65-
this.daemonStoppedEmitter,
66-
this.configChangedEmitter,
67-
this.platformInstalledEmitter,
68-
this.platformUninstalledEmitter,
69-
this.libraryInstalledEmitter,
70-
this.libraryUninstalledEmitter,
71-
this.attachedBoardsChangedEmitter
67+
this.indexWillUpdateEmitter,
68+
this.indexUpdateDidProgressEmitter,
69+
this.indexDidUpdateEmitter,
70+
this.daemonDidStartEmitter,
71+
this.daemonDidStopEmitter,
72+
this.configDidChangeEmitter,
73+
this.platformDidInstallEmitter,
74+
this.platformDidUninstallEmitter,
75+
this.libraryDidInstallEmitter,
76+
this.libraryDidUninstallEmitter,
77+
this.attachedBoardsDidChangeEmitter
7278
);
7379

74-
readonly onIndexUpdated = this.indexUpdatedEmitter.event;
75-
readonly onDaemonStarted = this.daemonStartedEmitter.event;
76-
readonly onDaemonStopped = this.daemonStoppedEmitter.event;
77-
readonly onConfigChanged = this.configChangedEmitter.event;
78-
readonly onPlatformInstalled = this.platformInstalledEmitter.event;
79-
readonly onPlatformUninstalled = this.platformUninstalledEmitter.event;
80-
readonly onLibraryInstalled = this.libraryInstalledEmitter.event;
81-
readonly onLibraryUninstalled = this.libraryUninstalledEmitter.event;
82-
readonly onAttachedBoardsChanged = this.attachedBoardsChangedEmitter.event;
83-
readonly onRecentSketchesChanged = this.recentSketchesChangedEmitter.event;
80+
readonly onIndexDidUpdate = this.indexDidUpdateEmitter.event;
81+
readonly onIndexWillUpdate = this.indexDidUpdateEmitter.event;
82+
readonly onIndexUpdateDidProgress = this.indexUpdateDidProgressEmitter.event;
83+
readonly onDaemonDidStart = this.daemonDidStartEmitter.event;
84+
readonly onDaemonDidStop = this.daemonDidStopEmitter.event;
85+
readonly onConfigDidChange = this.configDidChangeEmitter.event;
86+
readonly onPlatformDidInstall = this.platformDidInstallEmitter.event;
87+
readonly onPlatformDidUninstall = this.platformDidUninstallEmitter.event;
88+
readonly onLibraryDidInstall = this.libraryDidInstallEmitter.event;
89+
readonly onLibraryDidUninstall = this.libraryDidUninstallEmitter.event;
90+
readonly onAttachedBoardsDidChange =
91+
this.attachedBoardsDidChangeEmitter.event;
92+
readonly onRecentSketchesDidChange = this.recentSketchesChangedEmitter.event;
8493
readonly onAppStateDidChange = this.onAppStateDidChangeEmitter.event;
8594

8695
@postConstruct()
@@ -97,43 +106,51 @@ export class NotificationCenter
97106
this.toDispose.dispose();
98107
}
99108

100-
notifyIndexUpdated(): void {
101-
this.indexUpdatedEmitter.fire();
109+
notifyIndexWillUpdate(progressId: string): void {
110+
this.indexWillUpdateEmitter.fire(progressId);
102111
}
103112

104-
notifyDaemonStarted(port: string): void {
105-
this.daemonStartedEmitter.fire(port);
113+
notifyIndexUpdateDidProgress(progressMessage: ProgressMessage): void {
114+
this.indexUpdateDidProgressEmitter.fire(progressMessage);
106115
}
107116

108-
notifyDaemonStopped(): void {
109-
this.daemonStoppedEmitter.fire();
117+
notifyIndexDidUpdate(progressId: string): void {
118+
this.indexDidUpdateEmitter.fire(progressId);
110119
}
111120

112-
notifyConfigChanged(event: { config: Config | undefined }): void {
113-
this.configChangedEmitter.fire(event);
121+
notifyDaemonDidStart(port: string): void {
122+
this.daemonDidStartEmitter.fire(port);
114123
}
115124

116-
notifyPlatformInstalled(event: { item: BoardsPackage }): void {
117-
this.platformInstalledEmitter.fire(event);
125+
notifyDaemonDidStop(): void {
126+
this.daemonDidStopEmitter.fire();
118127
}
119128

120-
notifyPlatformUninstalled(event: { item: BoardsPackage }): void {
121-
this.platformUninstalledEmitter.fire(event);
129+
notifyConfigDidChange(event: { config: Config | undefined }): void {
130+
this.configDidChangeEmitter.fire(event);
122131
}
123132

124-
notifyLibraryInstalled(event: { item: LibraryPackage }): void {
125-
this.libraryInstalledEmitter.fire(event);
133+
notifyPlatformDidInstall(event: { item: BoardsPackage }): void {
134+
this.platformDidInstallEmitter.fire(event);
126135
}
127136

128-
notifyLibraryUninstalled(event: { item: LibraryPackage }): void {
129-
this.libraryUninstalledEmitter.fire(event);
137+
notifyPlatformDidUninstall(event: { item: BoardsPackage }): void {
138+
this.platformDidUninstallEmitter.fire(event);
130139
}
131140

132-
notifyAttachedBoardsChanged(event: AttachedBoardsChangeEvent): void {
133-
this.attachedBoardsChangedEmitter.fire(event);
141+
notifyLibraryDidInstall(event: { item: LibraryPackage }): void {
142+
this.libraryDidInstallEmitter.fire(event);
134143
}
135144

136-
notifyRecentSketchesChanged(event: { sketches: Sketch[] }): void {
145+
notifyLibraryDidUninstall(event: { item: LibraryPackage }): void {
146+
this.libraryDidUninstallEmitter.fire(event);
147+
}
148+
149+
notifyAttachedBoardsDidChange(event: AttachedBoardsChangeEvent): void {
150+
this.attachedBoardsDidChangeEmitter.fire(event);
151+
}
152+
153+
notifyRecentSketchesDidChange(event: { sketches: Sketch[] }): void {
137154
this.recentSketchesChangedEmitter.fire(event);
138155
}
139156
}

0 commit comments

Comments
 (0)