Fix download progress reporting for force update

This commit is contained in:
Fedor Indutny 2024-11-12 14:04:10 -08:00 committed by GitHub
parent 541ba6c9de
commit 8557de20c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 13 deletions

View file

@ -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<void> {
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<DownloadUpdateResultType | undefined> {
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<void> {
@ -810,7 +819,7 @@ export abstract class Updater {
downloadStream.on('data', data => {
downloadedSize += data.length;
this.throttledSendDownloadingUpdate(downloadedSize);
this.throttledSendDownloadingUpdate(downloadedSize, downloadSize);
});
}

View file

@ -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);
}
},
}),