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B;AACA,YAAA,UAAU,CAAC,EAAX,CAAc,OAAd,EAAuB,KAAK,IAAG;AAC7B,kBAAI;AACF,gBAAA,QAAQ,CAAC,GAAT;AACD,eAFD,CAGA,OAAO,CAAP,EAAU;AACR,qBAAK,OAAL,CAAa,IAAb,CAAkB,wBAAwB,CAAC,EAA3C;AACD;;AACD,cAAA,aAAa,GAAG,IAAhB;AACA,mBAAK,aAAL,CAAmB,cAAnB,CAAkC,OAAlC,EAA2C,MAA3C;AACA,cAAA,MAAM,CAAC,IAAI,KAAJ,CAAU,gBAAgB,cAAc,MAAM,KAAK,EAAnD,CAAD,CAAN;AACD,aAVD;AAYA,YAAA,QAAQ,CAAC,SAAT,CAAmB,GAAnB,EAAwB;AACtB,8BAAgB,iBADM;AAEtB,gCAAkB;AAFI,aAAxB;AAIA,YAAA,UAAU,CAAC,IAAX,CAAgB,QAAhB;AACD,WAlDD;AAmDA,UAAA,MAAM,CAAC,MAAP,CAAc,CAAd,EAAiB,WAAjB,EAA8B,MAAK;AACjC,iBAAK,aAAL,CAAmB,UAAnB,CAA8B;AAC5B,cAAA,GAAG,EAAE,YAAY,EADW;AAE5B,cAAA,OAAO,EAAE;AAAC,iCAAiB;AAAlB;AAFmB,aAA9B;AAKA,iBAAK,aAAL,CAAmB,IAAnB,CAAwB,OAAxB,EAAiC,MAAjC;AACA,iBAAK,aAAL,CAAmB,eAAnB;AACD,WARD;AASD,SA/DY,CAAb;AAgED;AA/EyB,KAArB,CAAP;AAiFD;;AAED,EAAA,cAAc,GAAA;AACZ,SAAK,aAAL,CAAmB,cAAnB;AACD;;AA5HuC,C","sourcesContent":["import { AllPublishOptions, newError, safeStringifyJson } from \"builder-util-runtime\"\nimport { stat } from \"fs-extra\"\nimport { createReadStream } from \"fs\"\nimport { createServer, IncomingMessage, ServerResponse } from \"http\"\nimport { AddressInfo } from \"net\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { AppUpdater, DownloadUpdateOptions } from \"./AppUpdater\"\nimport { UpdateDownloadedEvent } from \"./main\"\nimport { findFile } from \"./providers/Provider\"\nimport AutoUpdater = Electron.AutoUpdater\n\nexport class MacUpdater extends AppUpdater {\n private readonly nativeUpdater: AutoUpdater = require(\"electron\").autoUpdater\n\n private updateInfoForPendingUpdateDownloadedEvent: UpdateDownloadedEvent | null = null\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 const updateInfo = this.updateInfoForPendingUpdateDownloadedEvent\n this.updateInfoForPendingUpdateDownloadedEvent = null\n this.dispatchUpdateDownloaded(updateInfo!!)\n })\n }\n\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n this.updateInfoForPendingUpdateDownloadedEvent = null\n\n const files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info)\n .filter(file => (process.arch == 'arm64') === (file.url.pathname.includes('arm64')));\n const zipFileInfo = findFile(files, \"zip\", [\"pkg\", \"dmg\"])\n if (zipFileInfo == null) {\n throw newError(`ZIP file not provided: ${safeStringifyJson(files)}`, \"ERR_UPDATER_ZIP_FILE_NOT_FOUND\")\n }\n\n const server = createServer()\n server.on(\"close\", () => {\n this._logger.info(`Proxy server for native Squirrel.Mac is closed (was started to download ${zipFileInfo.url.href})`)\n })\n\n function getServerUrl(): string {\n const address = server.address() as AddressInfo\n return `http://127.0.0.1:${address.port}`\n }\n\n return this.executeDownload({\n fileExtension: \"zip\",\n fileInfo: zipFileInfo,\n downloadUpdateOptions,\n task: (destinationFile, downloadOptions) => {\n return this.httpExecutor.download(zipFileInfo.url, destinationFile, downloadOptions)\n },\n done: async event => {\n const downloadedFile = event.downloadedFile\n this.updateInfoForPendingUpdateDownloadedEvent = event\n let updateFileSize = zipFileInfo.info.size\n if (updateFileSize == null) {\n updateFileSize = (await stat(downloadedFile)).size\n }\n\n return await new Promise<Array<string>>((resolve, reject) => {\n // insecure random is ok\n const fileUrl = \"/\" + Date.now() + \"-\" + Math.floor(Math.random() * 9999) + \".zip\"\n server.on(\"request\", (request: IncomingMessage, response: ServerResponse) => {\n const requestUrl = request.url!!\n this._logger.info(`${requestUrl} requested`)\n if (requestUrl === \"/\") {\n const data = Buffer.from(`{ \"url\": \"${getServerUrl()}${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 this._logger.warn(`${requestUrl} requested, but not supported`)\n response.writeHead(404)\n response.end()\n return\n }\n\n this._logger.info(`${fileUrl} requested by Squirrel.Mac, pipe ${downloadedFile}`)\n\n let errorOccurred = false\n response.on(\"finish\", () => {\n try {\n setImmediate(() => server.close())\n }\n finally {\n if (!errorOccurred) {\n this.nativeUpdater.removeListener(\"error\", reject)\n resolve([])\n }\n }\n })\n\n const readStream = createReadStream(downloadedFile)\n readStream.on(\"error\", error => {\n try {\n response.end()\n }\n catch (e) {\n this._logger.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 server.listen(0, \"127.0.0.1\", () => {\n this.nativeUpdater.setFeedURL({\n url: getServerUrl(),\n headers: {\"Cache-Control\": \"no-cache\"},\n })\n\n this.nativeUpdater.once(\"error\", reject)\n this.nativeUpdater.checkForUpdates()\n })\n })\n }\n })\n }\n\n quitAndInstall(): void {\n this.nativeUpdater.quitAndInstall()\n }\n}"],"sourceRoot":""}