electron-updater
Version:
Cross platform updater for electron applications
1 lines • 20.7 kB
Source Map (JSON)
{"version":3,"file":"MacUpdater.js","sourceRoot":"","sources":["../src/MacUpdater.ts"],"names":[],"mappings":";;;AAAA,+DAAqF;AACrF,uCAAyD;AACzD,2BAAqC;AACrC,6BAA4B;AAC5B,+BAA4E;AAE5E,6CAAgE;AAGhE,mDAA+C;AAE/C,iDAA4C;AAC5C,mCAAoC;AAEpC,MAAa,UAAW,SAAQ,uBAAU;IAOxC,YAAY,OAA2B,EAAE,GAAgB;QACvD,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;QAPJ,kBAAa,GAAgB,OAAO,CAAC,UAAU,CAAC,CAAC,WAAW,CAAA;QAErE,6BAAwB,GAAG,KAAK,CAAA;QAOtC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE;YAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACrB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QACxB,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC9C,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAA;YACpC,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,KAAK,CAAC,OAAe;QAC3B,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YAC/B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;IAEO,mBAAmB;QACzB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;YAClC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,E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A4QC","sourcesContent":["import { AllPublishOptions, newError, safeStringifyJson } from \"builder-util-runtime\"\nimport { pathExistsSync, stat, copyFile } from \"fs-extra\"\nimport { createReadStream } from \"fs\"\nimport * as path from \"path\"\nimport { createServer, IncomingMessage, Server, ServerResponse } from \"http\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { AppUpdater, DownloadUpdateOptions } from \"./AppUpdater\"\nimport { ResolvedUpdateFileInfo } from \"./main\"\nimport { UpdateDownloadedEvent } from \"./types\"\nimport { findFile } from \"./providers/Provider\"\nimport AutoUpdater = Electron.AutoUpdater\nimport { execFileSync } from \"child_process\"\nimport { randomBytes } from \"crypto\"\n\nexport class MacUpdater extends AppUpdater {\n private readonly nativeUpdater: AutoUpdater = require(\"electron\").autoUpdater\n\n private squirrelDownloadedUpdate = false\n\n private server?: Server\n\n constructor(options?: AllPublishOptions, app?: AppAdapter) {\n super(options, app)\n\n this.nativeUpdater.on(\"error\", it => {\n this._logger.warn(it)\n this.emit(\"error\", it)\n })\n this.nativeUpdater.on(\"update-downloaded\", () => {\n this.squirrelDownloadedUpdate = true\n this.debug(\"nativeUpdater.update-downloaded\")\n })\n }\n\n private debug(message: string): void {\n if (this._logger.debug != null) {\n this._logger.debug(message)\n }\n }\n\n private closeServerIfExists() {\n if (this.server) {\n this.debug(\"Closing proxy server\")\n this.server.close(err => {\n if (err) {\n this.debug(\"proxy server wasn't already open, probably attempted closing again as a safety check before quit\")\n }\n })\n }\n }\n\n protected async doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n let files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info)\n\n const log = this._logger\n\n // detect if we are running inside Rosetta emulation\n const sysctlRosettaInfoKey = \"sysctl.proc_translated\"\n let isRosetta = false\n try {\n this.debug(\"Checking for macOS Rosetta environment\")\n const result = execFileSync(\"sysctl\", [sysctlRosettaInfoKey], { encoding: \"utf8\" })\n isRosetta = result.includes(`${sysctlRosettaInfoKey}: 1`)\n log.info(`Checked for macOS Rosetta environment (isRosetta=${isRosetta})`)\n } catch (e: any) {\n log.warn(`sysctl shell command to check for macOS Rosetta environment failed: ${e}`)\n }\n\n let isArm64Mac = false\n try {\n this.debug(\"Checking for arm64 in uname\")\n const result = execFileSync(\"uname\", [\"-a\"], { encoding: \"utf8\" })\n const isArm = result.includes(\"ARM\")\n log.info(`Checked 'uname -a': arm64=${isArm}`)\n isArm64Mac = isArm64Mac || isArm\n } catch (e: any) {\n log.warn(`uname shell command to check for arm64 failed: ${e}`)\n }\n\n isArm64Mac = isArm64Mac || process.arch === \"arm64\" || isRosetta\n\n // allow arm64 macs to install universal or rosetta2(x64) - https://github.com/electron-userland/electron-builder/pull/5524\n const isArm64 = (file: ResolvedUpdateFileInfo) => file.url.pathname.includes(\"arm64\") || file.info.url?.includes(\"arm64\")\n if (isArm64Mac && files.some(isArm64)) {\n files = files.filter(file => isArm64Mac === isArm64(file))\n } else {\n files = files.filter(file => !isArm64(file))\n }\n\n const zipFileInfo = findFile(files, \"zip\", [\"pkg\", \"dmg\"])\n\n if (zipFileInfo == null) {\n throw newError(`ZIP file not provided: ${safeStringifyJson(files)}`, \"ERR_UPDATER_ZIP_FILE_NOT_FOUND\")\n }\n\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const CURRENT_MAC_APP_ZIP_FILE_NAME = \"update.zip\"\n\n return this.executeDownload({\n fileExtension: \"zip\",\n fileInfo: zipFileInfo,\n downloadUpdateOptions,\n task: async (destinationFile, downloadOptions) => {\n const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)\n const canDifferentialDownload = () => {\n if (!pathExistsSync(cachedUpdateFilePath)) {\n log.info(\"Unable to locate previous update.zip for differential download (is this first install?), falling back to full download\")\n return false\n }\n return !downloadUpdateOptions.disableDifferentialDownload\n }\n let differentialDownloadFailed = true\n if (canDifferentialDownload()) {\n differentialDownloadFailed = await this.differentialDownloadInstaller(zipFileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_MAC_APP_ZIP_FILE_NAME)\n }\n\n if (differentialDownloadFailed) {\n await this.httpExecutor.download(zipFileInfo.url, destinationFile, downloadOptions)\n }\n },\n done: async event => {\n if (!downloadUpdateOptions.disableDifferentialDownload) {\n try {\n const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)\n await copyFile(event.downloadedFile, cachedUpdateFilePath)\n } catch (error: any) {\n this._logger.warn(`Unable to copy file for caching for future differential downloads: ${error.message}`)\n }\n }\n return this.updateDownloaded(zipFileInfo, event)\n },\n })\n }\n\n private async updateDownloaded(zipFileInfo: ResolvedUpdateFileInfo, event: UpdateDownloadedEvent): Promise<Array<string>> {\n const downloadedFile = event.downloadedFile\n const updateFileSize = zipFileInfo.info.size ?? (await stat(downloadedFile)).size\n\n const log = this._logger\n const logContext = `fileToProxy=${zipFileInfo.url.href}`\n this.closeServerIfExists()\n this.debug(`Creating proxy server for native Squirrel.Mac (${logContext})`)\n this.server = createServer()\n this.debug(`Proxy server for native Squirrel.Mac is created (${logContext})`)\n this.server.on(\"close\", () => {\n log.info(`Proxy server for native Squirrel.Mac is closed (${logContext})`)\n })\n\n // must be called after server is listening, otherwise address is null\n const getServerUrl = (s: Server): string => {\n const address = s.address()\n if (typeof address === \"string\") {\n return address\n }\n return `http://127.0.0.1:${address?.port}`\n }\n\n return await new Promise<Array<string>>((resolve, reject) => {\n const pass = randomBytes(64).toString(\"base64\").replace(/\\//g, \"_\").replace(/\\+/g, \"-\")\n const authInfo = Buffer.from(`autoupdater:${pass}`, \"ascii\")\n\n // insecure random is ok\n const fileUrl = `/${randomBytes(64).toString(\"hex\")}.zip`\n this.server!.on(\"request\", (request: IncomingMessage, response: ServerResponse) => {\n const requestUrl = request.url!\n log.info(`${requestUrl} requested`)\n if (requestUrl === \"/\") {\n // check for basic auth header\n if (!request.headers.authorization || request.headers.authorization.indexOf(\"Basic \") === -1) {\n response.statusCode = 401\n response.statusMessage = \"Invalid Authentication Credentials\"\n response.end()\n log.warn(\"No authenthication info\")\n return\n }\n\n // verify auth credentials\n const base64Credentials = request.headers.authorization.split(\" \")[1]\n const credentials = Buffer.from(base64Credentials, \"base64\").toString(\"ascii\")\n const [username, password] = credentials.split(\":\")\n if (username !== \"autoupdater\" || password !== pass) {\n response.statusCode = 401\n response.statusMessage = \"Invalid Authentication Credentials\"\n response.end()\n log.warn(\"Invalid authenthication credentials\")\n return\n }\n\n const data = Buffer.from(`{ \"url\": \"${getServerUrl(this.server!)}${fileUrl}\" }`)\n response.writeHead(200, { \"Content-Type\": \"application/json\", \"Content-Length\": data.length })\n response.end(data)\n return\n }\n\n if (!requestUrl.startsWith(fileUrl)) {\n log.warn(`${requestUrl} requested, but not supported`)\n response.writeHead(404)\n response.end()\n return\n }\n\n log.info(`${fileUrl} requested by Squirrel.Mac, pipe ${downloadedFile}`)\n\n let errorOccurred = false\n response.on(\"finish\", () => {\n if (!errorOccurred) {\n this.nativeUpdater.removeListener(\"error\", reject)\n resolve([])\n }\n })\n\n const readStream = createReadStream(downloadedFile)\n readStream.on(\"error\", error => {\n try {\n response.end()\n } catch (e: any) {\n log.warn(`cannot end response: ${e}`)\n }\n errorOccurred = true\n this.nativeUpdater.removeListener(\"error\", reject)\n reject(new Error(`Cannot pipe \"${downloadedFile}\": ${error}`))\n })\n\n response.writeHead(200, {\n \"Content-Type\": \"application/zip\",\n \"Content-Length\": updateFileSize,\n })\n readStream.pipe(response)\n })\n\n this.debug(`Proxy server for native Squirrel.Mac is starting to listen (${logContext})`)\n\n this.server!.listen(0, \"127.0.0.1\", () => {\n this.debug(`Proxy server for native Squirrel.Mac is listening (address=${getServerUrl(this.server!)}, ${logContext})`)\n this.nativeUpdater.setFeedURL({\n url: getServerUrl(this.server!),\n headers: {\n \"Cache-Control\": \"no-cache\",\n Authorization: `Basic ${authInfo.toString(\"base64\")}`,\n },\n })\n\n // The update has been downloaded and is ready to be served to Squirrel\n this.dispatchUpdateDownloaded(event)\n\n if (this.autoInstallOnAppQuit) {\n this.nativeUpdater.once(\"error\", reject)\n // This will trigger fetching and installing the file on Squirrel side\n this.nativeUpdater.checkForUpdates()\n } else {\n resolve([])\n }\n })\n })\n }\n\n private handleUpdateDownloaded() {\n if (this.autoRunAppAfterInstall) {\n this.nativeUpdater.quitAndInstall()\n } else {\n this.app.quit()\n }\n this.closeServerIfExists()\n }\n\n quitAndInstall(): void {\n if (this.squirrelDownloadedUpdate) {\n // update already fetched by Squirrel, it's ready to install\n this.handleUpdateDownloaded()\n } else {\n // Quit and install as soon as Squirrel get the update\n this.nativeUpdater.on(\"update-downloaded\", () => this.handleUpdateDownloaded())\n\n if (!this.autoInstallOnAppQuit) {\n /**\n * If this was not `true` previously then MacUpdater.doDownloadUpdate()\n * would not actually initiate the downloading by electron's autoUpdater\n */\n this.nativeUpdater.checkForUpdates()\n }\n }\n }\n}\n"]}