electron-updater 4.3.7 → 4.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,6 +59,16 @@ function _FileWithEmbeddedBlockMapDifferentialDownloader() {
59
59
  return data;
60
60
  }
61
61
 
62
+ function _main() {
63
+ const data = require("./main");
64
+
65
+ _main = function () {
66
+ return data;
67
+ };
68
+
69
+ return data;
70
+ }
71
+
62
72
  function _Provider() {
63
73
  const data = require("./providers/Provider");
64
74
 
@@ -111,14 +121,21 @@ class AppImageUpdater extends _BaseUpdater().BaseUpdater {
111
121
  let isDownloadFull = false;
112
122
 
113
123
  try {
114
- await new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(fileInfo.info, this.httpExecutor, {
124
+ const downloadOptions = {
115
125
  newUrl: fileInfo.url,
116
126
  oldFile,
117
127
  logger: this._logger,
118
128
  newFile: updateFile,
119
129
  isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,
120
- requestHeaders: downloadUpdateOptions.requestHeaders
121
- }).download();
130
+ requestHeaders: downloadUpdateOptions.requestHeaders,
131
+ cancellationToken: downloadUpdateOptions.cancellationToken
132
+ };
133
+
134
+ if (this.listenerCount(_main().DOWNLOAD_PROGRESS) > 0) {
135
+ downloadOptions.onProgress = it => this.emit(_main().DOWNLOAD_PROGRESS, it);
136
+ }
137
+
138
+ await new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(fileInfo.info, this.httpExecutor, downloadOptions).download();
122
139
  } catch (e) {
123
140
  this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`); // during test (developer machine mac) we must throw error
124
141
 
@@ -156,6 +173,11 @@ class AppImageUpdater extends _BaseUpdater().BaseUpdater {
156
173
  }
157
174
 
158
175
  (0, _child_process().execFileSync)("mv", ["-f", options.installerPath, destination]);
176
+
177
+ if (destination !== appImageFile) {
178
+ this.emit('appimage-filename-updated', destination);
179
+ }
180
+
159
181
  const env = { ...process.env,
160
182
  APPIMAGE_SILENT_INSTALL: "true"
161
183
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/AppImageUpdater.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AACA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEM,MAAO,eAAP,SAA+B,0BAA/B,CAA0C;AAC9C,EAAA,WAAA,CAAY,OAAZ,EAAgD,GAAhD,EAAyD;AACvD,UAAM,OAAN,EAAe,GAAf;AACD;;AAEM,EAAA,eAAe,GAAA;AACpB,QAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,IAAwB,IAA5B,EAAkC;AAChC,UAAI,OAAO,CAAC,GAAR,CAAY,IAAZ,IAAoB,IAAxB,EAA8B;AAC5B,aAAK,OAAL,CAAa,IAAb,CAAkB,qEAAlB;AACD,OAFD,MAGK;AACH,aAAK,OAAL,CAAa,IAAb,CAAkB,0CAAlB;AACD;;AACD,aAAO,KAAP;AACD;;AACD,WAAO,MAAM,eAAN,EAAP;AACD;AAED;;;AACU,EAAA,gBAAgB,CAAC,qBAAD,EAA6C;AACrE,UAAM,QAAQ,GAAG,qBAAqB,CAAC,qBAAtB,CAA4C,QAA7D;AACA,UAAM,QAAQ,GAAG,0BAAS,QAAQ,CAAC,YAAT,CAAsB,qBAAqB,CAAC,qBAAtB,CAA4C,IAAlE,CAAT,EAAkF,UAAlF,CAAjB;AACA,WAAO,KAAK,eAAL,CAAqB;AAC1B,MAAA,aAAa,EAAE,UADW;AAE1B,MAAA,QAF0B;AAG1B,MAAA,qBAH0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gBAAgB,GAAG,IAAI,CAAC,QAAL,CAAc,YAAd,CAAzB,CAVyC,CAWzC;AACA;;AACA,QAAI,IAAI,CAAC,QAAL,CAAc,OAAO,CAAC,aAAtB,MAAyC,gBAAzC,IAA6D,CAAC,gBAAgB,IAAhB,CAAqB,gBAArB,CAAlE,EAA0G;AACxG;AACA,MAAA,WAAW,GAAG,YAAd;AACD,KAHD,MAIK;AACH,MAAA,WAAW,GAAG,IAAI,CAAC,IAAL,CAAU,IAAI,CAAC,OAAL,CAAa,YAAb,CAAV,EAAsC,IAAI,CAAC,QAAL,CAAc,OAAO,CAAC,aAAtB,CAAtC,CAAd;AACD;;AAED,uCAAa,IAAb,EAAmB,CAAC,IAAD,EAAO,OAAO,CAAC,aAAf,EAA8B,WAA9B,CAAnB;AAEA,UAAM,GAAG,GAAQ,EACf,GAAG,OAAO,CAAC,GADI;AAEf,MAAA,uBAAuB,EAAE;AAFV,KAAjB;;AAKA,QAAI,OAAO,CAAC,eAAZ,EAA6B;AAC3B,kCAAM,WAAN,EAAmB,EAAnB,EAAuB;AACrB,QAAA,QAAQ,EAAE,IADW;AAErB,QAAA,KAAK,EAAE,QAFc;AAGrB,QAAA;AAHqB,OAAvB,EAKG,KALH;AAMD,KAPD,MAQK;AACH,MAAA,GAAG,CAAC,2BAAJ,GAAkC,MAAlC;AACA,yCAAa,WAAb,EAA0B,EAA1B,EAA8B;AAAC,QAAA;AAAD,OAA9B;AACD;;AACD,WAAO,IAAP;AACD;;AApG6C,C","sourcesContent":["import { AllPublishOptions, newError } from \"builder-util-runtime\"\nimport { execFileSync, spawn } from \"child_process\"\nimport { chmod } from \"fs-extra\"\nimport { unlinkSync } from \"fs\"\nimport * as path from \"path\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { BaseUpdater, InstallOptions } from \"./BaseUpdater\"\nimport { FileWithEmbeddedBlockMapDifferentialDownloader } from \"./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader\"\nimport { findFile } from \"./providers/Provider\"\n\nexport class AppImageUpdater extends BaseUpdater {\n constructor(options?: AllPublishOptions | null, app?: any) {\n super(options, app)\n }\n\n public isUpdaterActive(): boolean {\n if (process.env.APPIMAGE == null) {\n if (process.env.SNAP == null) {\n this._logger.warn(\"APPIMAGE env is not defined, current application is not an AppImage\")\n }\n else {\n this._logger.info(\"SNAP env is defined, updater is disabled\")\n }\n return false\n }\n return super.isUpdaterActive()\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"AppImage\")!!\n return this.executeDownload({\n fileExtension: \"AppImage\",\n fileInfo,\n downloadUpdateOptions,\n task: async (updateFile, downloadOptions) => {\n const oldFile = process.env.APPIMAGE!!\n if (oldFile == null) {\n throw newError(\"APPIMAGE env is not defined\", \"ERR_UPDATER_OLD_FILE_NOT_FOUND\")\n }\n\n let isDownloadFull = false\n try {\n await new FileWithEmbeddedBlockMapDifferentialDownloader(fileInfo.info, this.httpExecutor, {\n newUrl: fileInfo.url,\n oldFile,\n logger: this._logger,\n newFile: updateFile,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n requestHeaders: downloadUpdateOptions.requestHeaders,\n })\n .download()\n }\n catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n // during test (developer machine mac) we must throw error\n isDownloadFull = process.platform === \"linux\"\n }\n\n if (isDownloadFull) {\n await this.httpExecutor.download(fileInfo.url, updateFile, downloadOptions)\n }\n\n await chmod(updateFile, 0o755)\n },\n })\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const appImageFile = process.env.APPIMAGE!!\n if (appImageFile == null) {\n throw newError(\"APPIMAGE env is not defined\", \"ERR_UPDATER_OLD_FILE_NOT_FOUND\")\n }\n\n // https://stackoverflow.com/a/1712051/1910191\n unlinkSync(appImageFile)\n\n let destination: string\n const existingBaseName = path.basename(appImageFile)\n // https://github.com/electron-userland/electron-builder/issues/2964\n // if no version in existing file name, it means that user wants to preserve current custom name\n if (path.basename(options.installerPath) === existingBaseName || !/\\d+\\.\\d+\\.\\d+/.test(existingBaseName)) {\n // no version in the file name, overwrite existing\n destination = appImageFile\n }\n else {\n destination = path.join(path.dirname(appImageFile), path.basename(options.installerPath))\n }\n\n execFileSync(\"mv\", [\"-f\", options.installerPath, destination])\n\n const env: any = {\n ...process.env,\n APPIMAGE_SILENT_INSTALL: \"true\",\n }\n\n if (options.isForceRunAfter) {\n spawn(destination, [], {\n detached: true,\n stdio: \"ignore\",\n env,\n })\n .unref()\n }\n else {\n env.APPIMAGE_EXIT_AFTER_INSTALL = \"true\"\n execFileSync(destination, [], {env})\n }\n return true\n }\n}"],"sourceRoot":""}
1
+ {"version":3,"sources":["../src/AppImageUpdater.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AACA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEM,MAAO,eAAP,SAA+B,0BAA/B,CAA0C;AAC9C,EAAA,WAAA,CAAY,OAAZ,EAAgD,GAAhD,EAAyD;AACvD,UAAM,OAAN,EAAe,GAAf;AACD;;AAEM,EAAA,eAAe,GAAA;AACpB,QAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,IAAwB,IAA5B,EAAkC;AAChC,UAAI,OAAO,CAAC,GAAR,CAAY,IAAZ,IAAoB,IAAxB,EAA8B;AAC5B,aAAK,OAAL,CAAa,IAAb,CAAk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EAAkC;AAChC,WAAK,IAAL,CAAU,2BAAV,EAAuC,WAAvC;AACD;;AAED,UAAM,GAAG,GAAQ,EACf,GAAG,OAAO,CAAC,GADI;AAEf,MAAA,uBAAuB,EAAE;AAFV,KAAjB;;AAKA,QAAI,OAAO,CAAC,eAAZ,EAA6B;AAC3B,kCAAM,WAAN,EAAmB,EAAnB,EAAuB;AACrB,QAAA,QAAQ,EAAE,IADW;AAErB,QAAA,KAAK,EAAE,QAFc;AAGrB,QAAA;AAHqB,OAAvB,EAKG,KALH;AAMD,KAPD,MAQK;AACH,MAAA,GAAG,CAAC,2BAAJ,GAAkC,MAAlC;AACA,yCAAa,WAAb,EAA0B,EAA1B,EAA8B;AAAC,QAAA;AAAD,OAA9B;AACD;;AACD,WAAO,IAAP;AACD;;AA9G6C,C","sourcesContent":["import { AllPublishOptions, newError } from \"builder-util-runtime\"\nimport { execFileSync, spawn } from \"child_process\"\nimport { chmod } from \"fs-extra\"\nimport { unlinkSync } from \"fs\"\nimport * as path from \"path\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { BaseUpdater, InstallOptions } from \"./BaseUpdater\"\nimport { DifferentialDownloaderOptions } from \"./differentialDownloader/DifferentialDownloader\"\nimport { FileWithEmbeddedBlockMapDifferentialDownloader } from \"./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader\"\nimport { DOWNLOAD_PROGRESS } from \"./main\"\nimport { findFile } from \"./providers/Provider\"\n\nexport class AppImageUpdater extends BaseUpdater {\n constructor(options?: AllPublishOptions | null, app?: any) {\n super(options, app)\n }\n\n public isUpdaterActive(): boolean {\n if (process.env.APPIMAGE == null) {\n if (process.env.SNAP == null) {\n this._logger.warn(\"APPIMAGE env is not defined, current application is not an AppImage\")\n }\n else {\n this._logger.info(\"SNAP env is defined, updater is disabled\")\n }\n return false\n }\n return super.isUpdaterActive()\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"AppImage\")!!\n return this.executeDownload({\n fileExtension: \"AppImage\",\n fileInfo,\n downloadUpdateOptions,\n task: async (updateFile, downloadOptions) => {\n const oldFile = process.env.APPIMAGE!!\n if (oldFile == null) {\n throw newError(\"APPIMAGE env is not defined\", \"ERR_UPDATER_OLD_FILE_NOT_FOUND\")\n }\n\n let isDownloadFull = false\n try {\n const downloadOptions: DifferentialDownloaderOptions = {\n newUrl: fileInfo.url,\n oldFile,\n logger: this._logger,\n newFile: updateFile,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n requestHeaders: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n await new FileWithEmbeddedBlockMapDifferentialDownloader(fileInfo.info, this.httpExecutor, downloadOptions)\n .download()\n }\n catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n // during test (developer machine mac) we must throw error\n isDownloadFull = process.platform === \"linux\"\n }\n\n if (isDownloadFull) {\n await this.httpExecutor.download(fileInfo.url, updateFile, downloadOptions)\n }\n\n await chmod(updateFile, 0o755)\n },\n })\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const appImageFile = process.env.APPIMAGE!!\n if (appImageFile == null) {\n throw newError(\"APPIMAGE env is not defined\", \"ERR_UPDATER_OLD_FILE_NOT_FOUND\")\n }\n\n // https://stackoverflow.com/a/1712051/1910191\n unlinkSync(appImageFile)\n\n let destination: string\n const existingBaseName = path.basename(appImageFile)\n // https://github.com/electron-userland/electron-builder/issues/2964\n // if no version in existing file name, it means that user wants to preserve current custom name\n if (path.basename(options.installerPath) === existingBaseName || !/\\d+\\.\\d+\\.\\d+/.test(existingBaseName)) {\n // no version in the file name, overwrite existing\n destination = appImageFile\n }\n else {\n destination = path.join(path.dirname(appImageFile), path.basename(options.installerPath))\n }\n\n execFileSync(\"mv\", [\"-f\", options.installerPath, destination])\n if (destination !== appImageFile) {\n this.emit('appimage-filename-updated', destination)\n }\n\n const env: any = {\n ...process.env,\n APPIMAGE_SILENT_INSTALL: \"true\",\n }\n\n if (options.isForceRunAfter) {\n spawn(destination, [], {\n detached: true,\n stdio: \"ignore\",\n env,\n })\n .unref()\n }\n else {\n env.APPIMAGE_EXIT_AFTER_INSTALL = \"true\"\n execFileSync(destination, [], {env})\n }\n return true\n }\n}\n"],"sourceRoot":""}
@@ -16,8 +16,6 @@ export declare abstract class AppUpdater extends EventEmitter {
16
16
  autoDownload: boolean;
17
17
  /**
18
18
  * Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).
19
- *
20
- * Applicable only on Windows and Linux.
21
19
  */
22
20
  autoInstallOnAppQuit: boolean;
23
21
  /**
package/out/AppUpdater.js CHANGED
@@ -161,8 +161,6 @@ class AppUpdater extends _events().EventEmitter {
161
161
  this.autoDownload = true;
162
162
  /**
163
163
  * Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).
164
- *
165
- * Applicable only on Windows and Linux.
166
164
  */
167
165
 
168
166
  this.autoInstallOnAppQuit = true;
@@ -599,7 +597,7 @@ class AppUpdater extends _events().EventEmitter {
599
597
  this._appUpdateConfigPath = this.app.appUpdateConfigPath;
600
598
  }
601
599
 
602
- return (0, _jsYaml().safeLoad)(await (0, _fsExtra().readFile)(this._appUpdateConfigPath, "utf-8"));
600
+ return (0, _jsYaml().load)(await (0, _fsExtra().readFile)(this._appUpdateConfigPath, "utf-8"));
603
601
  }
604
602
 
605
603
  computeRequestHeaders(provider) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/AppUpdater.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;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;AAEA,UAAI,CAAC,YAAY,uCAAjB,EAAoC;AAClC,QAAA,GAAG,CAAC,IAAJ,CAAS,WAAT;AACA,aAAK,IAAL,CAAU,kBAAV,EAA8B,UAA9B;AACD;;AACD,YAAM,CAAN;AACD;;AAED,IAAA,GAAG,CAAC,IAAJ,CAAS,eAAe,OAAO,2BAA2B,UAAU,EAApE;AACA,WAAO,MAAM,IAAI,CAAC,IAAD,CAAjB;AACD;;AArmBkD;;;;AA8mBrD,SAAS,uBAAT,CAAiC,OAAjC,EAAgD;AAC9C,QAAM,0BAA0B,GAAG,0BAA6B,OAA7B,CAAnC;AACA,SAAO,0BAA0B,IAAI,IAA9B,IAAsC,0BAA0B,CAAC,MAA3B,GAAoC,CAAjF;AACD;AAED;;;AACM,MAAO,UAAP,CAAiB;AACrB;AACA,EAAA,IAAI,CAAC,OAAD,EAAc,CAChB;AACD,GAJoB,CAMrB;;;AACA,EAAA,IAAI,CAAC,OAAD,EAAc,CAChB;AACD,GAToB,CAWrB;;;AACA,EAAA,KAAK,CAAC,OAAD,EAAc,CACjB;AACD;;AAdoB,C","sourcesContent":["import { AllPublishOptions, asArray, CancellationToken, newError, PublishConfiguration, UpdateInfo, UUID, DownloadOptions, CancellationError } from \"builder-util-runtime\"\nimport { randomBytes } from \"crypto\"\nimport { Notification } from \"electron\"\nimport { EventEmitter } from \"events\"\nimport { ensureDir, outputFile, readFile, rename, unlink } from \"fs-extra\"\nimport { OutgoingHttpHeaders } from \"http\"\nimport { safeLoad } from \"js-yaml\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport { eq as isVersionsEqual, gt as isVersionGreaterThan, lt as isVersionLessThan, parse as parseVersion, prerelease as getVersionPreleaseComponents, SemVer } from \"semver\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { createTempUpdateFile, DownloadedUpdateHelper } from \"./DownloadedUpdateHelper\"\nimport { ElectronAppAdapter } from \"./ElectronAppAdapter\"\nimport { ElectronHttpExecutor, getNetSession } from \"./electronHttpExecutor\"\nimport { GenericProvider } from \"./providers/GenericProvider\"\nimport { DOWNLOAD_PROGRESS, Logger, Provider, ResolvedUpdateFileInfo, UPDATE_DOWNLOADED, UpdateCheckResult, UpdateDownloadedEvent, UpdaterSignal } from \"./main\"\nimport { createClient, isUrlProbablySupportMultiRangeRequests } from \"./providerFactory\"\nimport { ProviderPlatform } from \"./providers/Provider\"\nimport Session = Electron.Session\n\nexport abstract class AppUpdater extends EventEmitter {\n /**\n * Whether to automatically download an update when it is found.\n */\n autoDownload: boolean = true\n\n /**\n * Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).\n *\n * Applicable only on Windows and Linux.\n */\n autoInstallOnAppQuit: boolean = true\n\n /**\n * *GitHub provider only.* Whether to allow update to pre-release versions. Defaults to `true` if application version contains prerelease components (e.g. `0.12.1-alpha.1`, here `alpha` is a prerelease component), otherwise `false`.\n *\n * If `true`, downgrade will be allowed (`allowDowngrade` will be set to `true`).\n */\n allowPrerelease: boolean = false\n\n /**\n * *GitHub provider only.* Get all release notes (from current version to latest), not just the latest.\n * @default false\n */\n fullChangelog: boolean = false\n\n /**\n * Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).\n *\n * Taken in account only if channel differs (pre-release version component in terms of semantic versioning).\n *\n * @default false\n */\n allowDowngrade: boolean = false\n\n /**\n * The current application version.\n */\n readonly currentVersion: SemVer\n\n private _channel: string | null = null\n\n protected downloadedUpdateHelper: DownloadedUpdateHelper | null = null\n\n /**\n * Get the update channel. Not applicable for GitHub. Doesn't return `channel` from the update configuration, only if was previously set.\n */\n get channel(): string | null {\n return this._channel\n }\n\n /**\n * Set the update channel. Not applicable for GitHub. Overrides `channel` in the update configuration.\n *\n * `allowDowngrade` will be automatically set to `true`. If this behavior is not suitable for you, simple set `allowDowngrade` explicitly after.\n */\n set channel(value: string | null) {\n if (this._channel != null) {\n // noinspection SuspiciousTypeOfGuard\n if (typeof value !== \"string\") {\n throw newError(`Channel must be a string, but got: ${value}`, \"ERR_UPDATER_INVALID_CHANNEL\")\n }\n else if (value.length === 0) {\n throw newError(`Channel must be not an empty string`, \"ERR_UPDATER_INVALID_CHANNEL\")\n }\n }\n\n this._channel = value\n this.allowDowngrade = true\n }\n\n /**\n * The request headers.\n */\n requestHeaders: OutgoingHttpHeaders | null = null\n\n protected _logger: Logger = console\n\n // noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols\n get netSession(): Session {\n return getNetSession()\n }\n\n /**\n * The logger. You can pass [electron-log](https://github.com/megahertz/electron-log), [winston](https://github.com/winstonjs/winston) or another logger with the following interface: `{ info(), warn(), error() }`.\n * Set it to `null` if you would like to disable a logging feature.\n */\n get logger(): Logger | null {\n return this._logger\n }\n\n set logger(value: Logger | null) {\n this._logger = value == null ? new NoOpLogger() : value\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * For type safety you can use signals, e.g. `autoUpdater.signals.updateDownloaded(() => {})` instead of `autoUpdater.on('update-available', () => {})`\n */\n readonly signals = new UpdaterSignal(this)\n\n private _appUpdateConfigPath: string | null = null\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * test only\n * @private\n */\n set updateConfigPath(value: string | null) {\n this.clientPromise = null\n this._appUpdateConfigPath = value\n this.configOnDisk = new Lazy<any>(() => this.loadUpdateConfig())\n }\n\n private clientPromise: Promise<Provider<any>> | null = null\n\n protected readonly stagingUserIdPromise = new Lazy<string>(() => this.getOrCreateStagingUserId())\n\n // public, allow to read old config for anyone\n /** @internal */\n configOnDisk = new Lazy<any>(() => this.loadUpdateConfig())\n\n private checkForUpdatesPromise: Promise<UpdateCheckResult> | null = null\n\n protected readonly app: AppAdapter\n\n protected updateInfoAndProvider: UpdateInfoAndProvider | null = null\n\n /** @internal */\n readonly httpExecutor: ElectronHttpExecutor\n\n protected constructor(options: AllPublishOptions | null | undefined, app?: AppAdapter) {\n super()\n\n this.on(\"error\", (error: Error) => {\n this._logger.error(`Error: ${error.stack || error.message}`)\n })\n\n if (app == null) {\n this.app = new ElectronAppAdapter()\n this.httpExecutor = new ElectronHttpExecutor((authInfo, callback) => this.emit(\"login\", authInfo, callback))\n }\n else {\n this.app = app\n this.httpExecutor = null as any\n }\n\n const currentVersionString = this.app.version\n const currentVersion = parseVersion(currentVersionString)\n if (currentVersion == null) {\n throw newError(`App version is not a valid semver version: \"${currentVersionString}\"`, \"ERR_UPDATER_INVALID_VERSION\")\n }\n this.currentVersion = currentVersion\n this.allowPrerelease = hasPrereleaseComponents(currentVersion)\n\n if (options != null) {\n this.setFeedURL(options)\n\n if (typeof options !== \"string\" && options.requestHeaders) {\n this.requestHeaders = options.requestHeaders\n }\n }\n }\n\n //noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols\n getFeedURL(): string | null | undefined {\n return \"Deprecated. Do not use it.\"\n }\n\n /**\n * Configure update provider. If value is `string`, [GenericServerOptions](/configuration/publish#genericserveroptions) will be set with value as `url`.\n * @param options If you want to override configuration in the `app-update.yml`.\n */\n setFeedURL(options: PublishConfiguration | AllPublishOptions | string) {\n const runtimeOptions = this.createProviderRuntimeOptions()\n // https://github.com/electron-userland/electron-builder/issues/1105\n let provider: Provider<any>\n if (typeof options === \"string\") {\n provider = new GenericProvider({provider: \"generic\", url: options}, this, {\n ...runtimeOptions,\n isUseMultipleRangeRequest: isUrlProbablySupportMultiRangeRequests(options),\n })\n }\n else {\n provider = createClient(options, this, runtimeOptions)\n }\n this.clientPromise = Promise.resolve(provider)\n }\n\n /**\n * Asks the server whether there is an update.\n */\n checkForUpdates(): Promise<UpdateCheckResult> {\n let checkForUpdatesPromise = this.checkForUpdatesPromise\n if (checkForUpdatesPromise != null) {\n this._logger.info(\"Checking for update (already in progress)\")\n return checkForUpdatesPromise\n }\n\n const nullizePromise = () => this.checkForUpdatesPromise = null\n\n this._logger.info(\"Checking for update\")\n checkForUpdatesPromise = this.doCheckForUpdates()\n .then(it => {\n nullizePromise()\n return it\n })\n .catch(e => {\n nullizePromise()\n this.emit(\"error\", e, `Cannot check for updates: ${(e.stack || e).toString()}`)\n throw e\n })\n\n this.checkForUpdatesPromise = checkForUpdatesPromise\n return checkForUpdatesPromise\n }\n\n public isUpdaterActive(): boolean {\n if (!this.app.isPackaged) {\n this._logger.info(\"Skip checkForUpdatesAndNotify because application is not packed\")\n return false\n }\n return true\n }\n\n // noinspection JSUnusedGlobalSymbols\n checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null> {\n if (!this.isUpdaterActive()) {\n return Promise.resolve(null)\n }\n\n return this.checkForUpdates()\n .then(it => {\n const downloadPromise = it.downloadPromise\n if (downloadPromise == null) {\n const debug = this._logger.debug\n if (debug != null) {\n debug(\"checkForUpdatesAndNotify called, downloadPromise is null\")\n }\n return it\n }\n\n downloadPromise\n .then(() => {\n const notificationContent = this.formatDownloadNotification(it.updateInfo.version, this.app.name, downloadNotification);\n new Notification(notificationContent).show()\n })\n\n return it\n })\n }\n\n private formatDownloadNotification(version: string, appName: string, downloadNotification?: DownloadNotification): DownloadNotification {\n if (downloadNotification == null) {\n downloadNotification = {\n title: \"A new update is ready to install\",\n body: `{appName} version {version} has been downloaded and will be automatically installed on exit`\n }\n }\n downloadNotification = {\n title: downloadNotification.title.replace(\"{appName}\", appName).replace(\"{version}\", version),\n body: downloadNotification.body.replace(\"{appName}\", appName).replace(\"{version}\", version)\n }\n return downloadNotification;\n }\n\n private async isStagingMatch(updateInfo: UpdateInfo): Promise<boolean> {\n const rawStagingPercentage = updateInfo.stagingPercentage\n let stagingPercentage = rawStagingPercentage\n if (stagingPercentage == null) {\n return true\n }\n\n stagingPercentage = parseInt(stagingPercentage as any, 10)\n if (isNaN(stagingPercentage)) {\n this._logger.warn(`Staging percentage is NaN: ${rawStagingPercentage}`)\n return true\n }\n\n // convert from user 0-100 to internal 0-1\n stagingPercentage = stagingPercentage / 100\n\n const stagingUserId = await this.stagingUserIdPromise.value\n const val = UUID.parse(stagingUserId).readUInt32BE(12)\n const percentage = (val / 0xFFFFFFFF)\n this._logger.info(`Staging percentage: ${stagingPercentage}, percentage: ${percentage}, user id: ${stagingUserId}`)\n return percentage < stagingPercentage\n }\n\n private computeFinalHeaders(headers: OutgoingHttpHeaders) {\n if (this.requestHeaders != null) {\n Object.assign(headers, this.requestHeaders)\n }\n return headers\n }\n\n private async isUpdateAvailable(updateInfo: UpdateInfo): Promise<boolean> {\n const latestVersion = parseVersion(updateInfo.version)\n if (latestVersion == null) {\n throw newError(`This file could not be downloaded, or the latest version (from update server) does not have a valid semver version: \"${updateInfo.version}\"`, \"ERR_UPDATER_INVALID_VERSION\")\n }\n\n const currentVersion = this.currentVersion\n if (isVersionsEqual(latestVersion, currentVersion)) {\n return false\n }\n\n const isStagingMatch = await this.isStagingMatch(updateInfo)\n if (!isStagingMatch) {\n return false\n }\n\n // https://github.com/electron-userland/electron-builder/pull/3111#issuecomment-405033227\n // https://github.com/electron-userland/electron-builder/pull/3111#issuecomment-405030797\n const isLatestVersionNewer = isVersionGreaterThan(latestVersion, currentVersion)\n const isLatestVersionOlder = isVersionLessThan(latestVersion, currentVersion)\n\n if (isLatestVersionNewer) {\n return true\n }\n return this.allowDowngrade && isLatestVersionOlder;\n }\n\n protected async getUpdateInfoAndProvider(): Promise<UpdateInfoAndProvider> {\n await this.app.whenReady()\n\n if (this.clientPromise == null) {\n this.clientPromise = this.configOnDisk.value.then(it => createClient(it, this, this.createProviderRuntimeOptions()))\n }\n\n const client = await this.clientPromise\n const stagingUserId = await this.stagingUserIdPromise.value\n client.setRequestHeaders(this.computeFinalHeaders({\"x-user-staging-id\": stagingUserId}))\n return {\n info: await client.getLatestVersion(),\n provider: client,\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n private createProviderRuntimeOptions() {\n return {\n isUseMultipleRangeRequest: true,\n platform: this._testOnlyOptions == null ? process.platform as ProviderPlatform : this._testOnlyOptions.platform,\n executor: this.httpExecutor,\n }\n }\n\n private async doCheckForUpdates(): Promise<UpdateCheckResult> {\n this.emit(\"checking-for-update\")\n\n const result = await this.getUpdateInfoAndProvider()\n const updateInfo = result.info\n if (!await this.isUpdateAvailable(updateInfo)) {\n this._logger.info(`Update for version ${this.currentVersion} is not available (latest version: ${updateInfo.version}, downgrade is ${this.allowDowngrade ? \"allowed\" : \"disallowed\"}).`)\n this.emit(\"update-not-available\", updateInfo)\n return {\n versionInfo: updateInfo,\n updateInfo,\n }\n }\n\n this.updateInfoAndProvider = result\n this.onUpdateAvailable(updateInfo)\n\n const cancellationToken = new CancellationToken()\n //noinspection ES6MissingAwait\n return {\n versionInfo: updateInfo,\n updateInfo,\n cancellationToken,\n downloadPromise: this.autoDownload ? this.downloadUpdate(cancellationToken) : null\n }\n }\n\n protected onUpdateAvailable(updateInfo: UpdateInfo): void {\n this._logger.info(`Found version ${updateInfo.version} (url: ${asArray(updateInfo.files).map(it => it.url).join(\", \")})`)\n this.emit(\"update-available\", updateInfo)\n }\n\n /**\n * Start downloading update manually. You can use this method if `autoDownload` option is set to `false`.\n * @returns {Promise<string>} Path to downloaded file.\n */\n downloadUpdate(cancellationToken: CancellationToken = new CancellationToken()): Promise<any> {\n const updateInfoAndProvider = this.updateInfoAndProvider\n if (updateInfoAndProvider == null) {\n const error = new Error(\"Please check update first\")\n this.dispatchError(error)\n return Promise.reject(error)\n }\n\n this._logger.info(`Downloading update from ${asArray(updateInfoAndProvider.info.files).map(it => it.url).join(\", \")}`)\n const errorHandler = (e: Error): Error => {\n // https://github.com/electron-userland/electron-builder/issues/1150#issuecomment-436891159\n if (!(e instanceof CancellationError)) {\n try {\n this.dispatchError(e)\n }\n catch (nestedError) {\n this._logger.warn(`Cannot dispatch error event: ${nestedError.stack || nestedError}`)\n }\n }\n\n return e\n }\n\n try {\n return this.doDownloadUpdate({\n updateInfoAndProvider,\n requestHeaders: this.computeRequestHeaders(updateInfoAndProvider.provider),\n cancellationToken,\n })\n .catch(e => {\n throw errorHandler(e)\n })\n }\n catch (e) {\n return Promise.reject(errorHandler(e))\n }\n }\n\n protected dispatchError(e: Error): void {\n this.emit(\"error\", e, (e.stack || e).toString())\n }\n\n protected dispatchUpdateDownloaded(event: UpdateDownloadedEvent): void {\n this.emit(UPDATE_DOWNLOADED, event)\n }\n\n protected abstract doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>>\n\n /**\n * Restarts the app and installs the update after it has been downloaded.\n * It should only be called after `update-downloaded` has been emitted.\n *\n * **Note:** `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that.\n * This is different from the normal quit event sequence.\n *\n * @param isSilent *windows-only* Runs the installer in silent mode. Defaults to `false`.\n * @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.\n */\n abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void\n\n private async loadUpdateConfig(): Promise<any> {\n if (this._appUpdateConfigPath == null) {\n this._appUpdateConfigPath = this.app.appUpdateConfigPath\n }\n return safeLoad(await readFile(this._appUpdateConfigPath, \"utf-8\"))\n }\n\n private computeRequestHeaders(provider: Provider<any>): OutgoingHttpHeaders {\n const fileExtraDownloadHeaders = provider.fileExtraDownloadHeaders\n if (fileExtraDownloadHeaders != null) {\n const requestHeaders = this.requestHeaders\n return requestHeaders == null ? fileExtraDownloadHeaders : {\n ...fileExtraDownloadHeaders,\n ...requestHeaders,\n }\n }\n return this.computeFinalHeaders({accept: \"*/*\"})\n }\n\n private async getOrCreateStagingUserId(): Promise<string> {\n const file = path.join(this.app.userDataPath, \".updaterId\")\n try {\n const id = await readFile(file, \"utf-8\")\n if (UUID.check(id)) {\n return id\n }\n else {\n this._logger.warn(`Staging user id file exists, but content was invalid: ${id}`)\n }\n }\n catch (e) {\n if (e.code !== \"ENOENT\") {\n this._logger.warn(`Couldn't read staging user ID, creating a blank one: ${e}`)\n }\n }\n\n const id = UUID.v5(randomBytes(4096), UUID.OID)\n this._logger.info(`Generated new staging user ID: ${id}`)\n try {\n await outputFile(file, id)\n }\n catch (e) {\n this._logger.warn(`Couldn't write out staging user ID: ${e}`)\n }\n return id\n }\n\n /** @internal */\n get isAddNoCacheQuery(): boolean {\n const headers = this.requestHeaders\n // https://github.com/electron-userland/electron-builder/issues/3021\n if (headers == null) {\n return true\n }\n\n for (const headerName of Object.keys(headers)) {\n const s = headerName.toLowerCase()\n if (s === \"authorization\" || s === \"private-token\") {\n return false\n }\n }\n return true\n }\n\n /**\n * @private\n * @internal\n */\n _testOnlyOptions: TestOnlyUpdaterOptions | null = null\n\n private async getOrCreateDownloadHelper(): Promise<DownloadedUpdateHelper> {\n let result = this.downloadedUpdateHelper\n if (result == null) {\n const dirName = (await this.configOnDisk.value).updaterCacheDirName\n const logger = this._logger\n if (dirName == null) {\n logger.error(\"updaterCacheDirName is not specified in app-update.yml Was app build using at least electron-builder 20.34.0?\")\n }\n const cacheDir = path.join(this.app.baseCachePath, dirName || this.app.name)\n if (logger.debug != null) {\n logger.debug(`updater cache dir: ${cacheDir}`)\n }\n\n result = new DownloadedUpdateHelper(cacheDir)\n this.downloadedUpdateHelper = result\n }\n return result\n }\n\n protected async executeDownload(taskOptions: DownloadExecutorTask): Promise<Array<string>> {\n const fileInfo = taskOptions.fileInfo\n const downloadOptions: DownloadOptions = {\n headers: taskOptions.downloadUpdateOptions.requestHeaders,\n cancellationToken: taskOptions.downloadUpdateOptions.cancellationToken,\n sha2: (fileInfo.info as any).sha2,\n sha512: fileInfo.info.sha512,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n const updateInfo = taskOptions.downloadUpdateOptions.updateInfoAndProvider.info\n const version = updateInfo.version\n const packageInfo = fileInfo.packageInfo\n\n function getCacheUpdateFileName(): string {\n // NodeJS URL doesn't decode automatically\n const urlPath = decodeURIComponent(taskOptions.fileInfo.url.pathname)\n if (urlPath.endsWith(`.${taskOptions.fileExtension}`)) {\n return path.posix.basename(urlPath)\n }\n else {\n // url like /latest, generate name\n return `update.${taskOptions.fileExtension}`\n }\n }\n\n const downloadedUpdateHelper = await this.getOrCreateDownloadHelper()\n const cacheDir = downloadedUpdateHelper.cacheDirForPendingUpdate\n await ensureDir(cacheDir)\n const updateFileName = getCacheUpdateFileName()\n let updateFile = path.join(cacheDir, updateFileName)\n const packageFile = packageInfo == null ? null : path.join(cacheDir, `package-${version}${path.extname(packageInfo.path) || \".7z\"}`)\n\n const done = async (isSaveCache: boolean) => {\n await downloadedUpdateHelper.setDownloadedFile(updateFile, packageFile, updateInfo, fileInfo, updateFileName, isSaveCache)\n await taskOptions.done!!({\n ...updateInfo,\n downloadedFile: updateFile,\n })\n return packageFile == null ? [updateFile] : [updateFile, packageFile]\n }\n\n const log = this._logger\n const cachedUpdateFile = await downloadedUpdateHelper.validateDownloadedPath(updateFile, updateInfo, fileInfo, log)\n if (cachedUpdateFile != null) {\n updateFile = cachedUpdateFile\n return await done(false)\n }\n\n const removeFileIfAny = async () => {\n await downloadedUpdateHelper.clear()\n .catch(() => {\n // ignore\n })\n return await unlink(updateFile)\n .catch(() => {\n // ignore\n })\n }\n\n const tempUpdateFile = await createTempUpdateFile(`temp-${updateFileName}`, cacheDir, log)\n try {\n await taskOptions.task(tempUpdateFile, downloadOptions, packageFile, removeFileIfAny)\n await rename(tempUpdateFile, updateFile)\n }\n catch (e) {\n await removeFileIfAny()\n\n if (e instanceof CancellationError) {\n log.info(\"cancelled\")\n this.emit(\"update-cancelled\", updateInfo)\n }\n throw e\n }\n\n log.info(`New version ${version} has been downloaded to ${updateFile}`)\n return await done(true)\n }\n}\n\nexport interface DownloadUpdateOptions {\n readonly updateInfoAndProvider: UpdateInfoAndProvider\n readonly requestHeaders: OutgoingHttpHeaders\n readonly cancellationToken: CancellationToken\n}\n\nfunction hasPrereleaseComponents(version: SemVer) {\n const versionPrereleaseComponent = getVersionPreleaseComponents(version)\n return versionPrereleaseComponent != null && versionPrereleaseComponent.length > 0\n}\n\n/** @private */\nexport class NoOpLogger implements Logger {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n info(message?: any) {\n // ignore\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n warn(message?: any) {\n // ignore\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n error(message?: any) {\n // ignore\n }\n}\n\nexport interface UpdateInfoAndProvider {\n info: UpdateInfo\n provider: Provider<any>\n}\n\nexport interface DownloadExecutorTask {\n readonly fileExtension: string\n readonly fileInfo: ResolvedUpdateFileInfo\n readonly downloadUpdateOptions: DownloadUpdateOptions\n readonly task: (destinationFile: string, downloadOptions: DownloadOptions, packageFile: string | null, removeTempDirIfAny: () => Promise<any>) => Promise<any>\n\n readonly done?: (event: UpdateDownloadedEvent) => Promise<any>\n}\n\nexport interface DownloadNotification {\n body: string\n title: string\n}\n\n/** @private */\nexport interface TestOnlyUpdaterOptions {\n platform: ProviderPlatform\n\n isUseDifferentialDownload?: boolean\n}\n"],"sourceRoot":""}
1
+ {"version":3,"sources":["../src/AppUpdater.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AA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AI,CAAC,OAAD,EAAc,CAChB;AACD,GAJoB,CAMrB;;;AACA,EAAA,IAAI,CAAC,OAAD,EAAc,CAChB;AACD,GAToB,CAWrB;;;AACA,EAAA,KAAK,CAAC,OAAD,EAAc,CACjB;AACD;;AAdoB,C","sourcesContent":["import { AllPublishOptions, asArray, CancellationToken, newError, PublishConfiguration, UpdateInfo, UUID, DownloadOptions, CancellationError } from \"builder-util-runtime\"\nimport { randomBytes } from \"crypto\"\nimport { Notification } from \"electron\"\nimport { EventEmitter } from \"events\"\nimport { ensureDir, outputFile, readFile, rename, unlink } from \"fs-extra\"\nimport { OutgoingHttpHeaders } from \"http\"\nimport { load } from \"js-yaml\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport { eq as isVersionsEqual, gt as isVersionGreaterThan, lt as isVersionLessThan, parse as parseVersion, prerelease as getVersionPreleaseComponents, SemVer } from \"semver\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { createTempUpdateFile, DownloadedUpdateHelper } from \"./DownloadedUpdateHelper\"\nimport { ElectronAppAdapter } from \"./ElectronAppAdapter\"\nimport { ElectronHttpExecutor, getNetSession } from \"./electronHttpExecutor\"\nimport { GenericProvider } from \"./providers/GenericProvider\"\nimport { DOWNLOAD_PROGRESS, Logger, Provider, ResolvedUpdateFileInfo, UPDATE_DOWNLOADED, UpdateCheckResult, UpdateDownloadedEvent, UpdaterSignal } from \"./main\"\nimport { createClient, isUrlProbablySupportMultiRangeRequests } from \"./providerFactory\"\nimport { ProviderPlatform } from \"./providers/Provider\"\nimport Session = Electron.Session\n\nexport abstract class AppUpdater extends EventEmitter {\n /**\n * Whether to automatically download an update when it is found.\n */\n autoDownload: boolean = true\n\n /**\n * Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).\n */\n autoInstallOnAppQuit: boolean = true\n\n /**\n * *GitHub provider only.* Whether to allow update to pre-release versions. Defaults to `true` if application version contains prerelease components (e.g. `0.12.1-alpha.1`, here `alpha` is a prerelease component), otherwise `false`.\n *\n * If `true`, downgrade will be allowed (`allowDowngrade` will be set to `true`).\n */\n allowPrerelease: boolean = false\n\n /**\n * *GitHub provider only.* Get all release notes (from current version to latest), not just the latest.\n * @default false\n */\n fullChangelog: boolean = false\n\n /**\n * Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).\n *\n * Taken in account only if channel differs (pre-release version component in terms of semantic versioning).\n *\n * @default false\n */\n allowDowngrade: boolean = false\n\n /**\n * The current application version.\n */\n readonly currentVersion: SemVer\n\n private _channel: string | null = null\n\n protected downloadedUpdateHelper: DownloadedUpdateHelper | null = null\n\n /**\n * Get the update channel. Not applicable for GitHub. Doesn't return `channel` from the update configuration, only if was previously set.\n */\n get channel(): string | null {\n return this._channel\n }\n\n /**\n * Set the update channel. Not applicable for GitHub. Overrides `channel` in the update configuration.\n *\n * `allowDowngrade` will be automatically set to `true`. If this behavior is not suitable for you, simple set `allowDowngrade` explicitly after.\n */\n set channel(value: string | null) {\n if (this._channel != null) {\n // noinspection SuspiciousTypeOfGuard\n if (typeof value !== \"string\") {\n throw newError(`Channel must be a string, but got: ${value}`, \"ERR_UPDATER_INVALID_CHANNEL\")\n }\n else if (value.length === 0) {\n throw newError(`Channel must be not an empty string`, \"ERR_UPDATER_INVALID_CHANNEL\")\n }\n }\n\n this._channel = value\n this.allowDowngrade = true\n }\n\n /**\n * The request headers.\n */\n requestHeaders: OutgoingHttpHeaders | null = null\n\n protected _logger: Logger = console\n\n // noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols\n get netSession(): Session {\n return getNetSession()\n }\n\n /**\n * The logger. You can pass [electron-log](https://github.com/megahertz/electron-log), [winston](https://github.com/winstonjs/winston) or another logger with the following interface: `{ info(), warn(), error() }`.\n * Set it to `null` if you would like to disable a logging feature.\n */\n get logger(): Logger | null {\n return this._logger\n }\n\n set logger(value: Logger | null) {\n this._logger = value == null ? new NoOpLogger() : value\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * For type safety you can use signals, e.g. `autoUpdater.signals.updateDownloaded(() => {})` instead of `autoUpdater.on('update-available', () => {})`\n */\n readonly signals = new UpdaterSignal(this)\n\n private _appUpdateConfigPath: string | null = null\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * test only\n * @private\n */\n set updateConfigPath(value: string | null) {\n this.clientPromise = null\n this._appUpdateConfigPath = value\n this.configOnDisk = new Lazy<any>(() => this.loadUpdateConfig())\n }\n\n private clientPromise: Promise<Provider<any>> | null = null\n\n protected readonly stagingUserIdPromise = new Lazy<string>(() => this.getOrCreateStagingUserId())\n\n // public, allow to read old config for anyone\n /** @internal */\n configOnDisk = new Lazy<any>(() => this.loadUpdateConfig())\n\n private checkForUpdatesPromise: Promise<UpdateCheckResult> | null = null\n\n protected readonly app: AppAdapter\n\n protected updateInfoAndProvider: UpdateInfoAndProvider | null = null\n\n /** @internal */\n readonly httpExecutor: ElectronHttpExecutor\n\n protected constructor(options: AllPublishOptions | null | undefined, app?: AppAdapter) {\n super()\n\n this.on(\"error\", (error: Error) => {\n this._logger.error(`Error: ${error.stack || error.message}`)\n })\n\n if (app == null) {\n this.app = new ElectronAppAdapter()\n this.httpExecutor = new ElectronHttpExecutor((authInfo, callback) => this.emit(\"login\", authInfo, callback))\n }\n else {\n this.app = app\n this.httpExecutor = null as any\n }\n\n const currentVersionString = this.app.version\n const currentVersion = parseVersion(currentVersionString)\n if (currentVersion == null) {\n throw newError(`App version is not a valid semver version: \"${currentVersionString}\"`, \"ERR_UPDATER_INVALID_VERSION\")\n }\n this.currentVersion = currentVersion\n this.allowPrerelease = hasPrereleaseComponents(currentVersion)\n\n if (options != null) {\n this.setFeedURL(options)\n\n if (typeof options !== \"string\" && options.requestHeaders) {\n this.requestHeaders = options.requestHeaders\n }\n }\n }\n\n //noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols\n getFeedURL(): string | null | undefined {\n return \"Deprecated. Do not use it.\"\n }\n\n /**\n * Configure update provider. If value is `string`, [GenericServerOptions](/configuration/publish#genericserveroptions) will be set with value as `url`.\n * @param options If you want to override configuration in the `app-update.yml`.\n */\n setFeedURL(options: PublishConfiguration | AllPublishOptions | string) {\n const runtimeOptions = this.createProviderRuntimeOptions()\n // https://github.com/electron-userland/electron-builder/issues/1105\n let provider: Provider<any>\n if (typeof options === \"string\") {\n provider = new GenericProvider({provider: \"generic\", url: options}, this, {\n ...runtimeOptions,\n isUseMultipleRangeRequest: isUrlProbablySupportMultiRangeRequests(options),\n })\n }\n else {\n provider = createClient(options, this, runtimeOptions)\n }\n this.clientPromise = Promise.resolve(provider)\n }\n\n /**\n * Asks the server whether there is an update.\n */\n checkForUpdates(): Promise<UpdateCheckResult> {\n let checkForUpdatesPromise = this.checkForUpdatesPromise\n if (checkForUpdatesPromise != null) {\n this._logger.info(\"Checking for update (already in progress)\")\n return checkForUpdatesPromise\n }\n\n const nullizePromise = () => this.checkForUpdatesPromise = null\n\n this._logger.info(\"Checking for update\")\n checkForUpdatesPromise = this.doCheckForUpdates()\n .then(it => {\n nullizePromise()\n return it\n })\n .catch(e => {\n nullizePromise()\n this.emit(\"error\", e, `Cannot check for updates: ${(e.stack || e).toString()}`)\n throw e\n })\n\n this.checkForUpdatesPromise = checkForUpdatesPromise\n return checkForUpdatesPromise\n }\n\n public isUpdaterActive(): boolean {\n if (!this.app.isPackaged) {\n this._logger.info(\"Skip checkForUpdatesAndNotify because application is not packed\")\n return false\n }\n return true\n }\n\n // noinspection JSUnusedGlobalSymbols\n checkForUpdatesAndNotify(downloadNotification?: DownloadNotification): Promise<UpdateCheckResult | null> {\n if (!this.isUpdaterActive()) {\n return Promise.resolve(null)\n }\n\n return this.checkForUpdates()\n .then(it => {\n const downloadPromise = it.downloadPromise\n if (downloadPromise == null) {\n const debug = this._logger.debug\n if (debug != null) {\n debug(\"checkForUpdatesAndNotify called, downloadPromise is null\")\n }\n return it\n }\n\n downloadPromise\n .then(() => {\n const notificationContent = this.formatDownloadNotification(it.updateInfo.version, this.app.name, downloadNotification);\n new Notification(notificationContent).show()\n })\n\n return it\n })\n }\n\n private formatDownloadNotification(version: string, appName: string, downloadNotification?: DownloadNotification): DownloadNotification {\n if (downloadNotification == null) {\n downloadNotification = {\n title: \"A new update is ready to install\",\n body: `{appName} version {version} has been downloaded and will be automatically installed on exit`\n }\n }\n downloadNotification = {\n title: downloadNotification.title.replace(\"{appName}\", appName).replace(\"{version}\", version),\n body: downloadNotification.body.replace(\"{appName}\", appName).replace(\"{version}\", version)\n }\n return downloadNotification;\n }\n\n private async isStagingMatch(updateInfo: UpdateInfo): Promise<boolean> {\n const rawStagingPercentage = updateInfo.stagingPercentage\n let stagingPercentage = rawStagingPercentage\n if (stagingPercentage == null) {\n return true\n }\n\n stagingPercentage = parseInt(stagingPercentage as any, 10)\n if (isNaN(stagingPercentage)) {\n this._logger.warn(`Staging percentage is NaN: ${rawStagingPercentage}`)\n return true\n }\n\n // convert from user 0-100 to internal 0-1\n stagingPercentage = stagingPercentage / 100\n\n const stagingUserId = await this.stagingUserIdPromise.value\n const val = UUID.parse(stagingUserId).readUInt32BE(12)\n const percentage = (val / 0xFFFFFFFF)\n this._logger.info(`Staging percentage: ${stagingPercentage}, percentage: ${percentage}, user id: ${stagingUserId}`)\n return percentage < stagingPercentage\n }\n\n private computeFinalHeaders(headers: OutgoingHttpHeaders) {\n if (this.requestHeaders != null) {\n Object.assign(headers, this.requestHeaders)\n }\n return headers\n }\n\n private async isUpdateAvailable(updateInfo: UpdateInfo): Promise<boolean> {\n const latestVersion = parseVersion(updateInfo.version)\n if (latestVersion == null) {\n throw newError(`This file could not be downloaded, or the latest version (from update server) does not have a valid semver version: \"${updateInfo.version}\"`, \"ERR_UPDATER_INVALID_VERSION\")\n }\n\n const currentVersion = this.currentVersion\n if (isVersionsEqual(latestVersion, currentVersion)) {\n return false\n }\n\n const isStagingMatch = await this.isStagingMatch(updateInfo)\n if (!isStagingMatch) {\n return false\n }\n\n // https://github.com/electron-userland/electron-builder/pull/3111#issuecomment-405033227\n // https://github.com/electron-userland/electron-builder/pull/3111#issuecomment-405030797\n const isLatestVersionNewer = isVersionGreaterThan(latestVersion, currentVersion)\n const isLatestVersionOlder = isVersionLessThan(latestVersion, currentVersion)\n\n if (isLatestVersionNewer) {\n return true\n }\n return this.allowDowngrade && isLatestVersionOlder;\n }\n\n protected async getUpdateInfoAndProvider(): Promise<UpdateInfoAndProvider> {\n await this.app.whenReady()\n\n if (this.clientPromise == null) {\n this.clientPromise = this.configOnDisk.value.then(it => createClient(it, this, this.createProviderRuntimeOptions()))\n }\n\n const client = await this.clientPromise\n const stagingUserId = await this.stagingUserIdPromise.value\n client.setRequestHeaders(this.computeFinalHeaders({\"x-user-staging-id\": stagingUserId}))\n return {\n info: await client.getLatestVersion(),\n provider: client,\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n private createProviderRuntimeOptions() {\n return {\n isUseMultipleRangeRequest: true,\n platform: this._testOnlyOptions == null ? process.platform as ProviderPlatform : this._testOnlyOptions.platform,\n executor: this.httpExecutor,\n }\n }\n\n private async doCheckForUpdates(): Promise<UpdateCheckResult> {\n this.emit(\"checking-for-update\")\n\n const result = await this.getUpdateInfoAndProvider()\n const updateInfo = result.info\n if (!await this.isUpdateAvailable(updateInfo)) {\n this._logger.info(`Update for version ${this.currentVersion} is not available (latest version: ${updateInfo.version}, downgrade is ${this.allowDowngrade ? \"allowed\" : \"disallowed\"}).`)\n this.emit(\"update-not-available\", updateInfo)\n return {\n versionInfo: updateInfo,\n updateInfo,\n }\n }\n\n this.updateInfoAndProvider = result\n this.onUpdateAvailable(updateInfo)\n\n const cancellationToken = new CancellationToken()\n //noinspection ES6MissingAwait\n return {\n versionInfo: updateInfo,\n updateInfo,\n cancellationToken,\n downloadPromise: this.autoDownload ? this.downloadUpdate(cancellationToken) : null\n }\n }\n\n protected onUpdateAvailable(updateInfo: UpdateInfo): void {\n this._logger.info(`Found version ${updateInfo.version} (url: ${asArray(updateInfo.files).map(it => it.url).join(\", \")})`)\n this.emit(\"update-available\", updateInfo)\n }\n\n /**\n * Start downloading update manually. You can use this method if `autoDownload` option is set to `false`.\n * @returns {Promise<string>} Path to downloaded file.\n */\n downloadUpdate(cancellationToken: CancellationToken = new CancellationToken()): Promise<any> {\n const updateInfoAndProvider = this.updateInfoAndProvider\n if (updateInfoAndProvider == null) {\n const error = new Error(\"Please check update first\")\n this.dispatchError(error)\n return Promise.reject(error)\n }\n\n this._logger.info(`Downloading update from ${asArray(updateInfoAndProvider.info.files).map(it => it.url).join(\", \")}`)\n const errorHandler = (e: Error): Error => {\n // https://github.com/electron-userland/electron-builder/issues/1150#issuecomment-436891159\n if (!(e instanceof CancellationError)) {\n try {\n this.dispatchError(e)\n }\n catch (nestedError) {\n this._logger.warn(`Cannot dispatch error event: ${nestedError.stack || nestedError}`)\n }\n }\n\n return e\n }\n\n try {\n return this.doDownloadUpdate({\n updateInfoAndProvider,\n requestHeaders: this.computeRequestHeaders(updateInfoAndProvider.provider),\n cancellationToken,\n })\n .catch(e => {\n throw errorHandler(e)\n })\n }\n catch (e) {\n return Promise.reject(errorHandler(e))\n }\n }\n\n protected dispatchError(e: Error): void {\n this.emit(\"error\", e, (e.stack || e).toString())\n }\n\n protected dispatchUpdateDownloaded(event: UpdateDownloadedEvent): void {\n this.emit(UPDATE_DOWNLOADED, event)\n }\n\n protected abstract doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>>\n\n /**\n * Restarts the app and installs the update after it has been downloaded.\n * It should only be called after `update-downloaded` has been emitted.\n *\n * **Note:** `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that.\n * This is different from the normal quit event sequence.\n *\n * @param isSilent *windows-only* Runs the installer in silent mode. Defaults to `false`.\n * @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.\n */\n abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void\n\n private async loadUpdateConfig(): Promise<any> {\n if (this._appUpdateConfigPath == null) {\n this._appUpdateConfigPath = this.app.appUpdateConfigPath\n }\n return load(await readFile(this._appUpdateConfigPath, \"utf-8\"))\n }\n\n private computeRequestHeaders(provider: Provider<any>): OutgoingHttpHeaders {\n const fileExtraDownloadHeaders = provider.fileExtraDownloadHeaders\n if (fileExtraDownloadHeaders != null) {\n const requestHeaders = this.requestHeaders\n return requestHeaders == null ? fileExtraDownloadHeaders : {\n ...fileExtraDownloadHeaders,\n ...requestHeaders,\n }\n }\n return this.computeFinalHeaders({accept: \"*/*\"})\n }\n\n private async getOrCreateStagingUserId(): Promise<string> {\n const file = path.join(this.app.userDataPath, \".updaterId\")\n try {\n const id = await readFile(file, \"utf-8\")\n if (UUID.check(id)) {\n return id\n }\n else {\n this._logger.warn(`Staging user id file exists, but content was invalid: ${id}`)\n }\n }\n catch (e) {\n if (e.code !== \"ENOENT\") {\n this._logger.warn(`Couldn't read staging user ID, creating a blank one: ${e}`)\n }\n }\n\n const id = UUID.v5(randomBytes(4096), UUID.OID)\n this._logger.info(`Generated new staging user ID: ${id}`)\n try {\n await outputFile(file, id)\n }\n catch (e) {\n this._logger.warn(`Couldn't write out staging user ID: ${e}`)\n }\n return id\n }\n\n /** @internal */\n get isAddNoCacheQuery(): boolean {\n const headers = this.requestHeaders\n // https://github.com/electron-userland/electron-builder/issues/3021\n if (headers == null) {\n return true\n }\n\n for (const headerName of Object.keys(headers)) {\n const s = headerName.toLowerCase()\n if (s === \"authorization\" || s === \"private-token\") {\n return false\n }\n }\n return true\n }\n\n /**\n * @private\n * @internal\n */\n _testOnlyOptions: TestOnlyUpdaterOptions | null = null\n\n private async getOrCreateDownloadHelper(): Promise<DownloadedUpdateHelper> {\n let result = this.downloadedUpdateHelper\n if (result == null) {\n const dirName = (await this.configOnDisk.value).updaterCacheDirName\n const logger = this._logger\n if (dirName == null) {\n logger.error(\"updaterCacheDirName is not specified in app-update.yml Was app build using at least electron-builder 20.34.0?\")\n }\n const cacheDir = path.join(this.app.baseCachePath, dirName || this.app.name)\n if (logger.debug != null) {\n logger.debug(`updater cache dir: ${cacheDir}`)\n }\n\n result = new DownloadedUpdateHelper(cacheDir)\n this.downloadedUpdateHelper = result\n }\n return result\n }\n\n protected async executeDownload(taskOptions: DownloadExecutorTask): Promise<Array<string>> {\n const fileInfo = taskOptions.fileInfo\n const downloadOptions: DownloadOptions = {\n headers: taskOptions.downloadUpdateOptions.requestHeaders,\n cancellationToken: taskOptions.downloadUpdateOptions.cancellationToken,\n sha2: (fileInfo.info as any).sha2,\n sha512: fileInfo.info.sha512,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n const updateInfo = taskOptions.downloadUpdateOptions.updateInfoAndProvider.info\n const version = updateInfo.version\n const packageInfo = fileInfo.packageInfo\n\n function getCacheUpdateFileName(): string {\n // NodeJS URL doesn't decode automatically\n const urlPath = decodeURIComponent(taskOptions.fileInfo.url.pathname)\n if (urlPath.endsWith(`.${taskOptions.fileExtension}`)) {\n return path.posix.basename(urlPath)\n }\n else {\n // url like /latest, generate name\n return `update.${taskOptions.fileExtension}`\n }\n }\n\n const downloadedUpdateHelper = await this.getOrCreateDownloadHelper()\n const cacheDir = downloadedUpdateHelper.cacheDirForPendingUpdate\n await ensureDir(cacheDir)\n const updateFileName = getCacheUpdateFileName()\n let updateFile = path.join(cacheDir, updateFileName)\n const packageFile = packageInfo == null ? null : path.join(cacheDir, `package-${version}${path.extname(packageInfo.path) || \".7z\"}`)\n\n const done = async (isSaveCache: boolean) => {\n await downloadedUpdateHelper.setDownloadedFile(updateFile, packageFile, updateInfo, fileInfo, updateFileName, isSaveCache)\n await taskOptions.done!!({\n ...updateInfo,\n downloadedFile: updateFile,\n })\n return packageFile == null ? [updateFile] : [updateFile, packageFile]\n }\n\n const log = this._logger\n const cachedUpdateFile = await downloadedUpdateHelper.validateDownloadedPath(updateFile, updateInfo, fileInfo, log)\n if (cachedUpdateFile != null) {\n updateFile = cachedUpdateFile\n return await done(false)\n }\n\n const removeFileIfAny = async () => {\n await downloadedUpdateHelper.clear()\n .catch(() => {\n // ignore\n })\n return await unlink(updateFile)\n .catch(() => {\n // ignore\n })\n }\n\n const tempUpdateFile = await createTempUpdateFile(`temp-${updateFileName}`, cacheDir, log)\n try {\n await taskOptions.task(tempUpdateFile, downloadOptions, packageFile, removeFileIfAny)\n await rename(tempUpdateFile, updateFile)\n }\n catch (e) {\n await removeFileIfAny()\n\n if (e instanceof CancellationError) {\n log.info(\"cancelled\")\n this.emit(\"update-cancelled\", updateInfo)\n }\n throw e\n }\n\n log.info(`New version ${version} has been downloaded to ${updateFile}`)\n return await done(true)\n }\n}\n\nexport interface DownloadUpdateOptions {\n readonly updateInfoAndProvider: UpdateInfoAndProvider\n readonly requestHeaders: OutgoingHttpHeaders\n readonly cancellationToken: CancellationToken\n}\n\nfunction hasPrereleaseComponents(version: SemVer) {\n const versionPrereleaseComponent = getVersionPreleaseComponents(version)\n return versionPrereleaseComponent != null && versionPrereleaseComponent.length > 0\n}\n\n/** @private */\nexport class NoOpLogger implements Logger {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n info(message?: any) {\n // ignore\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n warn(message?: any) {\n // ignore\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n error(message?: any) {\n // ignore\n }\n}\n\nexport interface UpdateInfoAndProvider {\n info: UpdateInfo\n provider: Provider<any>\n}\n\nexport interface DownloadExecutorTask {\n readonly fileExtension: string\n readonly fileInfo: ResolvedUpdateFileInfo\n readonly downloadUpdateOptions: DownloadUpdateOptions\n readonly task: (destinationFile: string, downloadOptions: DownloadOptions, packageFile: string | null, removeTempDirIfAny: () => Promise<any>) => Promise<any>\n\n readonly done?: (event: UpdateDownloadedEvent) => Promise<any>\n}\n\nexport interface DownloadNotification {\n body: string\n title: string\n}\n\n/** @private */\nexport interface TestOnlyUpdaterOptions {\n platform: ProviderPlatform\n\n isUseDifferentialDownload?: boolean\n}\n"],"sourceRoot":""}
@@ -3,7 +3,7 @@ import { AppAdapter } from "./AppAdapter";
3
3
  import { AppUpdater, DownloadUpdateOptions } from "./AppUpdater";
4
4
  export declare class MacUpdater extends AppUpdater {
5
5
  private readonly nativeUpdater;
6
- private updateInfoForPendingUpdateDownloadedEvent;
6
+ private squirrelDownloadedUpdate;
7
7
  constructor(options?: AllPublishOptions, app?: AppAdapter);
8
8
  protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>>;
9
9
  quitAndInstall(): void;
package/out/MacUpdater.js CHANGED
@@ -61,22 +61,26 @@ class MacUpdater extends _AppUpdater().AppUpdater {
61
61
  constructor(options, app) {
62
62
  super(options, app);
63
63
  this.nativeUpdater = require("electron").autoUpdater;
64
- this.updateInfoForPendingUpdateDownloadedEvent = null;
64
+ this.squirrelDownloadedUpdate = false;
65
65
  this.nativeUpdater.on("error", it => {
66
66
  this._logger.warn(it);
67
67
 
68
68
  this.emit("error", it);
69
69
  });
70
70
  this.nativeUpdater.on("update-downloaded", () => {
71
- const updateInfo = this.updateInfoForPendingUpdateDownloadedEvent;
72
- this.updateInfoForPendingUpdateDownloadedEvent = null;
73
- this.dispatchUpdateDownloaded(updateInfo);
71
+ this.squirrelDownloadedUpdate = true;
74
72
  });
75
73
  }
76
74
 
77
75
  doDownloadUpdate(downloadUpdateOptions) {
78
- this.updateInfoForPendingUpdateDownloadedEvent = null;
79
- const files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info).filter(file => process.arch == 'arm64' === file.url.pathname.includes('arm64'));
76
+ let files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info); // Allow arm64 macs to install universal or rosetta2(x64) - https://github.com/electron-userland/electron-builder/pull/5524
77
+
78
+ const isArm64 = file => file.url.pathname.includes("arm64");
79
+
80
+ if (files.some(isArm64)) {
81
+ files = files.filter(file => process.arch === "arm64" === isArm64(file));
82
+ }
83
+
80
84
  const zipFileInfo = (0, _Provider().findFile)(files, "zip", ["pkg", "dmg"]);
81
85
 
82
86
  if (zipFileInfo == null) {
@@ -102,7 +106,6 @@ class MacUpdater extends _AppUpdater().AppUpdater {
102
106
  },
103
107
  done: async event => {
104
108
  const downloadedFile = event.downloadedFile;
105
- this.updateInfoForPendingUpdateDownloadedEvent = event;
106
109
  let updateFileSize = zipFileInfo.info.size;
107
110
 
108
111
  if (updateFileSize == null) {
@@ -173,8 +176,14 @@ class MacUpdater extends _AppUpdater().AppUpdater {
173
176
  "Cache-Control": "no-cache"
174
177
  }
175
178
  });
176
- this.nativeUpdater.once("error", reject);
177
- this.nativeUpdater.checkForUpdates();
179
+ this.nativeUpdater.once("error", reject); // The update has been dowloaded and is ready to be served to Squirrel
180
+
181
+ this.dispatchUpdateDownloaded(event);
182
+
183
+ if (this.autoInstallOnAppQuit) {
184
+ // This will trigger fetching and installing the file on Squirrel side
185
+ this.nativeUpdater.checkForUpdates();
186
+ }
178
187
  });
179
188
  });
