mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-15 21:56:18 -08:00
fix(downloads): keep renderer download state global
This commit is contained in:
1 parent
505face7e4
commit
117bd75f01
11 files changed
+102
-23
No files matched your search
@@ -37,7 +37,7 @@ type DownloadsElectronStub = {
|
||||
[number, string]
|
||||
>;
|
||||
downloadsSelectFolder?: jest.Mock<Promise<string | null>, []>;
|
||||
downloadsGetList: jest.Mock<Promise<DownloadItem[]>, [string?]>;
|
||||
downloadsGetList: jest.Mock<Promise<DownloadItem[]>, []>;
|
||||
};
|
||||
|
||||
describe('DownloadsService', () => {
|
||||
@@ -121,7 +121,7 @@ describe('DownloadsService', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('tracks loading and loaded state around a successful download list request', async () => {
|
||||
it('loads the global download list without a playlist filter and tracks request state', async () => {
|
||||
const item = createDownload(1);
|
||||
const pending = createDeferred<DownloadItem[]>();
|
||||
const electron = {
|
||||
@@ -130,11 +130,11 @@ describe('DownloadsService', () => {
|
||||
testWindow.electron = electron;
|
||||
const service = createService();
|
||||
|
||||
const request = service.loadDownloads('playlist-1');
|
||||
const request = service.loadDownloads();
|
||||
|
||||
expect(service.isLoadingDownloads()).toBe(true);
|
||||
expect(service.hasLoadedDownloads()).toBe(false);
|
||||
expect(electron.downloadsGetList).toHaveBeenCalledWith('playlist-1');
|
||||
expect(electron.downloadsGetList).toHaveBeenCalledWith();
|
||||
|
||||
pending.resolve([item]);
|
||||
await request;
|
||||
@@ -245,8 +245,8 @@ describe('DownloadsService', () => {
|
||||
testWindow.electron = electron;
|
||||
const service = createService();
|
||||
|
||||
const firstRequest = service.loadDownloads('playlist-old');
|
||||
const secondRequest = service.loadDownloads('playlist-new');
|
||||
const firstRequest = service.loadDownloads();
|
||||
const secondRequest = service.loadDownloads();
|
||||
|
||||
expect(service.isLoadingDownloads()).toBe(true);
|
||||
|
||||
@@ -262,14 +262,8 @@ describe('DownloadsService', () => {
|
||||
|
||||
expect(service.downloads()).toEqual([latestItem]);
|
||||
expect(service.isLoadingDownloads()).toBe(false);
|
||||
expect(electron.downloadsGetList).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'playlist-old'
|
||||
);
|
||||
expect(electron.downloadsGetList).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
'playlist-new'
|
||||
);
|
||||
expect(electron.downloadsGetList).toHaveBeenNthCalledWith(1);
|
||||
expect(electron.downloadsGetList).toHaveBeenNthCalledWith(2);
|
||||
});
|
||||
|
||||
it('reports paused content and resumes it by content identity', async () => {
|
||||
|
||||
@@ -106,14 +106,14 @@ export class DownloadsService implements OnDestroy {
|
||||
/**
|
||||
* Load downloads from the backend
|
||||
*/
|
||||
async loadDownloads(playlistId?: string): Promise<void> {
|
||||
async loadDownloads(): Promise<void> {
|
||||
if (!this.isAvailable()) return;
|
||||
|
||||
const requestId = ++this.loadDownloadsRequestId;
|
||||
this._isLoadingDownloads.set(true);
|
||||
|
||||
try {
|
||||
const list = await window.electron.downloadsGetList(playlistId);
|
||||
const list = await window.electron.downloadsGetList();
|
||||
if (requestId === this.loadDownloadsRequestId) {
|
||||
this.downloads.set(list);
|
||||
this._hasLoadedDownloads.set(true);
|
||||
|
||||
Reference in new issue
Block a user