BaseUpdater.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.BaseUpdater = void 0;
  6. function _bluebirdLst() {
  7. const data = require("bluebird-lst");
  8. _bluebirdLst = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _AppUpdater() {
  14. const data = require("./AppUpdater");
  15. _AppUpdater = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. class BaseUpdater extends _AppUpdater().AppUpdater {
  21. constructor(options, app) {
  22. super(options, app);
  23. this.quitAndInstallCalled = false;
  24. this.quitHandlerAdded = false;
  25. }
  26. quitAndInstall(isSilent = false, isForceRunAfter = false) {
  27. var _this = this;
  28. return (0, _bluebirdLst().coroutine)(function* () {
  29. _this._logger.info(`Install on explicit quitAndInstall`);
  30. const isInstalled = yield _this.install(isSilent, isSilent ? isForceRunAfter : true);
  31. if (isInstalled) {
  32. setImmediate(() => {
  33. if (_this.app.quit !== undefined) {
  34. _this.app.quit();
  35. }
  36. });
  37. } else {
  38. _this.quitAndInstallCalled = false;
  39. }
  40. })();
  41. }
  42. executeDownload(taskOptions) {
  43. var _this2 = this;
  44. return super.executeDownload(Object.assign({}, taskOptions, {
  45. done: (() => {
  46. var _ref = (0, _bluebirdLst().coroutine)(function* () {
  47. _this2.addQuitHandler();
  48. });
  49. return function done() {
  50. return _ref.apply(this, arguments);
  51. };
  52. })()
  53. }));
  54. }
  55. install(isSilent, isRunAfter) {
  56. var _this3 = this;
  57. return (0, _bluebirdLst().coroutine)(function* () {
  58. if (_this3.quitAndInstallCalled) {
  59. _this3._logger.warn("install call ignored: quitAndInstallCalled is set to true");
  60. return false;
  61. }
  62. const installerPath = _this3.downloadedUpdateHelper.file; // todo check (for now it is ok to no check as before, cached (from previous launch) update file checked in any case)
  63. // const isValid = await this.isUpdateValid(installerPath)
  64. if (installerPath == null) {
  65. _this3.dispatchError(new Error("No valid update available, can't quit and install"));
  66. return false;
  67. } // prevent calling several times
  68. _this3.quitAndInstallCalled = true;
  69. try {
  70. _this3._logger.info(`Install: isSilent: ${isSilent}, isRunAfter: ${isRunAfter}`);
  71. return _this3.doInstall(installerPath, isSilent, isRunAfter);
  72. } catch (e) {
  73. _this3.dispatchError(e);
  74. return false;
  75. }
  76. })();
  77. }
  78. addQuitHandler() {
  79. var _this4 = this;
  80. if (this.quitHandlerAdded || !this.autoInstallOnAppQuit) {
  81. return;
  82. }
  83. this.quitHandlerAdded = true;
  84. this.app.once("quit", (0, _bluebirdLst().coroutine)(function* () {
  85. if (!_this4.quitAndInstallCalled) {
  86. _this4._logger.info("Auto install update on quit");
  87. yield _this4.install(true, false);
  88. } else {
  89. _this4._logger.info("Update installer has already been triggered. Quitting application.");
  90. }
  91. }));
  92. }
  93. } exports.BaseUpdater = BaseUpdater;
  94. //# sourceMappingURL=BaseUpdater.js.map