2024-09-16 15:38:12 -04:00
|
|
|
// Copyright 2024 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-11-13 12:30:35 -05:00
|
|
|
import { AttachmentDownloadManager } from '../jobs/AttachmentDownloadManager';
|
2025-07-18 18:19:02 -05:00
|
|
|
import { createLogger } from '../logging/log';
|
2024-09-16 15:38:12 -04:00
|
|
|
import { DataWriter } from '../sql/Client';
|
2024-11-13 12:30:35 -05:00
|
|
|
|
2025-07-18 18:19:02 -05:00
|
|
|
const log = createLogger('backupMediaDownload');
|
|
|
|
|
2024-11-13 12:30:35 -05:00
|
|
|
export async function startBackupMediaDownload(): Promise<void> {
|
|
|
|
await window.storage.put('backupMediaDownloadPaused', false);
|
|
|
|
|
|
|
|
await AttachmentDownloadManager.start();
|
|
|
|
}
|
2024-09-16 15:38:12 -04:00
|
|
|
|
|
|
|
export async function pauseBackupMediaDownload(): Promise<void> {
|
2025-07-18 18:19:02 -05:00
|
|
|
log.info('Pausing media download');
|
2024-09-16 15:38:12 -04:00
|
|
|
await window.storage.put('backupMediaDownloadPaused', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function resumeBackupMediaDownload(): Promise<void> {
|
2025-07-18 18:19:02 -05:00
|
|
|
log.info('Resuming media download');
|
2024-11-13 12:30:35 -05:00
|
|
|
return startBackupMediaDownload();
|
2024-09-16 15:38:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function resetBackupMediaDownloadItems(): Promise<void> {
|
|
|
|
await Promise.all([
|
|
|
|
window.storage.remove('backupMediaDownloadTotalBytes'),
|
|
|
|
window.storage.remove('backupMediaDownloadCompletedBytes'),
|
|
|
|
window.storage.remove('backupMediaDownloadBannerDismissed'),
|
|
|
|
window.storage.remove('backupMediaDownloadPaused'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function cancelBackupMediaDownload(): Promise<void> {
|
2025-07-18 18:19:02 -05:00
|
|
|
log.info('Canceling media download');
|
|
|
|
await window.storage.put('backupMediaDownloadBannerDismissed', true);
|
2024-09-16 15:38:12 -04:00
|
|
|
await DataWriter.removeAllBackupAttachmentDownloadJobs();
|
2025-07-18 18:19:02 -05:00
|
|
|
await DataWriter.resetBackupAttachmentDownloadStats();
|
2024-09-16 15:38:12 -04:00
|
|
|
await resetBackupMediaDownloadItems();
|
|
|
|
}
|
|
|
|
|
2024-09-23 15:24:41 -04:00
|
|
|
export async function resetBackupMediaDownloadProgress(): Promise<void> {
|
2025-07-18 18:19:02 -05:00
|
|
|
await DataWriter.removeAllBackupAttachmentDownloadJobs();
|
|
|
|
await DataWriter.resetBackupAttachmentDownloadStats();
|
2024-09-16 15:38:12 -04:00
|
|
|
await resetBackupMediaDownloadItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function dismissBackupMediaDownloadBanner(): Promise<void> {
|
|
|
|
await window.storage.put('backupMediaDownloadBannerDismissed', true);
|
|
|
|
}
|