electron-updater 4.3.5 → 4.3.9

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.
Files changed (70) hide show
  1. package/LICENSE +22 -0
  2. package/out/AppAdapter.js +19 -28
  3. package/out/AppAdapter.js.map +1 -1
  4. package/out/AppImageUpdater.js +103 -173
  5. package/out/AppImageUpdater.js.map +1 -1
  6. package/out/AppUpdater.d.ts +1 -3
  7. package/out/AppUpdater.js +517 -773
  8. package/out/AppUpdater.js.map +1 -1
  9. package/out/BaseUpdater.js +79 -103
  10. package/out/BaseUpdater.js.map +1 -1
  11. package/out/DownloadedUpdateHelper.js +150 -224
  12. package/out/DownloadedUpdateHelper.js.map +1 -1
  13. package/out/ElectronAppAdapter.js +35 -63
  14. package/out/ElectronAppAdapter.js.map +1 -1
  15. package/out/MacUpdater.d.ts +1 -1
  16. package/out/MacUpdater.js +132 -182
  17. package/out/MacUpdater.js.map +1 -1
  18. package/out/NoOpLogger.d.ts +6 -0
  19. package/out/NoOpLogger.js +19 -0
  20. package/out/NoOpLogger.js.map +1 -0
  21. package/out/NsisUpdater.js +199 -331
  22. package/out/NsisUpdater.js.map +1 -1
  23. package/out/differentialDownloader/DataSplitter.js +180 -252
  24. package/out/differentialDownloader/DataSplitter.js.map +1 -1
  25. package/out/differentialDownloader/DifferentialDownloader.d.ts +3 -0
  26. package/out/differentialDownloader/DifferentialDownloader.js +243 -308
  27. package/out/differentialDownloader/DifferentialDownloader.js.map +1 -1
  28. package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js +29 -65
  29. package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js.map +1 -1
  30. package/out/differentialDownloader/GenericDifferentialDownloader.js +7 -21
  31. package/out/differentialDownloader/GenericDifferentialDownloader.js.map +1 -1
  32. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.d.ts +32 -0
  33. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js +90 -0
  34. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js.map +1 -0
  35. package/out/differentialDownloader/downloadPlanBuilder.js +99 -124
  36. package/out/differentialDownloader/downloadPlanBuilder.js.map +1 -1
  37. package/out/differentialDownloader/multipleRangeDownloader.js +99 -148
  38. package/out/differentialDownloader/multipleRangeDownloader.js.map +1 -1
  39. package/out/electronHttpExecutor.js +73 -106
  40. package/out/electronHttpExecutor.js.map +1 -1
  41. package/out/event.d.ts +35 -0
  42. package/out/event.js +39 -0
  43. package/out/event.js.map +1 -0
  44. package/out/log.d.ts +11 -0
  45. package/out/log.js +19 -0
  46. package/out/log.js.map +1 -0
  47. package/out/main.d.ts +1 -4
  48. package/out/main.js +60 -212
  49. package/out/main.js.map +1 -1
  50. package/out/providerFactory.js +49 -105
  51. package/out/providerFactory.js.map +1 -1
  52. package/out/providers/BintrayProvider.d.ts +2 -2
  53. package/out/providers/BintrayProvider.js +40 -95
  54. package/out/providers/BintrayProvider.js.map +1 -1
  55. package/out/providers/GenericProvider.d.ts +2 -2
  56. package/out/providers/GenericProvider.js +46 -80
  57. package/out/providers/GenericProvider.js.map +1 -1
  58. package/out/providers/GitHubProvider.d.ts +2 -2
  59. package/out/providers/GitHubProvider.js +122 -201
  60. package/out/providers/GitHubProvider.js.map +1 -1
  61. package/out/providers/PrivateGitHubProvider.js +87 -165
  62. package/out/providers/PrivateGitHubProvider.js.map +1 -1
  63. package/out/providers/Provider.js +122 -173
  64. package/out/providers/Provider.js.map +1 -1
  65. package/out/util.d.ts +5 -0
  66. package/out/util.js +42 -0
  67. package/out/util.js.map +1 -0
  68. package/out/windowsExecutableCodeSignatureVerifier.js +99 -139
  69. package/out/windowsExecutableCodeSignatureVerifier.js.map +1 -1
  70. package/package.json +33 -31
@@ -1,244 +1,170 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createTempUpdateFile = createTempUpdateFile;
7
- exports.DownloadedUpdateHelper = void 0;
8
-
9
- function _crypto() {
10
- const data = require("crypto");
11
-
12
- _crypto = function () {
13
- return data;
14
- };
15
-
16
- return data;
17
- }
18
-
19
- var _fs = require("fs");
20
-
21
- function _lodash() {
22
- const data = _interopRequireDefault(require("lodash.isequal"));
23
-
24
- _lodash = function () {
25
- return data;
26
- };
27
-
28
- return data;
29
- }
30
-
31
- function _fsExtra() {
32
- const data = require("fs-extra");
33
-
34
- _fsExtra = function () {
35
- return data;
36
- };
37
-
38
- return data;
39
- }
40
-
41
- var path = _interopRequireWildcard(require("path"));
42
-
43
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
44
-
45
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
46
-
47
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
48
-
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTempUpdateFile = exports.DownloadedUpdateHelper = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const fs_1 = require("fs");
6
+ // @ts-ignore
7
+ const isEqual = require("lodash.isequal");
8
+ const fs_extra_1 = require("fs-extra");
9
+ const path = require("path");
49
10
  /** @private **/
