diff --git a/packages/electron-updater/src/MacUpdater.ts b/packages/electron-updater/src/MacUpdater.ts index b8a8369448f..b63cfc3362d 100644 --- a/packages/electron-updater/src/MacUpdater.ts +++ b/packages/electron-updater/src/MacUpdater.ts @@ -1,6 +1,7 @@ import { AllPublishOptions, newError, safeStringifyJson, CURRENT_MAC_APP_ZIP_FILE_NAME } from "builder-util-runtime" import { stat } from "fs-extra" -import { createReadStream, copyFileSync } from "fs" +import { createReadStream, copyFileSync, readFileSync, writeFileSync } from "fs" +import { join } from "path" import { createServer, IncomingMessage, Server, ServerResponse } from "http" import { AppAdapter } from "./AppAdapter" import { AppUpdater, DownloadUpdateOptions } from "./AppUpdater" @@ -86,10 +87,19 @@ export class MacUpdater extends AppUpdater { fileInfo: zipFileInfo, downloadUpdateOptions, task: async (destinationFile, downloadOptions) => { - if (await this.differentialDownloadInstaller(zipFileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_MAC_APP_ZIP_FILE_NAME)) { + const currentVersionFileName = "currentVersion" + const currentVersion = readFileSync(currentVersionFileName, "utf8") + let differentialDownloadedFailed = false + if (currentVersion === this.app.version) { + differentialDownloadedFailed = await this.differentialDownloadInstaller(zipFileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_MAC_APP_ZIP_FILE_NAME) + } + + if (differentialDownloadedFailed) { await this.httpExecutor.download(zipFileInfo.url, destinationFile, downloadOptions) } - copyFileSync(destinationFile, this.downloadedUpdateHelper!.cacheDir + "/update.zip") + + copyFileSync(destinationFile, join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)) + writeFileSync(currentVersionFileName, downloadUpdateOptions.updateInfoAndProvider.info.version) }, done: event => this.updateDownloaded(zipFileInfo, event), })