AppImageUpdater.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.AppImageUpdater = void 0;
  6. function _bluebirdLst() {
  7. const data = require("bluebird-lst");
  8. _bluebirdLst = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _builderUtilRuntime() {
  14. const data = require("builder-util-runtime");
  15. _builderUtilRuntime = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _child_process() {
  21. const data = require("child_process");
  22. _child_process = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _electronIsDev() {
  28. const data = _interopRequireDefault(require("electron-is-dev"));
  29. _electronIsDev = function () {
  30. return data;
  31. };
  32. return data;
  33. }
  34. function _fsExtraP() {
  35. const data = require("fs-extra-p");
  36. _fsExtraP = function () {
  37. return data;
  38. };
  39. return data;
  40. }
  41. var path = _interopRequireWildcard(require("path"));
  42. require("source-map-support/register");
  43. function _BaseUpdater() {
  44. const data = require("./BaseUpdater");
  45. _BaseUpdater = function () {
  46. return data;
  47. };
  48. return data;
  49. }
  50. function _FileWithEmbeddedBlockMapDifferentialDownloader() {
  51. const data = require("./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader");
  52. _FileWithEmbeddedBlockMapDifferentialDownloader = function () {
  53. return data;
  54. };
  55. return data;
  56. }
  57. function _Provider() {
  58. const data = require("./Provider");
  59. _Provider = function () {
  60. return data;
  61. };
  62. return data;
  63. }
  64. 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; } }
  65. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  66. class AppImageUpdater extends _BaseUpdater().BaseUpdater {
  67. constructor(options, app) {
  68. super(options, app);
  69. }
  70. checkForUpdatesAndNotify() {
  71. if (_electronIsDev().default) {
  72. return Promise.resolve(null);
  73. }
  74. if (process.env.APPIMAGE == null) {
  75. if (process.env.SNAP == null) {
  76. this._logger.warn("APPIMAGE env is not defined, current application is not an AppImage");
  77. } else {
  78. this._logger.info("SNAP env is defined, updater is disabled");
  79. }
  80. return Promise.resolve(null);
  81. }
  82. return super.checkForUpdatesAndNotify();
  83. }
  84. /*** @private */
  85. doDownloadUpdate(updateInfo, cancellationToken) {
  86. var _this = this;
  87. return (0, _bluebirdLst().coroutine)(function* () {
  88. const provider = yield _this.provider;
  89. const fileInfo = (0, _Provider().findFile)(provider.resolveFiles(updateInfo), "AppImage");
  90. const requestHeaders = yield _this.computeRequestHeaders();
  91. const downloadOptions = {
  92. skipDirCreation: true,
  93. headers: requestHeaders,
  94. cancellationToken,
  95. sha512: fileInfo.info.sha512
  96. };
  97. return yield _this.executeDownload({
  98. fileExtension: "AppImage",
  99. downloadOptions,
  100. fileInfo,
  101. updateInfo,
  102. task: (() => {
  103. var _ref = (0, _bluebirdLst().coroutine)(function* (updateFile) {
  104. const oldFile = process.env.APPIMAGE;
  105. if (oldFile == null) {
  106. throw (0, _builderUtilRuntime().newError)("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND");
  107. }
  108. let isDownloadFull = false;
  109. try {
  110. yield new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(fileInfo.info, _this.httpExecutor, {
  111. newUrl: fileInfo.url.href,
  112. oldFile,
  113. logger: _this._logger,
  114. newFile: updateFile,
  115. useMultipleRangeRequest: provider.useMultipleRangeRequest,
  116. requestHeaders
  117. }).download();
  118. } catch (e) {
  119. _this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`); // during test (developer machine mac) we must throw error
  120. isDownloadFull = process.platform === "linux";
  121. }
  122. if (isDownloadFull) {
  123. yield _this.httpExecutor.download(fileInfo.url.href, updateFile, downloadOptions);
  124. }
  125. yield (0, _fsExtraP().chmod)(updateFile, 0o755);
  126. });
  127. return function task(_x) {
  128. return _ref.apply(this, arguments);
  129. };
  130. })()
  131. });
  132. })();
  133. }
  134. doInstall(installerPath, isSilent, isRunAfter) {
  135. const appImageFile = process.env.APPIMAGE;
  136. if (appImageFile == null) {
  137. throw (0, _builderUtilRuntime().newError)("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND");
  138. } // https://stackoverflow.com/a/1712051/1910191
  139. (0, _fsExtraP().unlinkSync)(appImageFile);
  140. let destination;
  141. if (path.basename(installerPath) === path.basename(appImageFile)) {
  142. // no version in the file name, overwrite existing
  143. destination = appImageFile;
  144. } else {
  145. destination = path.join(path.dirname(appImageFile), path.basename(installerPath));
  146. }
  147. (0, _child_process().execFileSync)("mv", ["-f", installerPath, destination]);
  148. const env = Object.assign({}, process.env, {
  149. APPIMAGE_SILENT_INSTALL: "true"
  150. });
  151. if (isRunAfter) {
  152. (0, _child_process().spawn)(destination, [], {
  153. detached: true,
  154. stdio: "ignore",
  155. env
  156. }).unref();
  157. } else {
  158. env.APPIMAGE_EXIT_AFTER_INSTALL = "true";
  159. (0, _child_process().execFileSync)(destination, [], {
  160. env
  161. });
  162. }
  163. return true;
  164. }
  165. } exports.AppImageUpdater = AppImageUpdater;
  166. //# sourceMappingURL=AppImageUpdater.js.map