180
189
  }
@@ -182,7 +191,17 @@ class MacUpdater extends _AppUpdater().AppUpdater {
182
191
  }
183
192
 
184
193
  quitAndInstall() {
185
- this.nativeUpdater.quitAndInstall();
194
+ if (this.squirrelDownloadedUpdate) {
195
+ // Update already fetched by Squirrel, it's ready to install
196
+ this.nativeUpdater.quitAndInstall();
197
+ } else {
198
+ // Quit and install as soon as Squirrel get the update
199
+ this.nativeUpdater.on("update-downloaded", () => {
200
+ this.nativeUpdater.quitAndInstall();
201
+ }); // And trigger the update
202
+
203
+ this.nativeUpdater.checkForUpdates();
204
+ }
186
205
  }
187
206
 
188
207
  } exports.MacUpdater = MacUpdater;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/MacUpdater.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AACA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AAwB,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":""}
1
+ {"version":3,"sources":["../src/MacUpdater.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGM,MA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C,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,EANiC,CAQjC;;AACA,iBAAK,wBAAL,CAA8B,KAA9B;;AAEA,gBAAI,KAAK,oBAAT,EAA+B;AAC7B;AACA,mBAAK,aAAL,CAAmB,eAAnB;AACD;AACF,WAfD;AAgBD,SAtEY,CAAb;AAuED;AArFyB,KAArB,CAAP;AAuFD;;AAED,EAAA,cAAc,GAAA;AACZ,QAAI,KAAK,wBAAT,EAAmC;AACjC;AACA,WAAK,aAAL,CAAmB,cAAnB;AACD,KAHD,MAGO;AACL;AACA,WAAK,aAAL,CAAmB,EAAnB,CAAsB,mBAAtB,EAA2C,MAAK;AAC9C,aAAK,aAAL,CAAmB,cAAnB;AACD,OAFD,EAFK,CAML;;AACA,WAAK,aAAL,CAAmB,eAAnB;AACD;AACF;;AA/IuC,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 { ResolvedUpdateFileInfo } 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 squirrelDownloadedUpdate: boolean = false\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 })\n }\n\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n let files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info);\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\")\n if (files.some(isArm64)) {\n files = files.filter(file => (process.arch === \"arm64\") === isArm64(file));\n }\n\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 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\n // The update has been dowloaded and is ready to be served to Squirrel\n this.dispatchUpdateDownloaded(event)\n\n if (this.autoInstallOnAppQuit) {\n // This will trigger fetching and installing the file on Squirrel side\n this.nativeUpdater.checkForUpdates()\n }\n })\n })\n }\n })\n }\n\n quitAndInstall(): void {\n if (this.squirrelDownloadedUpdate) {\n // Update already fetched by Squirrel, it's ready to install\n this.nativeUpdater.quitAndInstall()\n } else {\n // Quit and install as soon as Squirrel get the update\n this.nativeUpdater.on(\"update-downloaded\", () => {\n this.nativeUpdater.quitAndInstall()\n })\n\n // And trigger the update\n this.nativeUpdater.checkForUpdates()\n }\n }\n}"],"sourceRoot":""}
@@ -152,7 +152,7 @@ class NsisUpdater extends _BaseUpdater().BaseUpdater {
152
152
  }
