refactor(frontend): adopt the lifecycle and the notification surface
The remaining views, brought onto the two mechanisms added earlier in this series. The lifecycle: every cached primary view moves its document listeners, intervals and event subscriptions off connect/disconnect and onto `viewActivated`/`viewDeactivated`, so `autotag-view` stops fielding keystrokes from Settings, `downloads-view`'s 30 s clock stops ticking for the session, and an off-screen view stops rendering on every search keystroke. `autotag-view` keeps a document listener only for Escape, whose dialogs Phase 5 migrates to wa-dialog anyway. The voice: the silent failures now speak — scan and full rescan (with a guard against the double-click the coalescing window allowed), job pause/resume/cancel, playlist delete, download request pause/remove/ clear, add and rename library, add-to-playlist, playlist track removal, autotag's dialogs and its apply, and favourite reverts. Both private toasts are gone, along with their CSS and keyframes. Playlist delete (single and the multi-select loop), download-request removal, download-client removal and a queue clear over 20 tracks ask first. Loading, empty and failed become three states rather than one, in `track-list` and `genre-details` — the first is on the first screen a new user ever sees — and the Settings index panel seeds itself with `GetIndexStatus()` instead of waiting forever for a change event. `smart-playlist-editor` and `download-picker` take the request-version guard `explore-view` already had. `track-details` loads through one memoised dynamic import in all ten openers, which is what takes its 42 kB out of the startup chunk: an un-upgraded custom element is a real HTMLElement on which `?.show()` throws, so each opener awaits it before touching the element its template already rendered.
This commit is contained in:
@@ -9,6 +9,7 @@ import type { DownloadCandidate } from '@store/download-store';
|
||||
import { downloadStore } from '@store/download-store';
|
||||
import type { download } from '@go/models';
|
||||
import './candidate-row';
|
||||
import { explainError } from '@utils/describe-error';
|
||||
|
||||
/**
|
||||
* The "find this album" dialog: searches every enabled download client,
|
||||
@@ -123,8 +124,17 @@ export class DownloadPicker extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monotonic search version. Closing and reopening the dialog for a
|
||||
* different album used to let the first search's result overwrite
|
||||
* the second's (errors.m8); the guard is `explore-view`'s.
|
||||
*/
|
||||
private searchVersion = 0;
|
||||
|
||||
/** Runs the search that populates the dialog. */
|
||||
private async search(): Promise<void> {
|
||||
const version = ++this.searchVersion;
|
||||
|
||||
this.searching = true;
|
||||
this.errorMessage = '';
|
||||
this.candidates = [];
|
||||
@@ -141,13 +151,23 @@ export class DownloadPicker extends LitElement {
|
||||
expected: this.expected ?? [],
|
||||
} as download.SearchRequest);
|
||||
|
||||
if (version !== this.searchVersion) return;
|
||||
|
||||
this.downloadId = result.downloadId;
|
||||
this.candidates = result.candidates ?? [];
|
||||
this.autoPicked = result.autoPicked;
|
||||
} catch (err) {
|
||||
this.errorMessage = String(err);
|
||||
if (version !== this.searchVersion) return;
|
||||
|
||||
console.error('download search failed', err);
|
||||
this.errorMessage = explainError(
|
||||
err,
|
||||
'The search did not finish.',
|
||||
);
|
||||
} finally {
|
||||
this.searching = false;
|
||||
if (version === this.searchVersion) {
|
||||
this.searching = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +181,11 @@ export class DownloadPicker extends LitElement {
|
||||
await downloadStore.pick(this.downloadId, event.detail.candidateId);
|
||||
this.close();
|
||||
} catch (err) {
|
||||
this.errorMessage = String(err);
|
||||
console.error('download pick failed', err);
|
||||
this.errorMessage = explainError(
|
||||
err,
|
||||
'That download could not be started.',
|
||||
);
|
||||
} finally {
|
||||
this.picking = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user