Skip to content

Layout improvements of the filter for boards and libs manager #1369

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

Closed
wants to merge 22 commits into from
Closed
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
Prev Previous commit
Next Next commit
API cleanup.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed Aug 30, 2022
commit 337f48a3fb2eebeabd023e8299dd4c9b5ce4f40b
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const NoUpdates = nls.localize(
'arduino/checkForUpdates/noUpdates',
'There are no recent updates available.'
);
const UpdatesBoards = nls.localize(
const UpdateBoards = nls.localize(
'arduino/checkForUpdates/updatedBoth',
'Updates are available for some of your boards.'
);
const UpdatesLibraries = nls.localize(
const UpdateLibraries = nls.localize(
'arduino/checkForUpdates/updatedBoth',
'Updates are available for some of your libraries.'
);
Expand All @@ -37,10 +37,12 @@ const InstallAll = nls.localize(
);

interface Task<T extends ArduinoComponent> {
run: () => Promise<void>;
item: T;
readonly run: () => Promise<void>;
readonly item: T;
}

const Updatable = { type: 'Updatable' } as const;

@injectable()
export class CheckForUpdates extends Contribution {
@inject(WindowServiceExt)
Expand Down Expand Up @@ -74,9 +76,9 @@ export class CheckForUpdates extends Contribution {
}

private async checkForUpdates(silent = true) {
const [libraryPackages, boardsPackages] = await Promise.all([
this.libraryService.updateables(),
this.boardsService.updateables(),
const [boardsPackages, libraryPackages] = await Promise.all([
this.boardsService.search(Updatable),
this.libraryService.search(Updatable),
]);
this.promptUpdateBoards(boardsPackages);
this.promptUpdateLibraries(libraryPackages);
Expand All @@ -90,8 +92,8 @@ export class CheckForUpdates extends Contribution {
items,
installable: this.libraryService,
viewContribution: this.librariesContribution,
message: UpdatesLibraries,
viewSearchOptions: { query: '', type: 'Updatable', topic: 'All' },
viewSearchOptions: { query: '', topic: 'All', ...Updatable },
message: UpdateLibraries,
});
}

Expand All @@ -100,8 +102,8 @@ export class CheckForUpdates extends Contribution {
items,
installable: this.boardsService,
viewContribution: this.boardsContribution,
message: UpdatesBoards,
viewSearchOptions: { query: '', type: 'Updatable' },
viewSearchOptions: { query: '', ...Updatable },
message: UpdateBoards,
});
}

Expand All @@ -120,17 +122,20 @@ export class CheckForUpdates extends Contribution {
if (!items.length) {
return;
}
const actions = [Later, InstallManually, InstallAll];
this.messageService.info(message, ...actions).then((answer) => {
if (answer === InstallAll) {
const tasks = items.map((item) => this.installTask(item, installable));
return this.executeTasks(tasks);
} else if (answer === InstallManually) {
viewContribution
.openView({ reveal: true })
.then((widget) => widget.refresh(viewSearchOptions));
}
});
this.messageService
.info(message, Later, InstallManually, InstallAll)
.then((answer) => {
if (answer === InstallAll) {
const tasks = items.map((item) =>
this.createInstallTask(item, installable)
);
this.executeTasks(tasks);
} else if (answer === InstallManually) {
viewContribution
.openView({ reveal: true })
.then((widget) => widget.refresh(viewSearchOptions));
}
});
}

private async executeTasks(tasks: Task<ArduinoComponent>[]): Promise<void> {
Expand All @@ -139,21 +144,33 @@ export class CheckForUpdates extends Contribution {
nls.localize('arduino/checkForUpdates/updating', 'Updating'),
this.messageService,
async (progress) => {
const total = tasks.length;
let count = 0;
for (const { run, item } of tasks) {
progress.report({
message: item.name,
});
await run();
progress.report({ work: { total, done: ++count } });
try {
const total = tasks.length;
let count = 0;
for (const { run, item } of tasks) {
// progress.report({
// message: item.name,
// });
try {
await run(); // runs update sequentially. // TODO: is parallel update desired?
} catch (err) {
console.error(err);
this.messageService.error(
`Failed to update ${item.name}. ${err}`
);
} finally {
progress.report({ work: { total, done: ++count } });
}
}
} finally {
progress.cancel();
}
}
);
}
}

private installTask<T extends ArduinoComponent>(
private createInstallTask<T extends ArduinoComponent>(
item: T,
installable: Installable<T>
): Task<T> {
Expand Down
1 change: 0 additions & 1 deletion arduino-ide-extension/src/browser/style/list-widget.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
}

.arduino-list-widget .filter-bar {
display: flex;
margin: 0px 10px 5px 15px;
}

Expand Down
5 changes: 0 additions & 5 deletions arduino-ide-extension/src/common/protocol/installable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ export interface Installable<T extends ArduinoComponent> {
* Uninstalls the given component. It is a NOOP if not installed.
*/
uninstall(options: { item: T; progressId?: string }): Promise<void>;

/**
* Returns with a promise which resolves all component that is installed but has a more recent version available.
*/
updateables(): Promise<T[]>;
}
export namespace Installable {
export type Version = string;
Expand Down
4 changes: 0 additions & 4 deletions arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ export class BoardsServiceImpl
);
}

updateables(): Promise<BoardsPackage[]> {
return this.search({ type: 'Updatable' });
}

async searchBoards({
query,
}: {
Expand Down
4 changes: 0 additions & 4 deletions arduino-ide-extension/src/node/library-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ export class LibraryServiceImpl
return (item: LibraryPackage) => item.category === topic;
}

async updateables(): Promise<LibraryPackage[]> {
return this.search({ type: 'Updatable' });
}

async list({
fqbn,
}: {
Expand Down