50
11
  class DownloadedUpdateHelper {
51
- constructor(cacheDir) {
52
- this.cacheDir = cacheDir;
53
- this._file = null;
54
- this._packageFile = null;
55
- this.versionInfo = null;
56
- this.fileInfo = null;
57
- this._downloadedFileInfo = null;
58
- }
59
-
60
- get downloadedFileInfo() {
61
- return this._downloadedFileInfo;
62
- }
63
-
64
- get file() {
65
- return this._file;
66
- }
67
-
68
- get packageFile() {
69
- return this._packageFile;
70
- }
71
-
72
- get cacheDirForPendingUpdate() {
73
- return path.join(this.cacheDir, "pending");
74
- }
75
-
76
- async validateDownloadedPath(updateFile, updateInfo, fileInfo, logger) {
77
- if (this.versionInfo != null && this.file === updateFile && this.fileInfo != null) {
78
- // update has already been downloaded from this running instance
79
- // check here only existence, not checksum
80
- if ((0, _lodash().default)(this.versionInfo, updateInfo) && (0, _lodash().default)(this.fileInfo.info, fileInfo.info) && (await (0, _fsExtra().pathExists)(updateFile))) {
81
- return updateFile;
82
- } else {
83
- return null;
84
- }
85
- } // update has already been downloaded from some previous app launch
86
-
87
-
88
- const cachedUpdateFile = await this.getValidCachedUpdateFile(fileInfo, logger);
89
-
90
- if (cachedUpdateFile === null) {
91
- return null;
12
+ constructor(cacheDir) {
13
+ this.cacheDir = cacheDir;
14
+ this._file = null;
15
+ this._packageFile = null;
16
+ this.versionInfo = null;
17
+ this.fileInfo = null;
18
+ this._downloadedFileInfo = null;
92
19
  }
93
-
94
- logger.info(`Update has already been downloaded to ${updateFile}).`);
95
- this._file = cachedUpdateFile;
96
- return cachedUpdateFile;
97
- }
98
-
99
- async setDownloadedFile(downloadedFile, packageFile, versionInfo, fileInfo, updateFileName, isSaveCache) {
100
- this._file = downloadedFile;
101
- this._packageFile = packageFile;
102
- this.versionInfo = versionInfo;
103
- this.fileInfo = fileInfo;
104
- this._downloadedFileInfo = {
105
- fileName: updateFileName,
106
- sha512: fileInfo.info.sha512,
107
- isAdminRightsRequired: fileInfo.info.isAdminRightsRequired === true
108
- };
109
-
110
- if (isSaveCache) {
111
- await (0, _fsExtra().outputJson)(this.getUpdateInfoFile(), this._downloadedFileInfo);
20
+ get downloadedFileInfo() {
21
+ return this._downloadedFileInfo;
112
22
  }
113
- }
114
-
115
- async clear() {
116
- this._file = null;
117
- this._packageFile = null;
118
- this.versionInfo = null;
119
- this.fileInfo = null;
120
- await this.cleanCacheDirForPendingUpdate();
121
- }
122
-
123
- async cleanCacheDirForPendingUpdate() {
124
- try {
125
- // remove stale data
126
- await (0, _fsExtra().emptyDir)(this.cacheDirForPendingUpdate);
127
- } catch (ignore) {// ignore
23
+ get file() {
24
+ return this._file;
128
25
  }
129
- }
130
- /**
131
- * Returns "update-info.json" which is created in the update cache directory's "pending" subfolder after the first update is downloaded. If the update file does not exist then the cache is cleared and recreated. If the update file exists then its properties are validated.
132
- * @param fileInfo
133
- * @param logger
134
- */
135
-
136
-
137
- async getValidCachedUpdateFile(fileInfo, logger) {
138
- var _a;
139
-
140
- const updateInfoFilePath = this.getUpdateInfoFile();
141
- const doesUpdateInfoFileExist = await (0, _fsExtra().pathExistsSync)(updateInfoFilePath);
142
-
143
- if (!doesUpdateInfoFileExist) {
144
- return null;
26
+ get packageFile() {
27
+ return this._packageFile;
145
28
  }
146
-
147
- let cachedInfo;
148
-
149
- try {
150
- cachedInfo = await (0, _fsExtra().readJson)(updateInfoFilePath);
151
- } catch (error) {
152
- let message = `No cached update info available`;
153
-
154
- if (error.code !== "ENOENT") {
155
- await this.cleanCacheDirForPendingUpdate();
156
- message += ` (error on read: ${error.message})`;
157
- }
158
-
159
- logger.info(message);
160
- return null;
29
+ get cacheDirForPendingUpdate() {
30
+ return path.join(this.cacheDir, "pending");
161
31
  }
162
-
163
- const isCachedInfoFileNameValid = (_a = (cachedInfo === null || cachedInfo === void 0 ? void 0 : cachedInfo.fileName) !== null) !== null && _a !== void 0 ? _a : false;
164
-
165
- if (!isCachedInfoFileNameValid) {
166
- logger.warn(`Cached update info is corrupted: no fileName, directory for cached update will be cleaned`);
167
- await this.cleanCacheDirForPendingUpdate();
168
- return null;
32
+ async validateDownloadedPath(updateFile, updateInfo, fileInfo, logger) {
33
+ if (this.versionInfo != null && this.file === updateFile && this.fileInfo != null) {
34
+ // update has already been downloaded from this running instance
35
+ // check here only existence, not checksum
36
+ if (isEqual(this.versionInfo, updateInfo) && isEqual(this.fileInfo.info, fileInfo.info) && (await fs_extra_1.pathExists(updateFile))) {
37
+ return updateFile;
38
+ }
39
+ else {
40
+ return null;
41
+ }
42
+ }
43
+ // update has already been downloaded from some previous app launch
44
+ const cachedUpdateFile = await this.getValidCachedUpdateFile(fileInfo, logger);
45
+ if (cachedUpdateFile === null) {
46
+ return null;
47
+ }
48
+ logger.info(`Update has already been downloaded to ${updateFile}).`);
49
+ this._file = cachedUpdateFile;
50
+ return cachedUpdateFile;
169
51
  }
170
-
171
- if (fileInfo.info.sha512 !== cachedInfo.sha512) {
172
- logger.info(`Cached update sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: ${cachedInfo.sha512}, expected: ${fileInfo.info.sha512}. Directory for cached update will be cleaned`);
173
- await this.cleanCacheDirForPendingUpdate();
174
- return null;
52
+ async setDownloadedFile(downloadedFile, packageFile, versionInfo, fileInfo, updateFileName, isSaveCache) {
53
+ this._file = downloadedFile;
54
+ this._packageFile = packageFile;
55
+ this.versionInfo = versionInfo;
56
+ this.fileInfo = fileInfo;
57
+ this._downloadedFileInfo = {
58
+ fileName: updateFileName,
59
+ sha512: fileInfo.info.sha512,
60
+ isAdminRightsRequired: fileInfo.info.isAdminRightsRequired === true,
61
+ };
62
+ if (isSaveCache) {
63
+ await fs_extra_1.outputJson(this.getUpdateInfoFile(), this._downloadedFileInfo);
64
+ }
175
65
  }
176
-
177
- const updateFile = path.join(this.cacheDirForPendingUpdate, cachedInfo.fileName);
178
-
179
- if (!(await (0, _fsExtra().pathExists)(updateFile))) {
180
- logger.info("Cached update file doesn't exist, directory for cached update will be cleaned");
181
- await this.cleanCacheDirForPendingUpdate();
182
- return null;
66
+ async clear() {
67
+ this._file = null;
68
+ this._packageFile = null;
69
+ this.versionInfo = null;
70
+ this.fileInfo = null;
71
+ await this.cleanCacheDirForPendingUpdate();
72
+ }
73
+ async cleanCacheDirForPendingUpdate() {
74
+ try {
75
+ // remove stale data
76
+ await fs_extra_1.emptyDir(this.cacheDirForPendingUpdate);
77
+ }
78
+ catch (ignore) {
79
+ // ignore
80
+ }
81
+ }
82
+ /**
83
+ * Returns "update-info.json" which is created in the update cache directory's "pending" subfolder after the first update is downloaded. If the update file does not exist then the cache is cleared and recreated. If the update file exists then its properties are validated.
84
+ * @param fileInfo
85
+ * @param logger
86
+ */
87
+ async getValidCachedUpdateFile(fileInfo, logger) {
88
+ var _a;
89
+ const updateInfoFilePath = this.getUpdateInfoFile();
90
+ const doesUpdateInfoFileExist = await fs_extra_1.pathExists(updateInfoFilePath);
91
+ if (!doesUpdateInfoFileExist) {
92
+ return null;
93
+ }
94
+ let cachedInfo;
95
+ try {
96
+ cachedInfo = await fs_extra_1.readJson(updateInfoFilePath);
97
+ }
98
+ catch (error) {
99
+ let message = `No cached update info available`;
100
+ if (error.code !== "ENOENT") {
101
+ await this.cleanCacheDirForPendingUpdate();
102
+ message += ` (error on read: ${error.message})`;
103
+ }
104
+ logger.info(message);
105
+ return null;
106
+ }
107
+ const isCachedInfoFileNameValid = (_a = (cachedInfo === null || cachedInfo === void 0 ? void 0 : cachedInfo.fileName) !== null) !== null && _a !== void 0 ? _a : false;
108
+ if (!isCachedInfoFileNameValid) {
109
+ logger.warn(`Cached update info is corrupted: no fileName, directory for cached update will be cleaned`);
110
+ await this.cleanCacheDirForPendingUpdate();
111
+ return null;
112
+ }
113
+ if (fileInfo.info.sha512 !== cachedInfo.sha512) {
114
+ logger.info(`Cached update sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: ${cachedInfo.sha512}, expected: ${fileInfo.info.sha512}. Directory for cached update will be cleaned`);
115
+ await this.cleanCacheDirForPendingUpdate();
116
+ return null;
117
+ }
118
+ const updateFile = path.join(this.cacheDirForPendingUpdate, cachedInfo.fileName);
119
+ if (!(await fs_extra_1.pathExists(updateFile))) {
120
+ logger.info("Cached update file doesn't exist");
121
+ return null;
122
+ }
123
+ const sha512 = await hashFile(updateFile);
124
+ if (fileInfo.info.sha512 !== sha512) {
125
+ logger.warn(`Sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: ${sha512}, expected: ${fileInfo.info.sha512}`);
126
+ await this.cleanCacheDirForPendingUpdate();
127
+ return null;
128
+ }
129
+ this._downloadedFileInfo = cachedInfo;
130
+ return updateFile;
183
131
  }
184
-
185
- const sha512 = await hashFile(updateFile);
186
-
187
- if (fileInfo.info.sha512 !== sha512) {
188
- logger.warn(`Sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: ${sha512}, expected: ${fileInfo.info.sha512}`);
189
- await this.cleanCacheDirForPendingUpdate();
190
- return null;
132
+ getUpdateInfoFile() {
133
+ return path.join(this.cacheDirForPendingUpdate, "update-info.json");
191
134
  }
192
-
193
- this._downloadedFileInfo = cachedInfo;
194
- return updateFile;
195
- }
196
-
197
- getUpdateInfoFile() {
198
- return path.join(this.cacheDirForPendingUpdate, "update-info.json");
199
- }
200
-
201
135
  }
202
-
203
136
  exports.DownloadedUpdateHelper = DownloadedUpdateHelper;
204
-
205
137
  function hashFile(file, algorithm = "sha512", encoding = "base64", options) {
206
- return new Promise((resolve, reject) => {
207
- const hash = (0, _crypto().createHash)(algorithm);
208
- hash.on("error", reject).setEncoding(encoding);
209
- (0, _fs.createReadStream)(file, { ...options,
210
- highWaterMark: 1024 * 1024
211
- /* better to use more memory but hash faster */
212
-
213
- }).on("error", reject).on("end", () => {
214
- hash.end();
215
- resolve(hash.read());
216
- }).pipe(hash, {
217
- end: false
138
+ return new Promise((resolve, reject) => {
139
+ const hash = crypto_1.createHash(algorithm);
140
+ hash.on("error", reject).setEncoding(encoding);
141
+ fs_1.createReadStream(file, { ...options, highWaterMark: 1024 * 1024 /* better to use more memory but hash faster */ })
142
+ .on("error", reject)
143
+ .on("end", () => {
144
+ hash.end();
145
+ resolve(hash.read());
146
+ })
147
+ .pipe(hash, { end: false });
218
148
  });
219
- });
220
149
  }
221
-
222
150
  async function createTempUpdateFile(name, cacheDir, log) {
223
- // https://github.com/electron-userland/electron-builder/pull/2474#issuecomment-366481912
224
- let nameCounter = 0;
225
- let result = path.join(cacheDir, name);
226
-
227
- for (let i = 0; i < 3; i++) {
228
- try {
229
- await (0, _fsExtra().unlink)(result);
230
- return result;
231
- } catch (e) {
232
- if (e.code === "ENOENT") {
233
- return result;
234
- }
235
-
236
- log.warn(`Error on remove temp update file: ${e}`);
237
- result = path.join(cacheDir, `${nameCounter++}-${name}`);
151
+ // https://github.com/electron-userland/electron-builder/pull/2474#issuecomment-366481912
152
+ let nameCounter = 0;
153
+ let result = path.join(cacheDir, name);
154
+ for (let i = 0; i < 3; i++) {
155
+ try {
156
+ await fs_extra_1.unlink(result);
157
+ return result;
158
+ }
159
+ catch (e) {
160
+ if (e.code === "ENOENT") {
161
+ return result;
162
+ }
163
+ log.warn(`Error on remove temp update file: ${e}`);
164
+ result = path.join(cacheDir, `${nameCounter++}-${name}`);
165
+ }
238
166
  }
239
- }
240
-
241
- return result;
242
- }
243
- // __ts-babel@6.0.4
167
+ return result;
168
+ }
169
+ exports.createTempUpdateFile = createTempUpdateFile;
244
170
  //# sourceMappingURL=DownloadedUpdateHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/DownloadedUpdateHelper.ts"],"names":[],"mappings":";;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;;;;;;;AAEA;AACM,MAAO,sBAAP,CAA6B;AAOjC,EAAA,WAAA,CAAqB,QAArB,EAAqC;AAAhB,SAAA,QAAA,GAAA,QAAA;AANb,SAAA,KAAA,GAAuB,IAAvB;AACA,SAAA,YAAA,GAA8B,IAA9B;AAEA,SAAA,WAAA,GAAiC,IAAjC;AACA,SAAA,QAAA,GAA0C,IAA1C;AAKA,SAAA,mBAAA,G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AAI,EAA5C,CAAT;AACD;AACF;;AACD,SAAO,MAAP;AACD,C","sourcesContent":["import { UpdateInfo } from \"builder-util-runtime\"\nimport { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\nimport isEqual from \"lodash.isequal\"\nimport { Logger, ResolvedUpdateFileInfo } from \"./main\"\nimport { pathExists, readJson, emptyDir, outputJson, unlink, pathExistsSync } from \"fs-extra\"\nimport * as path from \"path\"\n\n/** @private **/\nexport class DownloadedUpdateHelper {\n private _file: string | null = null\n private _packageFile: string | null = null\n\n private versionInfo: UpdateInfo | null = null\n private fileInfo: ResolvedUpdateFileInfo | null = null\n\n constructor(readonly cacheDir: string) {\n }\n\n private _downloadedFileInfo: CachedUpdateInfo | null = null\n get downloadedFileInfo(): CachedUpdateInfo | null {\n return this._downloadedFileInfo\n }\n\n get file(): string | null {\n return this._file\n }\n\n get packageFile(): string | null {\n return this._packageFile\n }\n\n get cacheDirForPendingUpdate(): string {\n return path.join(this.cacheDir, \"pending\")\n }\n\n async validateDownloadedPath(updateFile: string, updateInfo: UpdateInfo, fileInfo: ResolvedUpdateFileInfo, logger: Logger): Promise<string | null> {\n if (this.versionInfo != null && this.file === updateFile && this.fileInfo != null) {\n // update has already been downloaded from this running instance\n // check here only existence, not checksum\n if (isEqual(this.versionInfo, updateInfo) && isEqual(this.fileInfo.info, fileInfo.info) && (await pathExists(updateFile))) {\n return updateFile\n }\n else {\n return null\n }\n }\n\n // update has already been downloaded from some previous app launch\n const cachedUpdateFile = await this.getValidCachedUpdateFile(fileInfo, logger)\n if (cachedUpdateFile === null) {\n return null\n }\n logger.info(`Update has already been downloaded to ${updateFile}).`)\n this._file = cachedUpdateFile\n return cachedUpdateFile\n }\n\n async setDownloadedFile(downloadedFile: string, packageFile: string | null, versionInfo: UpdateInfo, fileInfo: ResolvedUpdateFileInfo, updateFileName: string, isSaveCache: boolean): Promise<void> {\n this._file = downloadedFile\n this._packageFile = packageFile\n this.versionInfo = versionInfo\n this.fileInfo = fileInfo\n this._downloadedFileInfo = {\n fileName: updateFileName,\n sha512: fileInfo.info.sha512,\n isAdminRightsRequired: fileInfo.info.isAdminRightsRequired === true,\n }\n\n if (isSaveCache) {\n await outputJson(this.getUpdateInfoFile(), this._downloadedFileInfo)\n }\n }\n\n async clear(): Promise<void> {\n this._file = null\n this._packageFile = null\n this.versionInfo = null\n this.fileInfo = null\n await this.cleanCacheDirForPendingUpdate()\n }\n\n private async cleanCacheDirForPendingUpdate(): Promise<void> {\n try {\n // remove stale data\n await emptyDir(this.cacheDirForPendingUpdate)\n }\n catch (ignore) {\n // ignore\n }\n }\n\n /**\n * Returns \"update-info.json\" which is created in the update cache directory's \"pending\" subfolder after the first update is downloaded. If the update file does not exist then the cache is cleared and recreated. If the update file exists then its properties are validated.\n * @param fileInfo\n * @param logger\n */\n private async getValidCachedUpdateFile(fileInfo: ResolvedUpdateFileInfo, logger: Logger): Promise<string | null> {\n const updateInfoFilePath: string = this.getUpdateInfoFile()\n\n const doesUpdateInfoFileExist = await pathExistsSync(updateInfoFilePath);\n if(!doesUpdateInfoFileExist) {\n return null;\n }\n\n\n let cachedInfo: CachedUpdateInfo\n try {\n cachedInfo = await readJson(updateInfoFilePath)\n }\n catch (error) {\n let message = `No cached update info available`\n if (error.code !== \"ENOENT\") {\n await this.cleanCacheDirForPendingUpdate()\n message += ` (error on read: ${error.message})`\n }\n logger.info(message)\n return null\n }\n\n const isCachedInfoFileNameValid = cachedInfo?.fileName !== null ?? false\n if (!isCachedInfoFileNameValid) {\n logger.warn(`Cached update info is corrupted: no fileName, directory for cached update will be cleaned`)\n await this.cleanCacheDirForPendingUpdate()\n return null\n }\n\n if (fileInfo.info.sha512 !== cachedInfo.sha512) {\n logger.info(`Cached update sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: ${cachedInfo.sha512}, expected: ${fileInfo.info.sha512}. Directory for cached update will be cleaned`)\n await this.cleanCacheDirForPendingUpdate()\n return null\n }\n\n const updateFile = path.join(this.cacheDirForPendingUpdate, cachedInfo.fileName)\n if (!(await pathExists(updateFile))) {\n logger.info(\"Cached update file doesn't exist, directory for cached update will be cleaned\")\n await this.cleanCacheDirForPendingUpdate()\n return null\n }\n\n const sha512 = await hashFile(updateFile)\n if (fileInfo.info.sha512 !== sha512) {\n logger.warn(`Sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: ${sha512}, expected: ${fileInfo.info.sha512}`)\n await this.cleanCacheDirForPendingUpdate()\n return null\n }\n this._downloadedFileInfo = cachedInfo\n return updateFile\n }\n\n private getUpdateInfoFile(): string {\n return path.join(this.cacheDirForPendingUpdate, \"update-info.json\")\n }\n}\n\ninterface CachedUpdateInfo {\n fileName: string\n sha512: string\n readonly isAdminRightsRequired: boolean\n}\n\nfunction hashFile(file: string, algorithm = \"sha512\", encoding: \"base64\" | \"hex\" = \"base64\", options?: any): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n const hash = createHash(algorithm)\n hash\n .on(\"error\", reject)\n .setEncoding(encoding)\n\n createReadStream(file, {...options, highWaterMark: 1024 * 1024 /* better to use more memory but hash faster */})\n .on(\"error\", reject)\n .on(\"end\", () => {\n hash.end()\n resolve(hash.read() as string)\n })\n .pipe(hash, {end: false})\n })\n}\n\nexport async function createTempUpdateFile(name: string, cacheDir: string, log: Logger): Promise<string> {\n // https://github.com/electron-userland/electron-builder/pull/2474#issuecomment-366481912\n let nameCounter = 0\n let result = path.join(cacheDir, name)\n for (let i = 0; i < 3; i++) {\n try {\n await unlink(result)\n return result\n }\n catch (e) {\n if (e.code === \"ENOENT\") {\n return result\n }\n\n log.warn(`Error on remove temp update file: ${e}`)\n result = path.join(cacheDir, `${nameCounter++}-${name}`)\n }\n }\n return result\n}\n"],"sourceRoot":""}
1
+ {"version":3,"file":"DownloadedUpdateHelper.js","sourceRoot":"","sources":["../src/DownloadedUpdateHelper.ts"],"names":[],"mappings":";;;AACA,mCAAmC;AACnC,2BAAqC;AACrC,aAAa;AACb,0CAAyC;AAEzC,uCAA6E;AAC7E,6B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AC,IAAI,CAAC,IAAI,EAAY,CAAC,CAAA;QAChC,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACJ,CAAC;AAEM,KAAK,UAAU,oBAAoB,CAAC,IAAY,EAAE,QAAgB,EAAE,GAAW;IACpF,yFAAyF;IACzF,IAAI,WAAW,GAAG,CAAC,CAAA;IACnB,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QAC1B,IAAI;YACF,MAAM,iBAAM,CAAC,MAAM,CAAC,CAAA;YACpB,OAAO,MAAM,CAAA;SACd;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE;gBACvB,OAAO,MAAM,CAAA;aACd;YAED,GAAG,CAAC,IAAI,CAAC,qCAAqC,CAAC,EAAE,CAAC,CAAA;YAClD,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;SACzD;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAlBD,oDAkBC","sourcesContent":["import { UpdateInfo } from \"builder-util-runtime\"\nimport { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\n// @ts-ignore\nimport * as isEqual from \"lodash.isequal\"\nimport { Logger, ResolvedUpdateFileInfo } from \"./main\"\nimport { pathExists, readJson, emptyDir, outputJson, unlink } from \"fs-extra\"\nimport * as path from \"path\"\n\n/** @private **/\nexport class DownloadedUpdateHelper {\n private _file: string | null = null\n private _packageFile: string | null = null\n\n private versionInfo: UpdateInfo | null = null\n private fileInfo: ResolvedUpdateFileInfo | null = null\n\n constructor(readonly cacheDir: string) {}\n\n private _downloadedFileInfo: CachedUpdateInfo | null = null\n get downloadedFileInfo(): CachedUpdateInfo | null {\n return this._downloadedFileInfo\n }\n\n get file(): string | null {\n return this._file\n }\n\n get packageFile(): string | null {\n return this._packageFile\n }\n\n get cacheDirForPendingUpdate(): string {\n return path.join(this.cacheDir, \"pending\")\n }\n\n async validateDownloadedPath(updateFile: string, updateInfo: UpdateInfo, fileInfo: ResolvedUpdateFileInfo, logger: Logger): Promise<string | null> {\n if (this.versionInfo != null && this.file === updateFile && this.fileInfo != null) {\n // update has already been downloaded from this running instance\n // check here only existence, not checksum\n if (isEqual(this.versionInfo, updateInfo) && isEqual(this.fileInfo.info, fileInfo.info) && (await pathExists(updateFile))) {\n return updateFile\n } else {\n return null\n }\n }\n\n // update has already been downloaded from some previous app launch\n const cachedUpdateFile = await this.getValidCachedUpdateFile(fileInfo, logger)\n if (cachedUpdateFile === null) {\n return null\n }\n logger.info(`Update has already been downloaded to ${updateFile}).`)\n this._file = cachedUpdateFile\n return cachedUpdateFile\n }\n\n async setDownloadedFile(\n downloadedFile: string,\n packageFile: string | null,\n versionInfo: UpdateInfo,\n fileInfo: ResolvedUpdateFileInfo,\n updateFileName: string,\n isSaveCache: boolean\n ): Promise<void> {\n this._file = downloadedFile\n this._packageFile = packageFile\n this.versionInfo = versionInfo\n this.fileInfo = fileInfo\n this._downloadedFileInfo = {\n fileName: updateFileName,\n sha512: fileInfo.info.sha512,\n isAdminRightsRequired: fileInfo.info.isAdminRightsRequired === true,\n }\n\n if (isSaveCache) {\n await outputJson(this.getUpdateInfoFile(), this._downloadedFileInfo)\n }\n }\n\n async clear(): Promise<void> {\n this._file = null\n this._packageFile = null\n this.versionInfo = null\n this.fileInfo = null\n await this.cleanCacheDirForPendingUpdate()\n }\n\n private async cleanCacheDirForPendingUpdate(): Promise<void> {\n try {\n // remove stale data\n await emptyDir(this.cacheDirForPendingUpdate)\n } catch (ignore) {\n // ignore\n }\n }\n\n /**\n * Returns \"update-info.json\" which is created in the update cache directory's \"pending\" subfolder after the first update is downloaded. If the update file does not exist then the cache is cleared and recreated. If the update file exists then its properties are validated.\n * @param fileInfo\n * @param logger\n */\n private async getValidCachedUpdateFile(fileInfo: ResolvedUpdateFileInfo, logger: Logger): Promise<string | null> {\n const updateInfoFilePath: string = this.getUpdateInfoFile()\n\n const doesUpdateInfoFileExist = await pathExists(updateInfoFilePath)\n if (!doesUpdateInfoFileExist) {\n return null\n }\n\n let cachedInfo: CachedUpdateInfo\n try {\n cachedInfo = await readJson(updateInfoFilePath)\n } catch (error) {\n let message = `No cached update info available`\n if (error.code !== \"ENOENT\") {\n await this.cleanCacheDirForPendingUpdate()\n message += ` (error on read: ${error.message})`\n }\n logger.info(message)\n return null\n }\n\n const isCachedInfoFileNameValid = cachedInfo?.fileName !== null ?? false\n if (!isCachedInfoFileNameValid) {\n logger.warn(`Cached update info is corrupted: no fileName, directory for cached update will be cleaned`)\n await this.cleanCacheDirForPendingUpdate()\n return null\n }\n\n if (fileInfo.info.sha512 !== cachedInfo.sha512) {\n logger.info(\n `Cached update sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: ${cachedInfo.sha512}, expected: ${fileInfo.info.sha512}. Directory for cached update will be cleaned`\n )\n await this.cleanCacheDirForPendingUpdate()\n return null\n }\n\n const updateFile = path.join(this.cacheDirForPendingUpdate, cachedInfo.fileName)\n if (!(await pathExists(updateFile))) {\n logger.info(\"Cached update file doesn't exist\")\n return null\n }\n\n const sha512 = await hashFile(updateFile)\n if (fileInfo.info.sha512 !== sha512) {\n logger.warn(`Sha512 checksum doesn't match the latest available update. New update must be downloaded. Cached: ${sha512}, expected: ${fileInfo.info.sha512}`)\n await this.cleanCacheDirForPendingUpdate()\n return null\n }\n this._downloadedFileInfo = cachedInfo\n return updateFile\n }\n\n private getUpdateInfoFile(): string {\n return path.join(this.cacheDirForPendingUpdate, \"update-info.json\")\n }\n}\n\ninterface CachedUpdateInfo {\n fileName: string\n sha512: string\n readonly isAdminRightsRequired: boolean\n}\n\nfunction hashFile(file: string, algorithm = \"sha512\", encoding: \"base64\" | \"hex\" = \"base64\", options?: any): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n const hash = createHash(algorithm)\n hash.on(\"error\", reject).setEncoding(encoding)\n\n createReadStream(file, { ...options, highWaterMark: 1024 * 1024 /* better to use more memory but hash faster */ })\n .on(\"error\", reject)\n .on(\"end\", () => {\n hash.end()\n resolve(hash.read() as string)\n })\n .pipe(hash, { end: false })\n })\n}\n\nexport async function createTempUpdateFile(name: string, cacheDir: string, log: Logger): Promise<string> {\n // https://github.com/electron-userland/electron-builder/pull/2474#issuecomment-366481912\n let nameCounter = 0\n let result = path.join(cacheDir, name)\n for (let i = 0; i < 3; i++) {\n try {\n await unlink(result)\n return result\n } catch (e) {\n if (e.code === \"ENOENT\") {\n return result\n }\n\n log.warn(`Error on remove temp update file: ${e}`)\n result = path.join(cacheDir, `${nameCounter++}-${name}`)\n }\n }\n return result\n}\n"]}
@@ -1,67 +1,39 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ElectronAppAdapter = void 0;
7
-
8
- var path = _interopRequireWildcard(require("path"));
9
-
10
- function _AppAdapter() {
11
- const data = require("./AppAdapter");
12
-
13
- _AppAdapter = function () {
14
- return data;
15
- };
16
-
17
- return data;
18
- }
19
-
20
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
21
-
22
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
-
4
+ const path = require("path");
5
+ const AppAdapter_1 = require("./AppAdapter");
24
6
  class ElectronAppAdapter {
25
- constructor(app = require("electron").app) {
26
- this.app = app;
27
- }
28
-
29
- whenReady() {
30
- return this.app.whenReady();
31
- }
32
-
33
- get version() {
34
- return this.app.getVersion();
35
- }
36
-
37
- get name() {
38
- return this.app.getName();
39
- }
40
-
41
- get isPackaged() {
42
- return this.app.isPackaged === true;
43
- }
44
-
45
- get appUpdateConfigPath() {
46
- return this.isPackaged ? path.join(process.resourcesPath, "app-update.yml") : path.join(this.app.getAppPath(), "dev-app-update.yml");
47
- }
48
-
49
- get userDataPath() {
50
- return this.app.getPath("userData");
51
- }
52
-
53
- get baseCachePath() {
54
- return (0, _AppAdapter().getAppCacheDir)();
55
- }
56
-
57
- quit() {
58
- this.app.quit();
59
- }
60
-
61
- onQuit(handler) {
62
- this.app.once("quit", (_, exitCode) => handler(exitCode));
63
- }
64
-
65
- } exports.ElectronAppAdapter = ElectronAppAdapter;
66
- // __ts-babel@6.0.4
7
+ constructor(app = require("electron").app) {
8
+ this.app = app;
9
+ }
10
+ whenReady() {
11
+ return this.app.whenReady();
12
+ }
13
+ get version() {
14
+ return this.app.getVersion();
15
+ }
16
+ get name() {
17
+ return this.app.getName();
18
+ }
19
+ get isPackaged() {
20
+ return this.app.isPackaged === true;
21
+ }
22
+ get appUpdateConfigPath() {
23
+ return this.isPackaged ? path.join(process.resourcesPath, "app-update.yml") : path.join(this.app.getAppPath(), "dev-app-update.yml");
24
+ }
25
+ get userDataPath() {
26
+ return this.app.getPath("userData");
27
+ }
28
+ get baseCachePath() {
29
+ return AppAdapter_1.getAppCacheDir();
30
+ }
31
+ quit() {
32
+ this.app.quit();
33
+ }
34
+ onQuit(handler) {
35
+ this.app.once("quit", (_, exitCode) => handler(exitCode));
36
+ }
37
+ }
38
+ exports.ElectronAppAdapter = ElectronAppAdapter;
67
39
  //# sourceMappingURL=ElectronAppAdapter.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ElectronAppAdapter.ts"],"names":[],"mappings":";;;;;;;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEM,MAAO,kBAAP,CAAyB;AAC7B,EAAA,WAAA,CAA6B,GAAA,GAAM,OAAO,CAAC,UAAD,CAAP,CAAoB,GAAvD,EAA0D;AAA7B,SAAA,GAAA,GAAA,GAAA;AAC5B;;AAED,EAAA,SAAS,GAAA;AACP,WAAO,KAAK,GAAL,CAAS,SAAT,EAAP;AACD;;AAED,MAAI,OAAJ,GAAW;AACT,WAAO,KAAK,GAAL,CAAS,UAAT,EAAP;AACD;;AAED,MAAI,IAAJ,GAAQ;AACN,WAAO,KAAK,GAAL,CAAS,OAAT,EAAP;AACD;;AAED,MAAI,UAAJ,GAAc;AACZ,WAAO,KAAK,GAAL,CAAS,UAAT,KAAwB,IAA/B;AACD;;AAED,MAAI,mBAAJ,GAAuB;AACrB,WAAO,KAAK,UAAL,GAAkB,IAAI,CAAC,IAAL,CAAU,OAAO,CAAC,aAAlB,EAAmC,gBAAnC,CAAlB,GAAyE,IAAI,CAAC,IAAL,CAAU,KAAK,GAAL,CAAS,UAAT,EAAV,EAAiC,oBAAjC,CAAhF;AACD;;AAED,MAAI,YAAJ,GAAgB;AACd,WAAO,KAAK,GAAL,CAAS,OAAT,CAAiB,UAAjB,CAAP;AACD;;AAED,MAAI,aAAJ,GAAiB;AACf,WAAO,mCAAP;AACD;;AAED,EAAA,IAAI,GAAA;AACF,SAAK,GAAL,CAAS,IAAT;AACD;;AAED,EAAA,MAAM,CAAC,OAAD,EAAoC;AACxC,SAAK,GAAL,CAAS,IAAT,CAAc,MAAd,EAAsB,CAAC,CAAD,EAAW,QAAX,KAAgC,OAAO,CAAC,QAAD,CAA7D;AACD;;AAtC4B,C","sourcesContent":["import * as path from \"path\"\nimport { AppAdapter, getAppCacheDir } from \"./AppAdapter\"\n\nexport class ElectronAppAdapter implements AppAdapter {\n constructor(private readonly app = require(\"electron\").app) {\n }\n\n whenReady(): Promise<void> {\n return this.app.whenReady()\n }\n\n get version(): string {\n return this.app.getVersion()\n }\n\n get name(): string {\n return this.app.getName()\n }\n\n get isPackaged(): boolean {\n return this.app.isPackaged === true\n }\n\n get appUpdateConfigPath(): string {\n return this.isPackaged ? path.join(process.resourcesPath!!, \"app-update.yml\") : path.join(this.app.getAppPath(), \"dev-app-update.yml\")\n }\n\n get userDataPath(): string {\n return this.app.getPath(\"userData\")\n }\n\n get baseCachePath(): string {\n return getAppCacheDir()\n }\n\n quit(): void {\n this.app.quit()\n }\n\n onQuit(handler: (exitCode: number) => void): void {\n this.app.once(\"quit\", (_: Event, exitCode: number) => handler(exitCode))\n }\n}"],"sourceRoot":""}
1
+ {"version":3,"file":"ElectronAppAdapter.js","sourceRoot":"","sources":["../src/ElectronAppAdapter.ts"],"names":[],"mappings":";;;AAAA,6BAA4B;AAC5B,6CAAyD;AAEzD,MAAa,kBAAkB;IAC7B,YAA6B,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG;QAA7B,QAAG,GAAH,GAAG,CAA0B;IAAG,CAAC;IAE9D,SAAS;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAA;IAC7B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAA;IAC9B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAA;IAC3B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,KAAK,IAAI,CAAA;IACrC,CAAC;IAED,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAc,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,oBAAoB,CAAC,CAAA;IACvI,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IAED,IAAI,aAAa;QACf,OAAO,2BAAc,EAAE,CAAA;IACzB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;IACjB,CAAC;IAED,MAAM,CAAC,OAAmC;QACxC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAQ,EAAE,QAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC1E,CAAC;CACF;AAtCD,gDAsCC","sourcesContent":["import * as path from \"path\"\nimport { AppAdapter, getAppCacheDir } from \"./AppAdapter\"\n\nexport class ElectronAppAdapter implements AppAdapter {\n constructor(private readonly app = require(\"electron\").app) {}\n\n whenReady(): Promise<void> {\n return this.app.whenReady()\n }\n\n get version(): string {\n return this.app.getVersion()\n }\n\n get name(): string {\n return this.app.getName()\n }\n\n get isPackaged(): boolean {\n return this.app.isPackaged === true\n }\n\n get appUpdateConfigPath(): string {\n return this.isPackaged ? path.join(process.resourcesPath!, \"app-update.yml\") : path.join(this.app.getAppPath(), \"dev-app-update.yml\")\n }\n\n get userDataPath(): string {\n return this.app.getPath(\"userData\")\n }\n\n get baseCachePath(): string {\n return getAppCacheDir()\n }\n\n quit(): void {\n this.app.quit()\n }\n\n onQuit(handler: (exitCode: number) => void): void {\n this.app.once(\"quit\", (_: Event, exitCode: number) => handler(exitCode))\n }\n}\n"]}
@@ -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;