1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.NoOpLogger = exports.AppUpdater = void 0;
|
7 |
|
8 | function _builderUtilRuntime() {
|
9 | const data = require("builder-util-runtime");
|
10 |
|
11 | _builderUtilRuntime = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _crypto() {
|
19 | const data = require("crypto");
|
20 |
|
21 | _crypto = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _electron() {
|
29 | const data = require("electron");
|
30 |
|
31 | _electron = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _events() {
|
39 | const data = require("events");
|
40 |
|
41 | _events = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | function _fsExtra() {
|
49 | const data = require("fs-extra");
|
50 |
|
51 | _fsExtra = function () {
|
52 | return data;
|
53 | };
|
54 |
|
55 | return data;
|
56 | }
|
57 |
|
58 | function _jsYaml() {
|
59 | const data = require("js-yaml");
|
60 |
|
61 | _jsYaml = function () {
|
62 | return data;
|
63 | };
|
64 |
|
65 | return data;
|
66 | }
|
67 |
|
68 | function _lazyVal() {
|
69 | const data = require("lazy-val");
|
70 |
|
71 | _lazyVal = function () {
|
72 | return data;
|
73 | };
|
74 |
|
75 | return data;
|
76 | }
|
77 |
|
78 | var path = _interopRequireWildcard(require("path"));
|
79 |
|
80 | function _semver() {
|
81 | const data = require("semver");
|
82 |
|
83 | _semver = function () {
|
84 | return data;
|
85 | };
|
86 |
|
87 | return data;
|
88 | }
|
89 |
|
90 | function _DownloadedUpdateHelper() {
|
91 | const data = require("./DownloadedUpdateHelper");
|
92 |
|
93 | _DownloadedUpdateHelper = function () {
|
94 | return data;
|
95 | };
|
96 |
|
97 | return data;
|
98 | }
|
99 |
|
100 | function _ElectronAppAdapter() {
|
101 | const data = require("./ElectronAppAdapter");
|
102 |
|
103 | _ElectronAppAdapter = function () {
|
104 | return data;
|
105 | };
|
106 |
|
107 | return data;
|
108 | }
|
109 |
|
110 | function _electronHttpExecutor() {
|
111 | const data = require("./electronHttpExecutor");
|
112 |
|
113 | _electronHttpExecutor = function () {
|
114 | return data;
|
115 | };
|
116 |
|
117 | return data;
|
118 | }
|
119 |
|
120 | function _GenericProvider() {
|
121 | const data = require("./providers/GenericProvider");
|
122 |
|
123 | _GenericProvider = function () {
|
124 | return data;
|
125 | };
|
126 |
|
127 | return data;
|
128 | }
|
129 |
|
130 | function _main() {
|
131 | const data = require("./main");
|
132 |
|
133 | _main = function () {
|
134 | return data;
|
135 | };
|
136 |
|
137 | return data;
|
138 | }
|
139 |
|
140 | function _providerFactory() {
|
141 | const data = require("./providerFactory");
|
142 |
|
143 | _providerFactory = function () {
|
144 | return data;
|
145 | };
|
146 |
|
147 | return data;
|
148 | }
|
149 |
|
150 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
151 |
|
152 | 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; }
|
153 |
|
154 | class AppUpdater extends _events().EventEmitter {
|
155 | constructor(options, app) {
|
156 | super();
|
157 | |
158 |
|
159 |
|
160 |
|
161 | this.autoDownload = true;
|
162 | |
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | this.autoInstallOnAppQuit = true;
|
169 | |
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | this.allowPrerelease = false;
|
176 | |
177 |
|
178 |
|
179 |
|
180 |
|
181 | this.fullChangelog = false;
|
182 | |
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | this.allowDowngrade = false;
|
191 | this._channel = null;
|
192 | this.downloadedUpdateHelper = null;
|
193 | |
194 |
|
195 |
|
196 |
|
197 | this.requestHeaders = null;
|
198 | this._logger = console;
|
199 |
|
200 | |
201 |
|
202 |
|
203 |
|
204 | this.signals = new (_main().UpdaterSignal)(this);
|
205 | this._appUpdateConfigPath = null;
|
206 | this.clientPromise = null;
|
207 | this.stagingUserIdPromise = new (_lazyVal().Lazy)(() => this.getOrCreateStagingUserId());
|
208 |
|
209 |
|
210 |
|
211 | this.configOnDisk = new (_lazyVal().Lazy)(() => this.loadUpdateConfig());
|
212 | this.checkForUpdatesPromise = null;
|
213 | this.updateInfoAndProvider = null;
|
214 | |
215 |
|
216 |
|
217 |
|
218 |
|
219 | this._testOnlyOptions = null;
|
220 | this.on("error", error => {
|
221 | this._logger.error(`Error: ${error.stack || error.message}`);
|
222 | });
|
223 |
|
224 | if (app == null) {
|
225 | this.app = new (_ElectronAppAdapter().ElectronAppAdapter)();
|
226 | this.httpExecutor = new (_electronHttpExecutor().ElectronHttpExecutor)((authInfo, callback) => this.emit("login", authInfo, callback));
|
227 | } else {
|
228 | this.app = app;
|
229 | this.httpExecutor = null;
|
230 | }
|
231 |
|
232 | const currentVersionString = this.app.version;
|
233 | const currentVersion = (0, _semver().parse)(currentVersionString);
|
234 |
|
235 | if (currentVersion == null) {
|
236 | throw (0, _builderUtilRuntime().newError)(`App version is not a valid semver version: "${currentVersionString}"`, "ERR_UPDATER_INVALID_VERSION");
|
237 | }
|
238 |
|
239 | this.currentVersion = currentVersion;
|
240 | this.allowPrerelease = hasPrereleaseComponents(currentVersion);
|
241 |
|
242 | if (options != null) {
|
243 | this.setFeedURL(options);
|
244 |
|
245 | if (typeof options !== "string" && options.requestHeaders) {
|
246 | this.requestHeaders = options.requestHeaders;
|
247 | }
|
248 | }
|
249 | }
|
250 | |
251 |
|
252 |
|
253 |
|
254 |
|
255 | get channel() {
|
256 | return this._channel;
|
257 | }
|
258 | |
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | set channel(value) {
|
266 | if (this._channel != null) {
|
267 |
|
268 | if (typeof value !== "string") {
|
269 | throw (0, _builderUtilRuntime().newError)(`Channel must be a string, but got: ${value}`, "ERR_UPDATER_INVALID_CHANNEL");
|
270 | } else if (value.length === 0) {
|
271 | throw (0, _builderUtilRuntime().newError)(`Channel must be not an empty string`, "ERR_UPDATER_INVALID_CHANNEL");
|
272 | }
|
273 | }
|
274 |
|
275 | this._channel = value;
|
276 | this.allowDowngrade = true;
|
277 | }
|
278 |
|
279 |
|
280 | get netSession() {
|
281 | return (0, _electronHttpExecutor().getNetSession)();
|
282 | }
|
283 | |
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 | get logger() {
|
290 | return this._logger;
|
291 | }
|
292 |
|
293 | set logger(value) {
|
294 | this._logger = value == null ? new NoOpLogger() : value;
|
295 | }
|
296 |
|
297 | |
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | set updateConfigPath(value) {
|
304 | this.clientPromise = null;
|
305 | this._appUpdateConfigPath = value;
|
306 | this.configOnDisk = new (_lazyVal().Lazy)(() => this.loadUpdateConfig());
|
307 | }
|
308 |
|
309 |
|
310 | getFeedURL() {
|
311 | return "Deprecated. Do not use it.";
|
312 | }
|
313 | |
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 | setFeedURL(options) {
|
320 | const runtimeOptions = this.createProviderRuntimeOptions();
|
321 |
|
322 | let provider;
|
323 |
|
324 | if (typeof options === "string") {
|
325 | provider = new (_GenericProvider().GenericProvider)({
|
326 | provider: "generic",
|
327 | url: options
|
328 | }, this, { ...runtimeOptions,
|
329 | isUseMultipleRangeRequest: (0, _providerFactory().isUrlProbablySupportMultiRangeRequests)(options)
|
330 | });
|
331 | } else {
|
332 | provider = (0, _providerFactory().createClient)(options, this, runtimeOptions);
|
333 | }
|
334 |
|
335 | this.clientPromise = Promise.resolve(provider);
|
336 | }
|
337 | |
338 |
|
339 |
|
340 |
|
341 |
|
342 | checkForUpdates() {
|
343 | let checkForUpdatesPromise = this.checkForUpdatesPromise;
|
344 |
|
345 | if (checkForUpdatesPromise != null) {
|
346 | this._logger.info("Checking for update (already in progress)");
|
347 |
|
348 | return checkForUpdatesPromise;
|
349 | }
|
350 |
|
351 | const nullizePromise = () => this.checkForUpdatesPromise = null;
|
352 |
|
353 | this._logger.info("Checking for update");
|
354 |
|
355 | checkForUpdatesPromise = this.doCheckForUpdates().then(it => {
|
356 | nullizePromise();
|
357 | return it;
|
358 | }).catch(e => {
|
359 | nullizePromise();
|
360 | this.emit("error", e, `Cannot check for updates: ${(e.stack || e).toString()}`);
|
361 | throw e;
|
362 | });
|
363 | this.checkForUpdatesPromise = checkForUpdatesPromise;
|
364 | return checkForUpdatesPromise;
|
365 | }
|
366 |
|
367 | isUpdaterActive() {
|
368 | if (!this.app.isPackaged) {
|
369 | this._logger.info("Skip checkForUpdatesAndNotify because application is not packed");
|
370 |
|
371 | return false;
|
372 | }
|
373 |
|
374 | return true;
|
375 | }
|
376 |
|
377 |
|
378 | checkForUpdatesAndNotify() {
|
379 | if (!this.isUpdaterActive()) {
|
380 | return Promise.resolve(null);
|
381 | }
|
382 |
|
383 | return this.checkForUpdates().then(it => {
|
384 | const downloadPromise = it.downloadPromise;
|
385 |
|
386 | if (downloadPromise == null) {
|
387 | const debug = this._logger.debug;
|
388 |
|
389 | if (debug != null) {
|
390 | debug("checkForUpdatesAndNotify called, downloadPromise is null");
|
391 | }
|
392 |
|
393 | return it;
|
394 | }
|
395 |
|
396 | downloadPromise.then(() => {
|
397 | new (_electron().Notification)({
|
398 | title: "A new update is ready to install",
|
399 | body: `${this.app.name} version ${it.updateInfo.version} has been downloaded and will be automatically installed on exit`
|
400 | }).show();
|
401 | });
|
402 | return it;
|
403 | });
|
404 | }
|
405 |
|
406 | async isStagingMatch(updateInfo) {
|
407 | const rawStagingPercentage = updateInfo.stagingPercentage;
|
408 | let stagingPercentage = rawStagingPercentage;
|
409 |
|
410 | if (stagingPercentage == null) {
|
411 | return true;
|
412 | }
|
413 |
|
414 | stagingPercentage = parseInt(stagingPercentage, 10);
|
415 |
|
416 | if (isNaN(stagingPercentage)) {
|
417 | this._logger.warn(`Staging percentage is NaN: ${rawStagingPercentage}`);
|
418 |
|
419 | return true;
|
420 | }
|
421 |
|
422 |
|
423 | stagingPercentage = stagingPercentage / 100;
|
424 | const stagingUserId = await this.stagingUserIdPromise.value;
|
425 |
|
426 | const val = _builderUtilRuntime().UUID.parse(stagingUserId).readUInt32BE(12);
|
427 |
|
428 | const percentage = val / 0xFFFFFFFF;
|
429 |
|
430 | this._logger.info(`Staging percentage: ${stagingPercentage}, percentage: ${percentage}, user id: ${stagingUserId}`);
|
431 |
|
432 | return percentage < stagingPercentage;
|
433 | }
|
434 |
|
435 | computeFinalHeaders(headers) {
|
436 | if (this.requestHeaders != null) {
|
437 | Object.assign(headers, this.requestHeaders);
|
438 | }
|
439 |
|
440 | return headers;
|
441 | }
|
442 |
|
443 | async isUpdateAvailable(updateInfo) {
|
444 | const latestVersion = (0, _semver().parse)(updateInfo.version);
|
445 |
|
446 | if (latestVersion == null) {
|
447 | throw (0, _builderUtilRuntime().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");
|
448 | }
|
449 |
|
450 | const currentVersion = this.currentVersion;
|
451 |
|
452 | if ((0, _semver().eq)(latestVersion, currentVersion)) {
|
453 | return false;
|
454 | }
|
455 |
|
456 | const isStagingMatch = await this.isStagingMatch(updateInfo);
|
457 |
|
458 | if (!isStagingMatch) {
|
459 | return false;
|
460 | }
|
461 |
|
462 |
|
463 |
|
464 | const isLatestVersionNewer = (0, _semver().gt)(latestVersion, currentVersion);
|
465 | const isLatestVersionOlder = (0, _semver().lt)(latestVersion, currentVersion);
|
466 |
|
467 | if (isLatestVersionNewer) {
|
468 | return true;
|
469 | }
|
470 |
|
471 | return this.allowDowngrade && isLatestVersionOlder;
|
472 | }
|
473 |
|
474 | async getUpdateInfoAndProvider() {
|
475 | await this.app.whenReady();
|
476 |
|
477 | if (this.clientPromise == null) {
|
478 | this.clientPromise = this.configOnDisk.value.then(it => (0, _providerFactory().createClient)(it, this, this.createProviderRuntimeOptions()));
|
479 | }
|
480 |
|
481 | const client = await this.clientPromise;
|
482 | const stagingUserId = await this.stagingUserIdPromise.value;
|
483 | client.setRequestHeaders(this.computeFinalHeaders({
|
484 | "x-user-staging-id": stagingUserId
|
485 | }));
|
486 | return {
|
487 | info: await client.getLatestVersion(),
|
488 | provider: client
|
489 | };
|
490 | }
|
491 |
|
492 |
|
493 | createProviderRuntimeOptions() {
|
494 | return {
|
495 | isUseMultipleRangeRequest: true,
|
496 | platform: this._testOnlyOptions == null ? process.platform : this._testOnlyOptions.platform,
|
497 | executor: this.httpExecutor
|
498 | };
|
499 | }
|
500 |
|
501 | async doCheckForUpdates() {
|
502 | this.emit("checking-for-update");
|
503 | const result = await this.getUpdateInfoAndProvider();
|
504 | const updateInfo = result.info;
|
505 |
|
506 | if (!(await this.isUpdateAvailable(updateInfo))) {
|
507 | this._logger.info(`Update for version ${this.currentVersion} is not available (latest version: ${updateInfo.version}, downgrade is ${this.allowDowngrade ? "allowed" : "disallowed"}).`);
|
508 |
|
509 | this.emit("update-not-available", updateInfo);
|
510 | return {
|
511 | versionInfo: updateInfo,
|
512 | updateInfo
|
513 | };
|
514 | }
|
515 |
|
516 | this.updateInfoAndProvider = result;
|
517 | this.onUpdateAvailable(updateInfo);
|
518 | const cancellationToken = new (_builderUtilRuntime().CancellationToken)();
|
519 |
|
520 | return {
|
521 | versionInfo: updateInfo,
|
522 | updateInfo,
|
523 | cancellationToken,
|
524 | downloadPromise: this.autoDownload ? this.downloadUpdate(cancellationToken) : null
|
525 | };
|
526 | }
|
527 |
|
528 | onUpdateAvailable(updateInfo) {
|
529 | this._logger.info(`Found version ${updateInfo.version} (url: ${(0, _builderUtilRuntime().asArray)(updateInfo.files).map(it => it.url).join(", ")})`);
|
530 |
|
531 | this.emit("update-available", updateInfo);
|
532 | }
|
533 | |
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 | downloadUpdate(cancellationToken = new (_builderUtilRuntime().CancellationToken)()) {
|
540 | const updateInfoAndProvider = this.updateInfoAndProvider;
|
541 |
|
542 | if (updateInfoAndProvider == null) {
|
543 | const error = new Error("Please check update first");
|
544 | this.dispatchError(error);
|
545 | return Promise.reject(error);
|
546 | }
|
547 |
|
548 | this._logger.info(`Downloading update from ${(0, _builderUtilRuntime().asArray)(updateInfoAndProvider.info.files).map(it => it.url).join(", ")}`);
|
549 |
|
550 | const errorHandler = e => {
|
551 |
|
552 | if (!(e instanceof _builderUtilRuntime().CancellationError)) {
|
553 | try {
|
554 | this.dispatchError(e);
|
555 | } catch (nestedError) {
|
556 | this._logger.warn(`Cannot dispatch error event: ${nestedError.stack || nestedError}`);
|
557 | }
|
558 | }
|
559 |
|
560 | return e;
|
561 | };
|
562 |
|
563 | try {
|
564 | return this.doDownloadUpdate({
|
565 | updateInfoAndProvider,
|
566 | requestHeaders: this.computeRequestHeaders(updateInfoAndProvider.provider),
|
567 | cancellationToken
|
568 | }).catch(e => {
|
569 | throw errorHandler(e);
|
570 | });
|
571 | } catch (e) {
|
572 | return Promise.reject(errorHandler(e));
|
573 | }
|
574 | }
|
575 |
|
576 | dispatchError(e) {
|
577 | this.emit("error", e, (e.stack || e).toString());
|
578 | }
|
579 |
|
580 | dispatchUpdateDownloaded(event) {
|
581 | this.emit(_main().UPDATE_DOWNLOADED, event);
|
582 | }
|
583 |
|
584 | async loadUpdateConfig() {
|
585 | if (this._appUpdateConfigPath == null) {
|
586 | this._appUpdateConfigPath = this.app.appUpdateConfigPath;
|
587 | }
|
588 |
|
589 | return (0, _jsYaml().safeLoad)((await (0, _fsExtra().readFile)(this._appUpdateConfigPath, "utf-8")));
|
590 | }
|
591 |
|
592 | computeRequestHeaders(provider) {
|
593 | const fileExtraDownloadHeaders = provider.fileExtraDownloadHeaders;
|
594 |
|
595 | if (fileExtraDownloadHeaders != null) {
|
596 | const requestHeaders = this.requestHeaders;
|
597 | return requestHeaders == null ? fileExtraDownloadHeaders : { ...fileExtraDownloadHeaders,
|
598 | ...requestHeaders
|
599 | };
|
600 | }
|
601 |
|
602 | return this.computeFinalHeaders({
|
603 | accept: "*/*"
|
604 | });
|
605 | }
|
606 |
|
607 | async getOrCreateStagingUserId() {
|
608 | const file = path.join(this.app.userDataPath, ".updaterId");
|
609 |
|
610 | try {
|
611 | const id = await (0, _fsExtra().readFile)(file, "utf-8");
|
612 |
|
613 | if (_builderUtilRuntime().UUID.check(id)) {
|
614 | return id;
|
615 | } else {
|
616 | this._logger.warn(`Staging user id file exists, but content was invalid: ${id}`);
|
617 | }
|
618 | } catch (e) {
|
619 | if (e.code !== "ENOENT") {
|
620 | this._logger.warn(`Couldn't read staging user ID, creating a blank one: ${e}`);
|
621 | }
|
622 | }
|
623 |
|
624 | const id = _builderUtilRuntime().UUID.v5((0, _crypto().randomBytes)(4096), _builderUtilRuntime().UUID.OID);
|
625 |
|
626 | this._logger.info(`Generated new staging user ID: ${id}`);
|
627 |
|
628 | try {
|
629 | await (0, _fsExtra().outputFile)(file, id);
|
630 | } catch (e) {
|
631 | this._logger.warn(`Couldn't write out staging user ID: ${e}`);
|
632 | }
|
633 |
|
634 | return id;
|
635 | }
|
636 |
|
637 |
|
638 |
|
639 | get isAddNoCacheQuery() {
|
640 | const headers = this.requestHeaders;
|
641 |
|
642 | if (headers == null) {
|
643 | return true;
|
644 | }
|
645 |
|
646 | for (const headerName of Object.keys(headers)) {
|
647 | const s = headerName.toLowerCase();
|
648 |
|
649 | if (s === "authorization" || s === "private-token") {
|
650 | return false;
|
651 | }
|
652 | }
|
653 |
|
654 | return true;
|
655 | }
|
656 |
|
657 | async getOrCreateDownloadHelper() {
|
658 | let result = this.downloadedUpdateHelper;
|
659 |
|
660 | if (result == null) {
|
661 | const dirName = (await this.configOnDisk.value).updaterCacheDirName;
|
662 | const logger = this._logger;
|
663 |
|
664 | if (dirName == null) {
|
665 | logger.error("updaterCacheDirName is not specified in app-update.yml Was app build using at least electron-builder 20.34.0?");
|
666 | }
|
667 |
|
668 | const cacheDir = path.join(this.app.baseCachePath, dirName || this.app.name);
|
669 |
|
670 | if (logger.debug != null) {
|
671 | logger.debug(`updater cache dir: ${cacheDir}`);
|
672 | }
|
673 |
|
674 | result = new (_DownloadedUpdateHelper().DownloadedUpdateHelper)(cacheDir);
|
675 | this.downloadedUpdateHelper = result;
|
676 | }
|
677 |
|
678 | return result;
|
679 | }
|
680 |
|
681 | async executeDownload(taskOptions) {
|
682 | const fileInfo = taskOptions.fileInfo;
|
683 | const downloadOptions = {
|
684 | headers: taskOptions.downloadUpdateOptions.requestHeaders,
|
685 | cancellationToken: taskOptions.downloadUpdateOptions.cancellationToken,
|
686 | sha2: fileInfo.info.sha2,
|
687 | sha512: fileInfo.info.sha512
|
688 | };
|
689 |
|
690 | if (this.listenerCount(_main().DOWNLOAD_PROGRESS) > 0) {
|
691 | downloadOptions.onProgress = it => this.emit(_main().DOWNLOAD_PROGRESS, it);
|
692 | }
|
693 |
|
694 | const updateInfo = taskOptions.downloadUpdateOptions.updateInfoAndProvider.info;
|
695 | const version = updateInfo.version;
|
696 | const packageInfo = fileInfo.packageInfo;
|
697 |
|
698 | function getCacheUpdateFileName() {
|
699 |
|
700 | const urlPath = decodeURIComponent(taskOptions.fileInfo.url.pathname);
|
701 |
|
702 | if (urlPath.endsWith(`.${taskOptions.fileExtension}`)) {
|
703 | return path.posix.basename(urlPath);
|
704 | } else {
|
705 |
|
706 | return `update.${taskOptions.fileExtension}`;
|
707 | }
|
708 | }
|
709 |
|
710 | const downloadedUpdateHelper = await this.getOrCreateDownloadHelper();
|
711 | const cacheDir = downloadedUpdateHelper.cacheDirForPendingUpdate;
|
712 | await (0, _fsExtra().ensureDir)(cacheDir);
|
713 | const updateFileName = getCacheUpdateFileName();
|
714 | let updateFile = path.join(cacheDir, updateFileName);
|
715 | const packageFile = packageInfo == null ? null : path.join(cacheDir, `package-${version}${path.extname(packageInfo.path) || ".7z"}`);
|
716 |
|
717 | const done = async isSaveCache => {
|
718 | await downloadedUpdateHelper.setDownloadedFile(updateFile, packageFile, updateInfo, fileInfo, updateFileName, isSaveCache);
|
719 | await taskOptions.done({ ...updateInfo,
|
720 | downloadedFile: updateFile
|
721 | });
|
722 | return packageFile == null ? [updateFile] : [updateFile, packageFile];
|
723 | };
|
724 |
|
725 | const log = this._logger;
|
726 | const cachedUpdateFile = await downloadedUpdateHelper.validateDownloadedPath(updateFile, updateInfo, fileInfo, log);
|
727 |
|
728 | if (cachedUpdateFile != null) {
|
729 | updateFile = cachedUpdateFile;
|
730 | return await done(false);
|
731 | }
|
732 |
|
733 | const removeFileIfAny = async () => {
|
734 | await downloadedUpdateHelper.clear().catch(() => {
|
735 | });
|
736 | return await (0, _fsExtra().unlink)(updateFile).catch(() => {
|
737 | });
|
738 | };
|
739 |
|
740 | const tempUpdateFile = await (0, _DownloadedUpdateHelper().createTempUpdateFile)(`temp-${updateFileName}`, cacheDir, log);
|
741 |
|
742 | try {
|
743 | await taskOptions.task(tempUpdateFile, downloadOptions, packageFile, removeFileIfAny);
|
744 | await (0, _fsExtra().rename)(tempUpdateFile, updateFile);
|
745 | } catch (e) {
|
746 | await removeFileIfAny();
|
747 |
|
748 | if (e instanceof _builderUtilRuntime().CancellationError) {
|
749 | log.info("cancelled");
|
750 | this.emit("update-cancelled", updateInfo);
|
751 | }
|
752 |
|
753 | throw e;
|
754 | }
|
755 |
|
756 | log.info(`New version ${version} has been downloaded to ${updateFile}`);
|
757 | return await done(true);
|
758 | }
|
759 |
|
760 | }
|
761 |
|
762 | exports.AppUpdater = AppUpdater;
|
763 |
|
764 | function hasPrereleaseComponents(version) {
|
765 | const versionPrereleaseComponent = (0, _semver().prerelease)(version);
|
766 | return versionPrereleaseComponent != null && versionPrereleaseComponent.length > 0;
|
767 | }
|
768 |
|
769 |
|
770 |
|
771 | class NoOpLogger {
|
772 |
|
773 | info(message) {}
|
774 |
|
775 |
|
776 |
|
777 | warn(message) {}
|
778 |
|
779 |
|
780 |
|
781 | error(message) {
|
782 | }
|
783 |
|
784 | } exports.NoOpLogger = NoOpLogger;
|
785 |
|
786 |
|
\ | No newline at end of file |