|
|
@@ -109,6 +109,16 @@ function _semver() {
|
|
|
|
|
|
require("source-map-support/register");
|
|
|
|
|
|
+function _DownloadedUpdateHelper() {
|
|
|
+ const data = require("./DownloadedUpdateHelper");
|
|
|
+
|
|
|
+ _DownloadedUpdateHelper = function () {
|
|
|
+ return data;
|
|
|
+ };
|
|
|
+
|
|
|
+ return data;
|
|
|
+}
|
|
|
+
|
|
|
function _electronHttpExecutor() {
|
|
|
const data = require("./electronHttpExecutor");
|
|
|
|
|
|
@@ -120,7 +130,7 @@ function _electronHttpExecutor() {
|
|
|
}
|
|
|
|
|
|
function _GenericProvider() {
|
|
|
- const data = require("./GenericProvider");
|
|
|
+ const data = require("./providers/GenericProvider");
|
|
|
|
|
|
_GenericProvider = function () {
|
|
|
return data;
|
|
|
@@ -149,16 +159,6 @@ function _providerFactory() {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
-function _DownloadedUpdateHelper() {
|
|
|
- const data = require("./DownloadedUpdateHelper");
|
|
|
-
|
|
|
- _DownloadedUpdateHelper = function () {
|
|
|
- return data;
|
|
|
- };
|
|
|
-
|
|
|
- return data;
|
|
|
-}
|
|
|
-
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
@@ -193,6 +193,9 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
this.fullChangelog = false;
|
|
|
/**
|
|
|
* Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).
|
|
|
+ *
|
|
|
+ * Taken in account only if channel differs (pre-release version component in terms of semantic versioning).
|
|
|
+ *
|
|
|
* @default false
|
|
|
*/
|
|
|
|
|
|
@@ -203,17 +206,19 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
*/
|
|
|
|
|
|
this.requestHeaders = null;
|
|
|
- this._logger = console;
|
|
|
+ this._logger = console; // noinspection JSUnusedGlobalSymbols
|
|
|
+
|
|
|
/**
|
|
|
* For type safety you can use signals, e.g. `autoUpdater.signals.updateDownloaded(() => {})` instead of `autoUpdater.on('update-available', () => {})`
|
|
|
*/
|
|
|
|
|
|
this.signals = new (_main().UpdaterSignal)(this);
|
|
|
this._appUpdateConfigPath = null;
|
|
|
- this.updateAvailable = false;
|
|
|
this.clientPromise = null;
|
|
|
this.stagingUserIdPromise = new (_lazyVal().Lazy)(() => this.getOrCreateStagingUserId()); // public, allow to read old config for anyone
|
|
|
|
|
|
+ /** @internal */
|
|
|
+
|
|
|
this.configOnDisk = new (_lazyVal().Lazy)(() => this.loadUpdateConfig());
|
|
|
this.checkForUpdatesPromise = null;
|
|
|
this.updateInfo = null;
|
|
|
@@ -237,16 +242,16 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- this.downloadedUpdateHelper = new (_DownloadedUpdateHelper().DownloadedUpdateHelper)(this.app.getPath("userData"));
|
|
|
+ this.downloadedUpdateHelper = new (_DownloadedUpdateHelper().DownloadedUpdateHelper)(path.join(this.app.getPath("userData"), "__update__"));
|
|
|
const currentVersionString = this.app.getVersion();
|
|
|
- const currentVersion = (0, _semver().valid)(currentVersionString);
|
|
|
+ const currentVersion = (0, _semver().parse)(currentVersionString);
|
|
|
|
|
|
if (currentVersion == null) {
|
|
|
- throw (0, _builderUtilRuntime().newError)(`App version is not a valid semver version: "${currentVersionString}`, "ERR_UPDATER_INVALID_VERSION");
|
|
|
+ throw (0, _builderUtilRuntime().newError)(`App version is not a valid semver version: "${currentVersionString}"`, "ERR_UPDATER_INVALID_VERSION");
|
|
|
}
|
|
|
|
|
|
this.currentVersion = currentVersion;
|
|
|
- this.allowPrerelease = hasPrereleaseComponents(this.currentVersion);
|
|
|
+ this.allowPrerelease = hasPrereleaseComponents(currentVersion);
|
|
|
|
|
|
if (options != null) {
|
|
|
this.setFeedURL(options);
|
|
|
@@ -269,6 +274,7 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
|
|
|
set channel(value) {
|
|
|
if (this._channel != null) {
|
|
|
+ // noinspection SuspiciousTypeOfGuard
|
|
|
if (typeof value !== "string") {
|
|
|
throw (0, _builderUtilRuntime().newError)(`Channel must be a string, but got: ${value}`, "ERR_UPDATER_INVALID_CHANNEL");
|
|
|
} else if (value.length === 0) {
|
|
|
@@ -327,7 +333,7 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
provider = new (_GenericProvider().GenericProvider)({
|
|
|
provider: "generic",
|
|
|
url: options
|
|
|
- }, this);
|
|
|
+ }, this, (0, _providerFactory().isUrlProbablySupportMultiRangeRequests)(options));
|
|
|
} else {
|
|
|
provider = (0, _providerFactory().createClient)(options, this);
|
|
|
}
|
|
|
@@ -365,7 +371,11 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
const downloadPromise = it.downloadPromise;
|
|
|
|
|
|
if (downloadPromise == null) {
|
|
|
- this._logger.warn("checkForUpdatesAndNotify called, but downloadPromise is null");
|
|
|
+ const debug = this._logger.debug;
|
|
|
+
|
|
|
+ if (debug != null) {
|
|
|
+ debug("checkForUpdatesAndNotify called, downloadPromise is null");
|
|
|
+ }
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
@@ -441,44 +451,77 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
return headers;
|
|
|
}
|
|
|
|
|
|
- getUpdateInfo() {
|
|
|
+ isUpdateAvailable(updateInfo) {
|
|
|
var _this3 = this;
|
|
|
|
|
|
return (0, _bluebirdLst().coroutine)(function* () {
|
|
|
- yield _this3.untilAppReady;
|
|
|
+ const latestVersion = (0, _semver().parse)(updateInfo.version);
|
|
|
|
|
|
- if (_this3.clientPromise == null) {
|
|
|
- _this3.clientPromise = _this3.configOnDisk.value.then(it => (0, _providerFactory().createClient)(it, _this3));
|
|
|
+ if (latestVersion == null) {
|
|
|
+ throw (0, _builderUtilRuntime().newError)(`This file could not be downloaded, or the latest version (from update server) does not have a valid semver version: "${latestVersion}"`, "ERR_UPDATER_INVALID_VERSION");
|
|
|
}
|
|
|
|
|
|
- const client = yield _this3.clientPromise;
|
|
|
- const stagingUserId = yield _this3.stagingUserIdPromise.value;
|
|
|
- client.setRequestHeaders(_this3.computeFinalHeaders({
|
|
|
- "X-User-Staging-Id": stagingUserId
|
|
|
- }));
|
|
|
- return yield client.getLatestVersion();
|
|
|
+ const currentVersion = _this3.currentVersion;
|
|
|
+
|
|
|
+ if ((0, _semver().eq)(latestVersion, currentVersion)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const isStagingMatch = yield _this3.isStagingMatch(updateInfo);
|
|
|
+
|
|
|
+ if (!isStagingMatch) {
|
|
|
+ return false;
|
|
|
+ } // https://github.com/electron-userland/electron-builder/pull/3111#issuecomment-405033227
|
|
|
+ // https://github.com/electron-userland/electron-builder/pull/3111#issuecomment-405030797
|
|
|
+
|
|
|
+
|
|
|
+ const isLatestVersionNewer = (0, _semver().gt)(latestVersion, currentVersion);
|
|
|
+
|
|
|
+ if (!_this3.allowDowngrade) {
|
|
|
+ return isLatestVersionNewer;
|
|
|
+ }
|
|
|
+
|
|
|
+ const currentVersionPrereleaseComponent = (0, _semver().prerelease)(currentVersion);
|
|
|
+ const latestVersionPrereleaseComponent = (0, _semver().prerelease)(latestVersion);
|
|
|
+
|
|
|
+ if (currentVersionPrereleaseComponent === latestVersionPrereleaseComponent) {
|
|
|
+ // allowDowngrade taken in account only if channel differs
|
|
|
+ return isLatestVersionNewer;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
})();
|
|
|
}
|
|
|
|
|
|
- doCheckForUpdates() {
|
|
|
+ getUpdateInfo() {
|
|
|
var _this4 = this;
|
|
|
|
|
|
return (0, _bluebirdLst().coroutine)(function* () {
|
|
|
- const updateInfo = yield _this4.getUpdateInfo();
|
|
|
- const latestVersion = (0, _semver().valid)(updateInfo.version);
|
|
|
+ yield _this4.untilAppReady;
|
|
|
|
|
|
- if (latestVersion == null) {
|
|
|
- throw (0, _builderUtilRuntime().newError)(`Latest version (from update server) is not valid semver version: "${latestVersion}`, "ERR_UPDATER_INVALID_VERSION");
|
|
|
+ if (_this4.clientPromise == null) {
|
|
|
+ _this4.clientPromise = _this4.configOnDisk.value.then(it => (0, _providerFactory().createClient)(it, _this4));
|
|
|
}
|
|
|
|
|
|
- const isStagingMatch = yield _this4.isStagingMatch(updateInfo);
|
|
|
+ const client = yield _this4.clientPromise;
|
|
|
+ const stagingUserId = yield _this4.stagingUserIdPromise.value;
|
|
|
+ client.setRequestHeaders(_this4.computeFinalHeaders({
|
|
|
+ "x-user-staging-id": stagingUserId
|
|
|
+ }));
|
|
|
+ return yield client.getLatestVersion();
|
|
|
+ })();
|
|
|
+ }
|
|
|
+
|
|
|
+ doCheckForUpdates() {
|
|
|
+ var _this5 = this;
|
|
|
|
|
|
- if (!isStagingMatch || (_this4.allowDowngrade && !hasPrereleaseComponents(latestVersion) ? (0, _semver().eq)(latestVersion, _this4.currentVersion) : !(0, _semver().gt)(latestVersion, _this4.currentVersion))) {
|
|
|
- _this4.updateAvailable = false;
|
|
|
+ return (0, _bluebirdLst().coroutine)(function* () {
|
|
|
+ const updateInfo = yield _this5.getUpdateInfo();
|
|
|
|
|
|
- _this4._logger.info(`Update for version ${_this4.currentVersion} is not available (latest version: ${updateInfo.version}, downgrade is ${_this4.allowDowngrade ? "allowed" : "disallowed"}).`);
|
|
|
+ if (!(yield _this5.isUpdateAvailable(updateInfo))) {
|
|
|
+ _this5._logger.info(`Update for version ${_this5.currentVersion} is not available (latest version: ${updateInfo.version}, downgrade is ${_this5.allowDowngrade ? "allowed" : "disallowed"}).`);
|
|
|
|
|
|
- _this4.emit("update-not-available", updateInfo);
|
|
|
+ _this5.emit("update-not-available", updateInfo);
|
|
|
|
|
|
return {
|
|
|
versionInfo: updateInfo,
|
|
|
@@ -486,10 +529,9 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- _this4.updateAvailable = true;
|
|
|
- _this4.updateInfo = updateInfo;
|
|
|
+ _this5.updateInfo = updateInfo;
|
|
|
|
|
|
- _this4.onUpdateAvailable(updateInfo);
|
|
|
+ _this5.onUpdateAvailable(updateInfo);
|
|
|
|
|
|
const cancellationToken = new (_builderUtilRuntime().CancellationToken)(); //noinspection ES6MissingAwait
|
|
|
|
|
|
@@ -497,7 +539,7 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
versionInfo: updateInfo,
|
|
|
updateInfo,
|
|
|
cancellationToken,
|
|
|
- downloadPromise: _this4.autoDownload ? _this4.downloadUpdate(cancellationToken) : null
|
|
|
+ downloadPromise: _this5.autoDownload ? _this5.downloadUpdate(cancellationToken) : null
|
|
|
};
|
|
|
})();
|
|
|
}
|
|
|
@@ -514,25 +556,29 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
|
|
|
|
|
|
downloadUpdate(cancellationToken = new (_builderUtilRuntime().CancellationToken)()) {
|
|
|
- var _this5 = this;
|
|
|
+ var _this6 = this;
|
|
|
|
|
|
return (0, _bluebirdLst().coroutine)(function* () {
|
|
|
- const updateInfo = _this5.updateInfo;
|
|
|
+ const updateInfo = _this6.updateInfo;
|
|
|
|
|
|
if (updateInfo == null) {
|
|
|
const error = new Error("Please check update first");
|
|
|
|
|
|
- _this5.dispatchError(error);
|
|
|
+ _this6.dispatchError(error);
|
|
|
|
|
|
throw error;
|
|
|
}
|
|
|
|
|
|
- _this5._logger.info(`Downloading update from ${(0, _builderUtilRuntime().asArray)(updateInfo.files).map(it => it.url).join(", ")}`);
|
|
|
+ _this6._logger.info(`Downloading update from ${(0, _builderUtilRuntime().asArray)(updateInfo.files).map(it => it.url).join(", ")}`);
|
|
|
|
|
|
try {
|
|
|
- return yield _this5.doDownloadUpdate(updateInfo, cancellationToken);
|
|
|
+ return yield _this6.doDownloadUpdate({
|
|
|
+ updateInfo,
|
|
|
+ requestHeaders: yield _this6.computeRequestHeaders(),
|
|
|
+ cancellationToken
|
|
|
+ });
|
|
|
} catch (e) {
|
|
|
- _this5.dispatchError(e);
|
|
|
+ _this6.dispatchError(e);
|
|
|
|
|
|
throw e;
|
|
|
}
|
|
|
@@ -544,41 +590,39 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
}
|
|
|
|
|
|
loadUpdateConfig() {
|
|
|
- var _this6 = this;
|
|
|
+ var _this7 = this;
|
|
|
|
|
|
return (0, _bluebirdLst().coroutine)(function* () {
|
|
|
- if (_this6._appUpdateConfigPath == null) {
|
|
|
- _this6._appUpdateConfigPath = _electronIsDev().default ? path.join(_this6.app.getAppPath(), "dev-app-update.yml") : path.join(process.resourcesPath, "app-update.yml");
|
|
|
+ if (_this7._appUpdateConfigPath == null) {
|
|
|
+ _this7._appUpdateConfigPath = _electronIsDev().default ? path.join(_this7.app.getAppPath(), "dev-app-update.yml") : path.join(process.resourcesPath, "app-update.yml");
|
|
|
}
|
|
|
|
|
|
- return (0, _jsYaml().safeLoad)((yield (0, _fsExtraP().readFile)(_this6._appUpdateConfigPath, "utf-8")));
|
|
|
+ return (0, _jsYaml().safeLoad)((yield (0, _fsExtraP().readFile)(_this7._appUpdateConfigPath, "utf-8")));
|
|
|
})();
|
|
|
}
|
|
|
- /*** @private */
|
|
|
-
|
|
|
|
|
|
computeRequestHeaders() {
|
|
|
- var _this7 = this;
|
|
|
+ var _this8 = this;
|
|
|
|
|
|
return (0, _bluebirdLst().coroutine)(function* () {
|
|
|
- const fileExtraDownloadHeaders = (yield _this7.provider).fileExtraDownloadHeaders;
|
|
|
+ const fileExtraDownloadHeaders = (yield _this8.provider).fileExtraDownloadHeaders;
|
|
|
|
|
|
if (fileExtraDownloadHeaders != null) {
|
|
|
- const requestHeaders = _this7.requestHeaders;
|
|
|
+ const requestHeaders = _this8.requestHeaders;
|
|
|
return requestHeaders == null ? fileExtraDownloadHeaders : Object.assign({}, fileExtraDownloadHeaders, requestHeaders);
|
|
|
}
|
|
|
|
|
|
- return _this7.computeFinalHeaders({
|
|
|
- Accept: "*/*"
|
|
|
+ return _this8.computeFinalHeaders({
|
|
|
+ accept: "*/*"
|
|
|
});
|
|
|
})();
|
|
|
}
|
|
|
|
|
|
getOrCreateStagingUserId() {
|
|
|
- var _this8 = this;
|
|
|
+ var _this9 = this;
|
|
|
|
|
|
return (0, _bluebirdLst().coroutine)(function* () {
|
|
|
- const file = path.join(_this8.app.getPath("userData"), ".updaterId");
|
|
|
+ const file = path.join(_this9.app.getPath("userData"), ".updaterId");
|
|
|
|
|
|
try {
|
|
|
const id = yield (0, _fsExtraP().readFile)(file, "utf-8");
|
|
|
@@ -586,27 +630,163 @@ class AppUpdater extends _events().EventEmitter {
|
|
|
if (_builderUtilRuntime().UUID.check(id)) {
|
|
|
return id;
|
|
|
} else {
|
|
|
- _this8._logger.warn(`Staging user id file exists, but content was invalid: ${id}`);
|
|
|
+ _this9._logger.warn(`Staging user id file exists, but content was invalid: ${id}`);
|
|
|
}
|
|
|
} catch (e) {
|
|
|
if (e.code !== "ENOENT") {
|
|
|
- _this8._logger.warn(`Couldn't read staging user ID, creating a blank one: ${e}`);
|
|
|
+ _this9._logger.warn(`Couldn't read staging user ID, creating a blank one: ${e}`);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const id = _builderUtilRuntime().UUID.v5((0, _crypto().randomBytes)(4096), _builderUtilRuntime().UUID.OID);
|
|
|
|
|
|
- _this8._logger.info(`Generated new staging user ID: ${id}`);
|
|
|
+ _this9._logger.info(`Generated new staging user ID: ${id}`);
|
|
|
|
|
|
try {
|
|
|
yield (0, _fsExtraP().outputFile)(file, id);
|
|
|
} catch (e) {
|
|
|
- _this8._logger.warn(`Couldn't write out staging user ID: ${e}`);
|
|
|
+ _this9._logger.warn(`Couldn't write out staging user ID: ${e}`);
|
|
|
}
|
|
|
|
|
|
return id;
|
|
|
})();
|
|
|
}
|
|
|
+ /** @internal */
|
|
|
+
|
|
|
+
|
|
|
+ get isAddNoCacheQuery() {
|
|
|
+ const headers = this.requestHeaders; // https://github.com/electron-userland/electron-builder/issues/3021
|
|
|
+
|
|
|
+ if (headers == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const headerName of Object.keys(headers)) {
|
|
|
+ const s = headerName.toLowerCase();
|
|
|
+
|
|
|
+ if (s === "authorization" || s === "private-token") {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ executeDownload(taskOptions) {
|
|
|
+ var _this10 = this;
|
|
|
+
|
|
|
+ return (0, _bluebirdLst().coroutine)(function* () {
|
|
|
+ const fileInfo = taskOptions.fileInfo;
|
|
|
+ const downloadOptions = {
|
|
|
+ skipDirCreation: true,
|
|
|
+ headers: taskOptions.downloadUpdateOptions.requestHeaders,
|
|
|
+ cancellationToken: taskOptions.downloadUpdateOptions.cancellationToken,
|
|
|
+ sha2: fileInfo.info.sha2,
|
|
|
+ sha512: fileInfo.info.sha512
|
|
|
+ };
|
|
|
+
|
|
|
+ if (_this10.listenerCount(_main().DOWNLOAD_PROGRESS) > 0) {
|
|
|
+ downloadOptions.onProgress = it => _this10.emit(_main().DOWNLOAD_PROGRESS, it);
|
|
|
+ }
|
|
|
+
|
|
|
+ const updateInfo = taskOptions.downloadUpdateOptions.updateInfo;
|
|
|
+ const version = updateInfo.version;
|
|
|
+ const packageInfo = fileInfo.packageInfo;
|
|
|
+
|
|
|
+ function getCacheUpdateFileName() {
|
|
|
+ // bloody NodeJS URL doesn't decode automatically
|
|
|
+ const urlPath = decodeURIComponent(taskOptions.fileInfo.url.pathname);
|
|
|
+
|
|
|
+ if (urlPath.endsWith(`.${taskOptions.fileExtension}`)) {
|
|
|
+ return path.posix.basename(urlPath);
|
|
|
+ } else {
|
|
|
+ // url like /latest, generate name
|
|
|
+ return `update.${taskOptions.fileExtension}`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const cacheDir = _this10.downloadedUpdateHelper.cacheDir;
|
|
|
+ yield (0, _fsExtraP().ensureDir)(cacheDir);
|
|
|
+ const updateFileName = getCacheUpdateFileName();
|
|
|
+ let updateFile = path.join(cacheDir, updateFileName);
|
|
|
+ const packageFile = packageInfo == null ? null : path.join(cacheDir, `package-${version}${path.extname(packageInfo.path) || ".7z"}`);
|
|
|
+
|
|
|
+ const done = (() => {
|
|
|
+ var _ref = (0, _bluebirdLst().coroutine)(function* (isSaveCache) {
|
|
|
+ _this10.downloadedUpdateHelper.setDownloadedFile(updateFile, packageFile, updateInfo, fileInfo);
|
|
|
+
|
|
|
+ if (isSaveCache) {
|
|
|
+ yield _this10.downloadedUpdateHelper.cacheUpdateInfo(updateFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ _this10.emit(_main().UPDATE_DOWNLOADED, updateInfo);
|
|
|
+
|
|
|
+ yield taskOptions.done(updateFile);
|
|
|
+ return packageFile == null ? [updateFile] : [updateFile, packageFile];
|
|
|
+ });
|
|
|
+
|
|
|
+ return function done(_x) {
|
|
|
+ return _ref.apply(this, arguments);
|
|
|
+ };
|
|
|
+ })();
|
|
|
+
|
|
|
+ const log = _this10._logger;
|
|
|
+ const cachedUpdateFile = yield _this10.downloadedUpdateHelper.validateDownloadedPath(updateFile, updateInfo, fileInfo, log);
|
|
|
+
|
|
|
+ if (cachedUpdateFile != null) {
|
|
|
+ updateFile = cachedUpdateFile;
|
|
|
+ return yield done(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ const removeFileIfAny = (() => {
|
|
|
+ var _ref2 = (0, _bluebirdLst().coroutine)(function* () {
|
|
|
+ yield _this10.downloadedUpdateHelper.clear().catch(() => {// ignore
|
|
|
+ });
|
|
|
+ return yield (0, _fsExtraP().unlink)(updateFile).catch(() => {// ignore
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return function removeFileIfAny() {
|
|
|
+ return _ref2.apply(this, arguments);
|
|
|
+ };
|
|
|
+ })(); // https://github.com/electron-userland/electron-builder/pull/2474#issuecomment-366481912
|
|
|
+
|
|
|
+
|
|
|
+ let nameCounter = 0;
|
|
|
+ let tempUpdateFile = path.join(cacheDir, `temp-${updateFileName}`);
|
|
|
+
|
|
|
+ for (let i = 0; i < 3; i++) {
|
|
|
+ try {
|
|
|
+ yield (0, _fsExtraP().unlink)(tempUpdateFile);
|
|
|
+ } catch (e) {
|
|
|
+ if (e.code === "ENOENT") {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn(`Error on remove temp update file: ${e}`);
|
|
|
+ tempUpdateFile = path.join(cacheDir, `temp-${nameCounter++}-${updateFileName}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ yield taskOptions.task(tempUpdateFile, downloadOptions, packageFile, removeFileIfAny);
|
|
|
+ yield (0, _fsExtraP().rename)(tempUpdateFile, updateFile);
|
|
|
+ } catch (e) {
|
|
|
+ yield removeFileIfAny();
|
|
|
+
|
|
|
+ if (e instanceof _builderUtilRuntime().CancellationError) {
|
|
|
+ log.info("Cancelled");
|
|
|
+
|
|
|
+ _this10.emit("update-cancelled", updateInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info(`New version ${version} has been downloaded to ${updateFile}`);
|
|
|
+ return yield done(true);
|
|
|
+ })();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|