Skip to content

Commit

Permalink
fix: macUpdater - change copyFileSync to async operation to unblock…
Browse files Browse the repository at this point in the history
… the main thread (electron-userland#8623)

Fix electron-userland#8622

Co-authored-by: Damon Yu <[email protected]>
  • Loading branch information
DamonYu6 and damonyu666 authored Oct 23, 2024
1 parent 74d98d8 commit cfa67c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-schools-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix: copyFileSync operation will block the main thread
8 changes: 4 additions & 4 deletions packages/electron-updater/src/MacUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AllPublishOptions, newError, safeStringifyJson } from "builder-util-runtime"
import { pathExistsSync, stat } from "fs-extra"
import { createReadStream, copyFileSync } from "fs"
import { pathExistsSync, stat, copyFile } from "fs-extra"
import { createReadStream } from "fs"
import * as path from "path"
import { createServer, IncomingMessage, Server, ServerResponse } from "http"
import { AppAdapter } from "./AppAdapter"
Expand Down Expand Up @@ -117,11 +117,11 @@ export class MacUpdater extends AppUpdater {
await this.httpExecutor.download(zipFileInfo.url, destinationFile, downloadOptions)
}
},
done: event => {
done: async event => {
if (!downloadUpdateOptions.disableDifferentialDownload) {
try {
const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)
copyFileSync(event.downloadedFile, cachedUpdateFilePath)
await copyFile(event.downloadedFile, cachedUpdateFilePath)
} catch (error: any) {
this._logger.warn(`Unable to copy file for caching for future differential downloads: ${error.message}`)
}
Expand Down

0 comments on commit cfa67c0

Please sign in to comment.