Fix download progress reporting for force update
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
ee5ba7c32d
commit
fece7b0e42
2 changed files with 26 additions and 13 deletions
|
@ -118,7 +118,10 @@ export abstract class Updater {
|
||||||
|
|
||||||
protected readonly getMainWindow: () => BrowserWindow | undefined;
|
protected readonly getMainWindow: () => BrowserWindow | undefined;
|
||||||
|
|
||||||
private throttledSendDownloadingUpdate: ((downloadedSize: number) => void) & {
|
private throttledSendDownloadingUpdate: ((
|
||||||
|
downloadedSize: number,
|
||||||
|
downloadSize: number
|
||||||
|
) => void) & {
|
||||||
cancel: () => void;
|
cancel: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -141,14 +144,17 @@ export abstract class Updater {
|
||||||
this.getMainWindow = getMainWindow;
|
this.getMainWindow = getMainWindow;
|
||||||
this.canRunSilently = canRunSilently;
|
this.canRunSilently = canRunSilently;
|
||||||
|
|
||||||
this.throttledSendDownloadingUpdate = throttle((downloadedSize: number) => {
|
this.throttledSendDownloadingUpdate = throttle(
|
||||||
const mainWindow = this.getMainWindow();
|
(downloadedSize: number, downloadSize: number) => {
|
||||||
mainWindow?.webContents.send(
|
const mainWindow = this.getMainWindow();
|
||||||
'show-update-dialog',
|
mainWindow?.webContents.send(
|
||||||
DialogType.Downloading,
|
'show-update-dialog',
|
||||||
{ downloadedSize }
|
DialogType.Downloading,
|
||||||
);
|
{ downloadedSize, downloadSize }
|
||||||
}, 50);
|
);
|
||||||
|
},
|
||||||
|
50
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -156,6 +162,7 @@ export abstract class Updater {
|
||||||
//
|
//
|
||||||
|
|
||||||
public async force(): Promise<void> {
|
public async force(): Promise<void> {
|
||||||
|
this.markedCannotUpdate = false;
|
||||||
return this.checkForUpdatesMaybeInstall(CheckType.ForceDownload);
|
return this.checkForUpdatesMaybeInstall(CheckType.ForceDownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,7 +612,7 @@ export abstract class Updater {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async downloadUpdate(
|
private async downloadUpdate(
|
||||||
{ fileName, sha512, differentialData }: UpdateInformationType,
|
{ fileName, sha512, differentialData, size }: UpdateInformationType,
|
||||||
mode: DownloadMode
|
mode: DownloadMode
|
||||||
): Promise<DownloadUpdateResultType | undefined> {
|
): Promise<DownloadUpdateResultType | undefined> {
|
||||||
const baseUrl = getUpdatesBase();
|
const baseUrl = getUpdatesBase();
|
||||||
|
@ -728,6 +735,7 @@ export abstract class Updater {
|
||||||
|
|
||||||
await this.downloadAndReport(
|
await this.downloadAndReport(
|
||||||
updateFileUrl,
|
updateFileUrl,
|
||||||
|
size,
|
||||||
tempUpdatePath,
|
tempUpdatePath,
|
||||||
updateOnProgress
|
updateOnProgress
|
||||||
);
|
);
|
||||||
|
@ -798,6 +806,7 @@ export abstract class Updater {
|
||||||
|
|
||||||
private async downloadAndReport(
|
private async downloadAndReport(
|
||||||
updateFileUrl: string,
|
updateFileUrl: string,
|
||||||
|
downloadSize: number,
|
||||||
targetUpdatePath: string,
|
targetUpdatePath: string,
|
||||||
updateOnProgress = false
|
updateOnProgress = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
@ -810,7 +819,7 @@ export abstract class Updater {
|
||||||
|
|
||||||
downloadStream.on('data', data => {
|
downloadStream.on('data', data => {
|
||||||
downloadedSize += data.length;
|
downloadedSize += data.length;
|
||||||
this.throttledSendDownloadingUpdate(downloadedSize);
|
this.throttledSendDownloadingUpdate(downloadedSize, downloadSize);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ export type PrepareDownloadOptionsType = Readonly<{
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type DownloadOptionsType = Readonly<{
|
export type DownloadOptionsType = Readonly<{
|
||||||
statusCallback?: (downloadedSize: number) => void;
|
statusCallback?: (downloadedSize: number, downloadSize: number) => void;
|
||||||
logger?: LoggerType;
|
logger?: LoggerType;
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
|
@ -286,6 +286,10 @@ export async function download(
|
||||||
);
|
);
|
||||||
|
|
||||||
const downloadActions = diff.filter(({ action }) => action === 'download');
|
const downloadActions = diff.filter(({ action }) => action === 'download');
|
||||||
|
let downloadSize = 0;
|
||||||
|
for (const { size } of downloadActions) {
|
||||||
|
downloadSize += size;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let downloadedSize = 0;
|
let downloadedSize = 0;
|
||||||
|
@ -302,7 +306,7 @@ export async function download(
|
||||||
chunkStatusCallback(chunkSize) {
|
chunkStatusCallback(chunkSize) {
|
||||||
downloadedSize += chunkSize;
|
downloadedSize += chunkSize;
|
||||||
if (!abortSignal.aborted) {
|
if (!abortSignal.aborted) {
|
||||||
statusCallback?.(downloadedSize);
|
statusCallback?.(downloadedSize, downloadSize);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Reference in a new issue