diff --git a/ts/updater/common.ts b/ts/updater/common.ts index 4450779ac6c8..88f3f8e0bf8d 100644 --- a/ts/updater/common.ts +++ b/ts/updater/common.ts @@ -118,7 +118,10 @@ export abstract class Updater { protected readonly getMainWindow: () => BrowserWindow | undefined; - private throttledSendDownloadingUpdate: ((downloadedSize: number) => void) & { + private throttledSendDownloadingUpdate: (( + downloadedSize: number, + downloadSize: number + ) => void) & { cancel: () => void; }; @@ -141,14 +144,17 @@ export abstract class Updater { this.getMainWindow = getMainWindow; this.canRunSilently = canRunSilently; - this.throttledSendDownloadingUpdate = throttle((downloadedSize: number) => { - const mainWindow = this.getMainWindow(); - mainWindow?.webContents.send( - 'show-update-dialog', - DialogType.Downloading, - { downloadedSize } - ); - }, 50); + this.throttledSendDownloadingUpdate = throttle( + (downloadedSize: number, downloadSize: number) => { + const mainWindow = this.getMainWindow(); + mainWindow?.webContents.send( + 'show-update-dialog', + DialogType.Downloading, + { downloadedSize, downloadSize } + ); + }, + 50 + ); } // @@ -156,6 +162,7 @@ export abstract class Updater { // public async force(): Promise { + this.markedCannotUpdate = false; return this.checkForUpdatesMaybeInstall(CheckType.ForceDownload); } @@ -605,7 +612,7 @@ export abstract class Updater { } private async downloadUpdate( - { fileName, sha512, differentialData }: UpdateInformationType, + { fileName, sha512, differentialData, size }: UpdateInformationType, mode: DownloadMode ): Promise { const baseUrl = getUpdatesBase(); @@ -728,6 +735,7 @@ export abstract class Updater { await this.downloadAndReport( updateFileUrl, + size, tempUpdatePath, updateOnProgress ); @@ -798,6 +806,7 @@ export abstract class Updater { private async downloadAndReport( updateFileUrl: string, + downloadSize: number, targetUpdatePath: string, updateOnProgress = false ): Promise { @@ -810,7 +819,7 @@ export abstract class Updater { downloadStream.on('data', data => { downloadedSize += data.length; - this.throttledSendDownloadingUpdate(downloadedSize); + this.throttledSendDownloadingUpdate(downloadedSize, downloadSize); }); } diff --git a/ts/updater/differential.ts b/ts/updater/differential.ts index 04fd924d4b28..fcaf769c330e 100644 --- a/ts/updater/differential.ts +++ b/ts/updater/differential.ts @@ -72,7 +72,7 @@ export type PrepareDownloadOptionsType = Readonly<{ }>; export type DownloadOptionsType = Readonly<{ - statusCallback?: (downloadedSize: number) => void; + statusCallback?: (downloadedSize: number, downloadSize: number) => void; logger?: LoggerType; // Testing @@ -286,6 +286,10 @@ export async function download( ); const downloadActions = diff.filter(({ action }) => action === 'download'); + let downloadSize = 0; + for (const { size } of downloadActions) { + downloadSize += size; + } try { let downloadedSize = 0; @@ -302,7 +306,7 @@ export async function download( chunkStatusCallback(chunkSize) { downloadedSize += chunkSize; if (!abortSignal.aborted) { - statusCallback?.(downloadedSize); + statusCallback?.(downloadedSize, downloadSize); } }, }),