AppImageUpdater.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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("./providers/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(downloadUpdateOptions) {
  86. var _this = this;
  87. return (0, _bluebirdLst().coroutine)(function* () {
  88. const provider = yield _this.provider;
  89. const fileInfo = (0, _Provider().findFile)(provider.resolveFiles(downloadUpdateOptions.updateInfo), "AppImage");
  90. return yield _this.executeDownload({
  91. fileExtension: "AppImage",
  92. fileInfo,
  93. downloadUpdateOptions,
  94. task: (() => {
  95. var _ref = (0, _bluebirdLst().coroutine)(function* (updateFile, downloadOptions) {
  96. const oldFile = process.env.APPIMAGE;
  97. if (oldFile == null) {
  98. throw (0, _builderUtilRuntime().newError)("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND");
  99. }
  100. let isDownloadFull = false;
  101. try {
  102. yield new (_FileWithEmbeddedBlockMapDifferentialDownloader().FileWithEmbeddedBlockMapDifferentialDownloader)(fileInfo.info, _this.httpExecutor, {
  103. newUrl: fileInfo.url.href,
  104. oldFile,
  105. logger: _this._logger,
  106. newFile: updateFile,
  107. useMultipleRangeRequest: provider.useMultipleRangeRequest,
  108. requestHeaders: downloadUpdateOptions.requestHeaders
  109. }).download();
  110. } catch (e) {
  111. _this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`); // during test (developer machine mac) we must throw error
  112. isDownloadFull = process.platform === "linux";
  113. }
  114. if (isDownloadFull) {
  115. yield _this.httpExecutor.download(fileInfo.url.href, updateFile, downloadOptions);
  116. }
  117. yield (0, _fsExtraP().chmod)(updateFile, 0o755);
  118. });
  119. return function task(_x, _x2) {
  120. return _ref.apply(this, arguments);
  121. };
  122. })()
  123. });
  124. })();
  125. }
  126. doInstall(installerPath, isSilent, isRunAfter) {
  127. const appImageFile = process.env.APPIMAGE;
  128. if (appImageFile == null) {
  129. throw (0, _builderUtilRuntime().newError)("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND");
  130. } // https://stackoverflow.com/a/1712051/1910191
  131. (0, _fsExtraP().unlinkSync)(appImageFile);
  132. let destination;
  133. const existingBaseName = path.basename(appImageFile); // https://github.com/electron-userland/electron-builder/issues/2964
  134. // if no version in existing file name, it means that user wants to preserve current custom name
  135. if (path.basename(installerPath) === existingBaseName || !/\d+\.\d+\.\d+/.test(existingBaseName)) {
  136. // no version in the file name, overwrite existing
  137. destination = appImageFile;
  138. } else {
  139. destination = path.join(path.dirname(appImageFile), path.basename(installerPath));
  140. }
  141. (0, _child_process().execFileSync)("mv", ["-f", installerPath, destination]);
  142. const env = Object.assign({}, process.env, {
  143. APPIMAGE_SILENT_INSTALL: "true"
  144. });
  145. if (isRunAfter) {
  146. (0, _child_process().spawn)(destination, [], {
  147. detached: true,
  148. stdio: "ignore",
  149. env
  150. }).unref();
  151. } else {
  152. env.APPIMAGE_EXIT_AFTER_INSTALL = "true";
  153. (0, _child_process().execFileSync)(destination, [], {
  154. env
  155. });
  156. }
  157. return true;
  158. }
  159. } exports.AppImageUpdater = AppImageUpdater;
  160. //# sourceMappingURL=AppImageUpdater.js.map