Skip to content

Commit

Permalink
Fix the overwrite installation issue by different version
Browse files Browse the repository at this point in the history
  • Loading branch information
PayneFuRC committed Aug 13, 2023
1 parent bd97680 commit d1ff531
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions 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"
Expand Down Expand Up @@ -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),
})
Expand Down

0 comments on commit d1ff531

Please sign in to comment.