153
153
 
154
154
  if (isWebInstaller) {
155
- if (await this.differentialDownloadWebPackage(packageInfo, packageFile, provider)) {
155
+ if (await this.differentialDownloadWebPackage(downloadUpdateOptions, packageInfo, packageFile, provider)) {
156
156
  try {
157
157
  await this.httpExecutor.download(new (_url().URL)(packageInfo.path), packageFile, {
158
158
  headers: downloadUpdateOptions.requestHeaders,
@@ -271,15 +271,22 @@ class NsisUpdater extends _BaseUpdater().BaseUpdater {
271
271
  }
272
272
  };
273
273
 
274
- const blockMapDataList = await Promise.all([downloadBlockMap(oldBlockMapUrl), downloadBlockMap(newBlockMapUrl)]);
275
- await new (_GenericDifferentialDownloader().GenericDifferentialDownloader)(fileInfo.info, this.httpExecutor, {
274
+ const downloadOptions = {
276
275
  newUrl: fileInfo.url,
277
276
  oldFile: path.join(this.downloadedUpdateHelper.cacheDir, _builderUtilRuntime().CURRENT_APP_INSTALLER_FILE_NAME),
278
277
  logger: this._logger,
279
278
  newFile: installerPath,
280
279
  isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,
281
- requestHeaders: downloadUpdateOptions.requestHeaders
282
- }).download(blockMapDataList[0], blockMapDataList[1]);
280
+ requestHeaders: downloadUpdateOptions.requestHeaders,
281
+ cancellationToken: downloadUpdateOptions.cancellationToken
282
+ };
283
+
284
+ if (this.listenerCount(_main().DOWNLOAD_PROGRESS) > 0) {
285
+ downloadOptions.onProgress = it => this.emit(_main().DOWNLOAD_PROGRESS, it);
286
+ }
287
+
288
+ const blockMapDataList = await Promise.all([downloadBlockMap(oldBlockMapUrl), downloadBlockMap(newBlockMapUrl)]);
289
+ await new (_GenericDifferentialDownloader().GenericDifferentialDownloader)(fileInfo.info, this.httpExecutor, downloadOptions).download(blockMapDataList[0], blockMapDataList[1]);
283
290
  return false;
284
291
  } catch (e) {
285
292
  this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`);
@@ -293,20 +300,27 @@ class NsisUpdater extends _BaseUpdater().BaseUpdater {
293
300
  }
294
301
  }
295
302
 
296
- async differentialDownloadWebPackage(packageInfo, packagePath, provider) {
303
+ async differentialDownloadWebPackage(downloadUpdateOptions, packageInfo, packagePath, provider) {
297
304
  if (packageInfo.blockMapSize == null) {
298
305
  return true;
299
306
  }
300
307
 
301
308
  try {
302
- await new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(packageInfo, this.httpExecutor, {
309
+ const downloadOptions = {
303
310
  newUrl: new (_url().URL)(packageInfo.path),
304
311
  oldFile: path.join(this.downloadedUpdateHelper.cacheDir, _builderUtilRuntime().CURRENT_APP_PACKAGE_FILE_NAME),
305
312
  logger: this._logger,
306
313
  newFile: packagePath,
307
314
  requestHeaders: this.requestHeaders,
308
- isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest
309
- }).download();
315
+ isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,
316
+ cancellationToken: downloadUpdateOptions.cancellationToken
317
+ };
318
+
319
+ if (this.listenerCount(_main().DOWNLOAD_PROGRESS) > 0) {
320
+ downloadOptions.onProgress = it => this.emit(_main().DOWNLOAD_PROGRESS, it);
321
+ }
322
+
323
+ await new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(packageInfo, this.httpExecutor, downloadOptions).download();
310
324
  } catch (e) {
311
325
  this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`); // during test (developer machine mac or linux) we must throw error
312
326
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/NsisUpdater.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;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GAAR,KAAgB,SAApB,EAA+B;AAC7B,QAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,KAbD,CAcA,OAAO,KAAP,EAAc;AACZ,MAAA,MAAM,CAAC,KAAD,CAAN;AACD;AACF,GAlBM,CAAP;AAmBD,C","sourcesContent":["import { AllPublishOptions, newError, PackageFileInfo, BlockMap, CURRENT_APP_PACKAGE_FILE_NAME, CURRENT_APP_INSTALLER_FILE_NAME } from \"builder-util-runtime\"\nimport { spawn } from \"child_process\"\nimport * as path from \"path\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { BaseUpdater, InstallOptions } from \"./BaseUpdater\"\nimport { FileWithEmbeddedBlockMapDifferentialDownloader } from \"./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader\"\nimport { GenericDifferentialDownloader } from \"./differentialDownloader/GenericDifferentialDownloader\"\nimport { newUrlFromBase, ResolvedUpdateFileInfo } from \"./main\"\nimport { findFile, Provider } from \"./providers/Provider\"\nimport { unlink } from \"fs-extra\"\nimport { verifySignature } from \"./windowsExecutableCodeSignatureVerifier\"\nimport { URL } from \"url\"\nimport { gunzipSync } from \"zlib\"\n\nexport class NsisUpdater extends BaseUpdater {\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"exe\")!!\n return this.executeDownload({\n fileExtension: \"exe\",\n downloadUpdateOptions,\n fileInfo,\n task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {\n const packageInfo = fileInfo.packageInfo\n const isWebInstaller = packageInfo != null && packageFile != null\n if (isWebInstaller || await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider)) {\n await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions)\n }\n\n const signatureVerificationStatus = await this.verifySignature(destinationFile)\n if (signatureVerificationStatus != null) {\n await removeTempDirIfAny()\n // noinspection ThrowInsideFinallyBlockJS\n throw newError(`New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`, \"ERR_UPDATER_INVALID_SIGNATURE\")\n }\n\n if (isWebInstaller) {\n if (await this.differentialDownloadWebPackage(packageInfo!!, packageFile!!, provider)) {\n try {\n await this.httpExecutor.download(new URL(packageInfo!!.path), packageFile!!, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n sha512: packageInfo!!.sha512,\n })\n }\n catch (e) {\n try {\n await unlink(packageFile!!)\n }\n catch (ignored) {\n // ignore\n }\n\n throw e\n }\n }\n }\n },\n })\n }\n\n // $certificateInfo = (Get-AuthenticodeSignature 'xxx\\yyy.exe'\n // | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains(\"CN=siemens.com\")})\n // | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }\n private async verifySignature(tempUpdateFile: string): Promise<string | null> {\n let publisherName: Array<string> | string | null\n try {\n publisherName = (await this.configOnDisk.value).publisherName\n if (publisherName == null) {\n return null\n }\n }\n catch (e) {\n if (e.code === \"ENOENT\") {\n // no app-update.yml\n return null\n }\n throw e\n }\n return await verifySignature(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile, this._logger)\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const args = [\"--updated\"]\n if (options.isSilent) {\n args.push(\"/S\")\n }\n\n if (options.isForceRunAfter) {\n args.push(\"--force-run\")\n }\n\n const packagePath = this.downloadedUpdateHelper == null ? null : this.downloadedUpdateHelper.packageFile\n if (packagePath != null) {\n // only = form is supported\n args.push(`--package-file=${packagePath}`)\n }\n\n const callUsingElevation = (): void => {\n _spawn(path.join(process.resourcesPath!!, \"elevate.exe\"), [options.installerPath].concat(args))\n .catch(e => this.dispatchError(e))\n }\n\n if (options.isAdminRightsRequired) {\n this._logger.info(\"isAdminRightsRequired is set to true, run installer using elevate.exe\")\n callUsingElevation()\n return true\n }\n\n _spawn(options.installerPath, args)\n .catch((e: Error) => {\n // https://github.com/electron-userland/electron-builder/issues/1129\n // Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors\n const errorCode = (e as NodeJS.ErrnoException).code\n this._logger.info(`Cannot run installer: error code: ${errorCode}, error message: \"${e.message}\", will be executed again using elevate if EACCES\"`)\n if (errorCode === \"UNKNOWN\" || errorCode === \"EACCES\") {\n callUsingElevation()\n }\n else {\n this.dispatchError(e)\n }\n })\n return true\n }\n\n private async differentialDownloadInstaller(fileInfo: ResolvedUpdateFileInfo, downloadUpdateOptions: DownloadUpdateOptions, installerPath: string, provider: Provider<any>): Promise<boolean> {\n try {\n if (this._testOnlyOptions != null && !this._testOnlyOptions.isUseDifferentialDownload) {\n return true\n }\n\n const newBlockMapUrl = newUrlFromBase(`${fileInfo.url.pathname}.blockmap`, fileInfo.url)\n const oldBlockMapUrl = newUrlFromBase(`${fileInfo.url.pathname.replace(new RegExp(downloadUpdateOptions.updateInfoAndProvider.info.version, \"g\"), this.app.version)}.blockmap`, fileInfo.url)\n this._logger.info(`Download block maps (old: \"${oldBlockMapUrl.href}\", new: ${newBlockMapUrl.href})`)\n\n const downloadBlockMap = async (url: URL): Promise<BlockMap> => {\n const data = await this.httpExecutor.downloadToBuffer(url, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n })\n\n if (data == null || data.length === 0) {\n throw new Error(`Blockmap \"${url.href}\" is empty`)\n }\n\n try {\n return JSON.parse(gunzipSync(data).toString())\n }\n catch (e) {\n throw new Error(`Cannot parse blockmap \"${url.href}\", error: ${e}, raw data: ${data}`)\n }\n }\n\n const blockMapDataList = await Promise.all([downloadBlockMap(oldBlockMapUrl), downloadBlockMap(newBlockMapUrl)])\n await new GenericDifferentialDownloader(fileInfo.info, this.httpExecutor, {\n newUrl: fileInfo.url,\n oldFile: path.join(this.downloadedUpdateHelper!!.cacheDir, CURRENT_APP_INSTALLER_FILE_NAME),\n logger: this._logger,\n newFile: installerPath,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n requestHeaders: downloadUpdateOptions.requestHeaders,\n })\n .download(blockMapDataList[0], blockMapDataList[1])\n return false\n }\n catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n if (this._testOnlyOptions != null) {\n // test mode\n throw e\n }\n return true\n }\n }\n\n private async differentialDownloadWebPackage(packageInfo: PackageFileInfo, packagePath: string, provider: Provider<any>): Promise<boolean> {\n if (packageInfo.blockMapSize == null) {\n return true\n }\n\n try {\n await new FileWithEmbeddedBlockMapDifferentialDownloader(packageInfo, this.httpExecutor, {\n newUrl: new URL(packageInfo.path),\n oldFile: path.join(this.downloadedUpdateHelper!!.cacheDir, CURRENT_APP_PACKAGE_FILE_NAME),\n logger: this._logger,\n newFile: packagePath,\n requestHeaders: this.requestHeaders,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n })\n .download()\n }\n catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n // during test (developer machine mac or linux) we must throw error\n return process.platform === \"win32\"\n }\n return false\n }\n}\n\n/**\n * This handles both node 8 and node 10 way of emitting error when spawning a process\n * - node 8: Throws the error\n * - node 10: Emit the error(Need to listen with on)\n */\nasync function _spawn(exe: string, args: Array<string>): Promise<any> {\n return new Promise((resolve, reject) => {\n try {\n const process = spawn(exe, args, {\n detached: true,\n stdio: \"ignore\",\n })\n process.on(\"error\", error => {\n reject(error)\n })\n process.unref()\n\n if (process.pid !== undefined) {\n resolve(true)\n }\n }\n catch (error) {\n reject(error)\n }\n })\n}\n"],"sourceRoot":""}
1
+ {"version":3,"sources":["../src/NsisUpdater.ts"],"names":[],"m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F,IAAW,CAAC,EAA7F,EADQ,CAER;;;AACA,aAAO,OAAO,CAAC,QAAR,KAAqB,OAA5B;AACD;;AACD,WAAO,KAAP;AACD;;AA1MyC;AA6M5C;;;;;;;;;AAKA,eAAe,MAAf,CAAsB,GAAtB,EAAmC,IAAnC,EAAsD;AACpD,SAAO,IAAI,OAAJ,CAAY,CAAC,OAAD,EAAU,MAAV,KAAoB;AACrC,QAAI;AACF,YAAM,OAAO,GAAG,4BAAM,GAAN,EAAW,IAAX,EAAiB;AAC/B,QAAA,QAAQ,EAAE,IADqB;AAE/B,QAAA,KAAK,EAAE;AAFwB,OAAjB,CAAhB;AAIA,MAAA,OAAO,CAAC,EAAR,CAAW,OAAX,EAAoB,KAAK,IAAG;AAC1B,QAAA,MAAM,CAAC,KAAD,CAAN;AACD,OAFD;AAGA,MAAA,OAAO,CAAC,KAAR;;AAEA,UAAI,OAAO,CAAC,GAAR,KAAgB,SAApB,EAA+B;AAC7B,QAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,KAbD,CAcA,OAAO,KAAP,EAAc;AACZ,MAAA,MAAM,CAAC,KAAD,CAAN;AACD;AACF,GAlBM,CAAP;AAmBD,C","sourcesContent":["import { AllPublishOptions, newError, PackageFileInfo, BlockMap, CURRENT_APP_PACKAGE_FILE_NAME, CURRENT_APP_INSTALLER_FILE_NAME } from \"builder-util-runtime\"\nimport { spawn } from \"child_process\"\nimport * as path from \"path\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { BaseUpdater, InstallOptions } from \"./BaseUpdater\"\nimport { DifferentialDownloaderOptions } from \"./differentialDownloader/DifferentialDownloader\"\nimport { FileWithEmbeddedBlockMapDifferentialDownloader } from \"./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader\"\nimport { GenericDifferentialDownloader } from \"./differentialDownloader/GenericDifferentialDownloader\"\nimport { DOWNLOAD_PROGRESS, newUrlFromBase, ResolvedUpdateFileInfo } from \"./main\"\nimport { findFile, Provider } from \"./providers/Provider\"\nimport { unlink } from \"fs-extra\"\nimport { verifySignature } from \"./windowsExecutableCodeSignatureVerifier\"\nimport { URL } from \"url\"\nimport { gunzipSync } from \"zlib\"\n\nexport class NsisUpdater extends BaseUpdater {\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"exe\")!!\n return this.executeDownload({\n fileExtension: \"exe\",\n downloadUpdateOptions,\n fileInfo,\n task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {\n const packageInfo = fileInfo.packageInfo\n const isWebInstaller = packageInfo != null && packageFile != null\n if (isWebInstaller || await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider)) {\n await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions)\n }\n\n const signatureVerificationStatus = await this.verifySignature(destinationFile)\n if (signatureVerificationStatus != null) {\n await removeTempDirIfAny()\n // noinspection ThrowInsideFinallyBlockJS\n throw newError(`New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`, \"ERR_UPDATER_INVALID_SIGNATURE\")\n }\n\n if (isWebInstaller) {\n if (await this.differentialDownloadWebPackage(downloadUpdateOptions, packageInfo!!, packageFile!!, provider)) {\n try {\n await this.httpExecutor.download(new URL(packageInfo!!.path), packageFile!!, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n sha512: packageInfo!!.sha512,\n })\n }\n catch (e) {\n try {\n await unlink(packageFile!!)\n }\n catch (ignored) {\n // ignore\n }\n\n throw e\n }\n }\n }\n },\n })\n }\n\n // $certificateInfo = (Get-AuthenticodeSignature 'xxx\\yyy.exe'\n // | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains(\"CN=siemens.com\")})\n // | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }\n private async verifySignature(tempUpdateFile: string): Promise<string | null> {\n let publisherName: Array<string> | string | null\n try {\n publisherName = (await this.configOnDisk.value).publisherName\n if (publisherName == null) {\n return null\n }\n }\n catch (e) {\n if (e.code === \"ENOENT\") {\n // no app-update.yml\n return null\n }\n throw e\n }\n return await verifySignature(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile, this._logger)\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const args = [\"--updated\"]\n if (options.isSilent) {\n args.push(\"/S\")\n }\n\n if (options.isForceRunAfter) {\n args.push(\"--force-run\")\n }\n\n const packagePath = this.downloadedUpdateHelper == null ? null : this.downloadedUpdateHelper.packageFile\n if (packagePath != null) {\n // only = form is supported\n args.push(`--package-file=${packagePath}`)\n }\n\n const callUsingElevation = (): void => {\n _spawn(path.join(process.resourcesPath!!, \"elevate.exe\"), [options.installerPath].concat(args))\n .catch(e => this.dispatchError(e))\n }\n\n if (options.isAdminRightsRequired) {\n this._logger.info(\"isAdminRightsRequired is set to true, run installer using elevate.exe\")\n callUsingElevation()\n return true\n }\n\n _spawn(options.installerPath, args)\n .catch((e: Error) => {\n // https://github.com/electron-userland/electron-builder/issues/1129\n // Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors\n const errorCode = (e as NodeJS.ErrnoException).code\n this._logger.info(`Cannot run installer: error code: ${errorCode}, error message: \"${e.message}\", will be executed again using elevate if EACCES\"`)\n if (errorCode === \"UNKNOWN\" || errorCode === \"EACCES\") {\n callUsingElevation()\n }\n else {\n this.dispatchError(e)\n }\n })\n return true\n }\n\n private async differentialDownloadInstaller(fileInfo: ResolvedUpdateFileInfo, downloadUpdateOptions: DownloadUpdateOptions, installerPath: string, provider: Provider<any>): Promise<boolean> {\n try {\n if (this._testOnlyOptions != null && !this._testOnlyOptions.isUseDifferentialDownload) {\n return true\n }\n\n const newBlockMapUrl = newUrlFromBase(`${fileInfo.url.pathname}.blockmap`, fileInfo.url)\n const oldBlockMapUrl = newUrlFromBase(`${fileInfo.url.pathname.replace(new RegExp(downloadUpdateOptions.updateInfoAndProvider.info.version, \"g\"), this.app.version)}.blockmap`, fileInfo.url)\n this._logger.info(`Download block maps (old: \"${oldBlockMapUrl.href}\", new: ${newBlockMapUrl.href})`)\n\n const downloadBlockMap = async (url: URL): Promise<BlockMap> => {\n const data = await this.httpExecutor.downloadToBuffer(url, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n })\n\n if (data == null || data.length === 0) {\n throw new Error(`Blockmap \"${url.href}\" is empty`)\n }\n\n try {\n return JSON.parse(gunzipSync(data).toString())\n }\n catch (e) {\n throw new Error(`Cannot parse blockmap \"${url.href}\", error: ${e}, raw data: ${data}`)\n }\n }\n\n const downloadOptions: DifferentialDownloaderOptions = {\n newUrl: fileInfo.url,\n oldFile: path.join(this.downloadedUpdateHelper!!.cacheDir, CURRENT_APP_INSTALLER_FILE_NAME),\n logger: this._logger,\n newFile: installerPath,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n requestHeaders: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n const blockMapDataList = await Promise.all([downloadBlockMap(oldBlockMapUrl), downloadBlockMap(newBlockMapUrl)])\n await new GenericDifferentialDownloader(fileInfo.info, this.httpExecutor, downloadOptions)\n .download(blockMapDataList[0], blockMapDataList[1])\n return false\n }\n catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n if (this._testOnlyOptions != null) {\n // test mode\n throw e\n }\n return true\n }\n }\n\n private async differentialDownloadWebPackage(downloadUpdateOptions: DownloadUpdateOptions, packageInfo: PackageFileInfo, packagePath: string, provider: Provider<any>): Promise<boolean> {\n if (packageInfo.blockMapSize == null) {\n return true\n }\n\n try {\n const downloadOptions: DifferentialDownloaderOptions = {\n newUrl: new URL(packageInfo.path),\n oldFile: path.join(this.downloadedUpdateHelper!!.cacheDir, CURRENT_APP_PACKAGE_FILE_NAME),\n logger: this._logger,\n newFile: packagePath,\n requestHeaders: this.requestHeaders,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n await new FileWithEmbeddedBlockMapDifferentialDownloader(packageInfo, this.httpExecutor, downloadOptions)\n .download()\n }\n catch (e) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n // during test (developer machine mac or linux) we must throw error\n return process.platform === \"win32\"\n }\n return false\n }\n}\n\n/**\n * This handles both node 8 and node 10 way of emitting error when spawning a process\n * - node 8: Throws the error\n * - node 10: Emit the error(Need to listen with on)\n */\nasync function _spawn(exe: string, args: Array<string>): Promise<any> {\n return new Promise((resolve, reject) => {\n try {\n const process = spawn(exe, args, {\n detached: true,\n stdio: \"ignore\",\n })\n process.on(\"error\", error => {\n reject(error)\n })\n process.unref()\n\n if (process.pid !== undefined) {\n resolve(true)\n }\n }\n catch (error) {\n reject(error)\n }\n })\n}\n"],"sourceRoot":""}