Skip to content

Commit 337f48a

Browse files
author
Akos Kitta
committed
API cleanup.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 36d8fe1 commit 337f48a

File tree

5 files changed

+48
-45
lines changed

5 files changed

+48
-45
lines changed

arduino-ide-extension/src/browser/contributions/check-for-updates.ts

+48-31
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const NoUpdates = nls.localize(
2323
'arduino/checkForUpdates/noUpdates',
2424
'There are no recent updates available.'
2525
);
26-
const UpdatesBoards = nls.localize(
26+
const UpdateBoards = nls.localize(
2727
'arduino/checkForUpdates/updatedBoth',
2828
'Updates are available for some of your boards.'
2929
);
30-
const UpdatesLibraries = nls.localize(
30+
const UpdateLibraries = nls.localize(
3131
'arduino/checkForUpdates/updatedBoth',
3232
'Updates are available for some of your libraries.'
3333
);
@@ -37,10 +37,12 @@ const InstallAll = nls.localize(
3737
);
3838

3939
interface Task<T extends ArduinoComponent> {
40-
run: () => Promise<void>;
41-
item: T;
40+
readonly run: () => Promise<void>;
41+
readonly item: T;
4242
}
4343

44+
const Updatable = { type: 'Updatable' } as const;
45+
4446
@injectable()
4547
export class CheckForUpdates extends Contribution {
4648
@inject(WindowServiceExt)
@@ -74,9 +76,9 @@ export class CheckForUpdates extends Contribution {
7476
}
7577

7678
private async checkForUpdates(silent = true) {
77-
const [libraryPackages, boardsPackages] = await Promise.all([
78-
this.libraryService.updateables(),
79-
this.boardsService.updateables(),
79+
const [boardsPackages, libraryPackages] = await Promise.all([
80+
this.boardsService.search(Updatable),
81+
this.libraryService.search(Updatable),
8082
]);
8183
this.promptUpdateBoards(boardsPackages);
8284
this.promptUpdateLibraries(libraryPackages);
@@ -90,8 +92,8 @@ export class CheckForUpdates extends Contribution {
9092
items,
9193
installable: this.libraryService,
9294
viewContribution: this.librariesContribution,
93-
message: UpdatesLibraries,
94-
viewSearchOptions: { query: '', type: 'Updatable', topic: 'All' },
95+
viewSearchOptions: { query: '', topic: 'All', ...Updatable },
96+
message: UpdateLibraries,
9597
});
9698
}
9799

@@ -100,8 +102,8 @@ export class CheckForUpdates extends Contribution {
100102
items,
101103
installable: this.boardsService,
102104
viewContribution: this.boardsContribution,
103-
message: UpdatesBoards,
104-
viewSearchOptions: { query: '', type: 'Updatable' },
105+
viewSearchOptions: { query: '', ...Updatable },
106+
message: UpdateBoards,
105107
});
106108
}
107109

@@ -120,17 +122,20 @@ export class CheckForUpdates extends Contribution {
120122
if (!items.length) {
121123
return;
122124
}
123-
const actions = [Later, InstallManually, InstallAll];
124-
this.messageService.info(message, ...actions).then((answer) => {
125-
if (answer === InstallAll) {
126-
const tasks = items.map((item) => this.installTask(item, installable));
127-
return this.executeTasks(tasks);
128-
} else if (answer === InstallManually) {
129-
viewContribution
130-
.openView({ reveal: true })
131-
.then((widget) => widget.refresh(viewSearchOptions));
132-
}
133-
});
125+
this.messageService
126+
.info(message, Later, InstallManually, InstallAll)
127+
.then((answer) => {
128+
if (answer === InstallAll) {
129+
const tasks = items.map((item) =>
130+
this.createInstallTask(item, installable)
131+
);
132+
this.executeTasks(tasks);
133+
} else if (answer === InstallManually) {
134+
viewContribution
135+
.openView({ reveal: true })
136+
.then((widget) => widget.refresh(viewSearchOptions));
137+
}
138+
});
134139
}
135140

136141
private async executeTasks(tasks: Task<ArduinoComponent>[]): Promise<void> {
@@ -139,21 +144,33 @@ export class CheckForUpdates extends Contribution {
139144
nls.localize('arduino/checkForUpdates/updating', 'Updating'),
140145
this.messageService,
141146
async (progress) => {
142-
const total = tasks.length;
143-
let count = 0;
144-
for (const { run, item } of tasks) {
145-
progress.report({
146-
message: item.name,
147-
});
148-
await run();
149-
progress.report({ work: { total, done: ++count } });
147+
try {
148+
const total = tasks.length;
149+
let count = 0;
150+
for (const { run, item } of tasks) {
151+
// progress.report({
152+
// message: item.name,
153+
// });
154+
try {
155+
await run(); // runs update sequentially. // TODO: is parallel update desired?
156+
} catch (err) {
157+
console.error(err);
158+
this.messageService.error(
159+
`Failed to update ${item.name}. ${err}`
160+
);
161+
} finally {
162+
progress.report({ work: { total, done: ++count } });
163+
}
164+
}
165+
} finally {
166+
progress.cancel();
150167
}
151168
}
152169
);
153170
}
154171
}
155172

156-
private installTask<T extends ArduinoComponent>(
173+
private createInstallTask<T extends ArduinoComponent>(
157174
item: T,
158175
installable: Installable<T>
159176
): Task<T> {

arduino-ide-extension/src/browser/style/list-widget.css

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
}
1717

1818
.arduino-list-widget .filter-bar {
19-
display: flex;
2019
margin: 0px 10px 5px 15px;
2120
}
2221

arduino-ide-extension/src/common/protocol/installable.ts

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ export interface Installable<T extends ArduinoComponent> {
2020
* Uninstalls the given component. It is a NOOP if not installed.
2121
*/
2222
uninstall(options: { item: T; progressId?: string }): Promise<void>;
23-
24-
/**
25-
* Returns with a promise which resolves all component that is installed but has a more recent version available.
26-
*/
27-
updateables(): Promise<T[]>;
2823
}
2924
export namespace Installable {
3025
export type Version = string;

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

-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ export class BoardsServiceImpl
190190
);
191191
}
192192

193-
updateables(): Promise<BoardsPackage[]> {
194-
return this.search({ type: 'Updatable' });
195-
}
196-
197193
async searchBoards({
198194
query,
199195
}: {

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

-4
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ export class LibraryServiceImpl
143143
return (item: LibraryPackage) => item.category === topic;
144144
}
145145

146-
async updateables(): Promise<LibraryPackage[]> {
147-
return this.search({ type: 'Updatable' });
148-
}
149-
150146
async list({
151147
fqbn,
152148
}: {

0 commit comments

Comments
 (0)