5.2 KiB
5.2 KiB
Download Manager Architecture
The download manager is a desktop-only feature that layers a curated queue, progress tracking, storage configuration, and playback controls on top of the existing Xtream (xtream-electron folder) + Stalker viewers. Backend work is handled in the Electron process while the Angular renderer surface exposes a dedicated /downloads route, contextual buttons, and theme-aware styling.
Backend responsibilities
- Queue control (apps/electron-backend/src/app/events/downloads.events.ts)
DownloadTaskmirrors the sharedDownloadItemtable plus transient cancel/progress helpers.enqueueDownload()resolves a unique file path, persists aqueuedrow indownloads, pushes the task ontodownloadQueue, and triggersprocessQueue().processQueue()keeps one active download, updates the row todownloading, and callsstartDownload(). - electron-dl integration
startDownload()now callselectron-dl’sdownload()helper. Headers (user agent, referer, origin) are attached, and theonStarted,onProgress,onCompleted, andonCancelcallbacks translate the helper’s payload into Drizzle updates. The handler throttles progress broadcast, savesfilePath/fileNamefromelectron-dl, and marks failures/cancellations cleanly. Errors and cancellations delete partial files. - IPC surface
The backend exposesDOWNLOADS_*handlers for list retrieval, start/cancel/retry/remove operations, folder selection/reveal, and theDOWNLOADS_UPDATE_EVENTemitter that the renderer listens to in order to refresh its signal store.
Renderer architecture
- Downloads service (
apps/web/src/app/services/downloads.service.ts) Signals back the current download list whilehasDownloadsandisAvailablegates UI rendering. Before each download the service resolves a download folder (stored inSettingsStoreor fetched viadownloadsGetDefaultFolder) and callsdownloadsStart. The backend extracts the file extension from the URL or falls back tomp4.onDownloadsUpdateupdates the signal, while helper methodsretryDownload,removeDownload,cancelDownload, andplayDownloadtalk to the corresponding IPC commands so retries reuse existing rows and completed items can open the recorded path. - Downloads view (
libs/portal/downloads/feature)
A standalone page exposes the queue, desktop-only messaging, folder picker, and action buttons.downloads.component.htmlnow wraps the list inside a scrollable panel (downloads__list-wrapper) so long queues stay reachable, anddownloads.component.scssdrives a bold two-tone aesthetic inspired by the frontend-design mandate—gradient cards, floating avatars, and theme-aware variables triggered viabody.dark-theme. Failed/canceled cards now show retry/delete controls, queued/downloading cards show a cancel icon, and completed cards render inline play/open buttons withmat-iconcues. The header also shows the resolved download folder and aCHANGE FOLDERaction. - Theme fixes
To keep typography legible in both modes,app-search-result-itemnow inherits color from:host-context(body.dark-theme)and:host-context(body:not(.dark-theme)), ensuring dense light-theme grids no longer show white text on white backgrounds.
Global API surface
- Preload + types
apps/electron-backend/src/app/api/main.preload.tswires every download IPC command plus theonDownloadsUpdatelistener towindow.electron.global.d.tsnow mirrors those methods, adds playback-position helpers, and exposesonPlaybackPositionUpdate/removePlaybackPositionListenerso Angular can type-check the new APIs. This keeps the renderer typing in sync with the backend implementation.
Routing and navigation
/downloadsis available under both portal flavors: the Xtream routes already loadDownloadsComponent, and the Stalker routes now import the same component so the sidebar link can target/stalker/:id/downloadswithout returning to the startup screen.- The navigation component already points
routerLink="./downloads"inside the shared nav pane, so both portals reuse the same download page.
Queuing, persistence, and UX notes
- Every download row writes to the shared
downloadstable with statuses (queued,downloading,completed,failed,canceled) plus metadata such asbytesDownloaded,totalBytes,errorMessage, and Xtream identifiers. Stale downloads reset tofailedon startup. - Queue cancellation removes the task or calls
downloadItem.cancel()if the item is active; retries reuse the same database entry, preventing duplicate rows. - Folder selection first checks stored preferences, falls back to the OS default downloads path, and finally prompts the user to pick a folder. The downloads service persists the chosen path via
SettingsStore. - The new UI leverages CSS variables for theme-specific backgrounds/borders, ensures
.downloads__listcan scroll inside its panel, and brings consistent badge/typography treatments to each card.
Keeping the backend queue, IPC handlers, shared schema, and renderer signals synchronized minimizes drift between platform rules and the UI. Future work might cover download list filters, cancel-all actions, or integration with upcoming playback analytics.