main.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getDefaultChannelName = getDefaultChannelName;
  6. exports.getCustomChannelName = getCustomChannelName;
  7. exports.getCurrentPlatform = getCurrentPlatform;
  8. exports.isUseOldMacProvider = isUseOldMacProvider;
  9. exports.getChannelFilename = getChannelFilename;
  10. exports.newBaseUrl = newBaseUrl;
  11. exports.newUrlFromBase = newUrlFromBase;
  12. Object.defineProperty(exports, "AppUpdater", {
  13. enumerable: true,
  14. get: function () {
  15. return _AppUpdater().AppUpdater;
  16. }
  17. });
  18. Object.defineProperty(exports, "NoOpLogger", {
  19. enumerable: true,
  20. get: function () {
  21. return _AppUpdater().NoOpLogger;
  22. }
  23. });
  24. Object.defineProperty(exports, "CancellationToken", {
  25. enumerable: true,
  26. get: function () {
  27. return _builderUtilRuntime().CancellationToken;
  28. }
  29. });
  30. Object.defineProperty(exports, "Provider", {
  31. enumerable: true,
  32. get: function () {
  33. return _Provider().Provider;
  34. }
  35. });
  36. exports.UpdaterSignal = exports.UPDATE_DOWNLOADED = exports.DOWNLOAD_PROGRESS = void 0;
  37. function _url() {
  38. const data = require("url");
  39. _url = function () {
  40. return data;
  41. };
  42. return data;
  43. }
  44. function _AppUpdater() {
  45. const data = require("./AppUpdater");
  46. _AppUpdater = function () {
  47. return data;
  48. };
  49. return data;
  50. }
  51. function _builderUtilRuntime() {
  52. const data = require("builder-util-runtime");
  53. _builderUtilRuntime = function () {
  54. return data;
  55. };
  56. return data;
  57. }
  58. function _Provider() {
  59. const data = require("./providers/Provider");
  60. _Provider = function () {
  61. return data;
  62. };
  63. return data;
  64. }
  65. // autoUpdater to mimic electron bundled autoUpdater
  66. let _autoUpdater;
  67. function _load_autoUpdater() {
  68. // tslint:disable:prefer-conditional-expression
  69. if (process.platform === "win32") {
  70. _autoUpdater = new (require("./NsisUpdater").NsisUpdater)();
  71. } else if (process.platform === "darwin") {
  72. _autoUpdater = new (require("./MacUpdater").MacUpdater)();
  73. } else {
  74. _autoUpdater = new (require("./AppImageUpdater").AppImageUpdater)();
  75. }
  76. return _autoUpdater;
  77. }
  78. Object.defineProperty(exports, "autoUpdater", {
  79. enumerable: true,
  80. get: () => {
  81. return _autoUpdater || _load_autoUpdater();
  82. }
  83. }); // due to historical reasons for windows we use channel name without platform specifier
  84. function getDefaultChannelName() {
  85. return `latest${getChannelFilePrefix()}`;
  86. }
  87. function getChannelFilePrefix() {
  88. const currentPlatform = getCurrentPlatform();
  89. if (currentPlatform === "linux") {
  90. const arch = process.env.TEST_UPDATER_ARCH || process.arch;
  91. const archSuffix = arch === "x64" ? "" : `-${arch}`;
  92. return "-linux" + archSuffix;
  93. } else {
  94. return currentPlatform === "darwin" ? "-mac" : "";
  95. }
  96. }
  97. function getCustomChannelName(channel) {
  98. return `${channel}${getChannelFilePrefix()}`;
  99. }
  100. function getCurrentPlatform() {
  101. return process.env.TEST_UPDATER_PLATFORM || process.platform;
  102. }
  103. function isUseOldMacProvider() {
  104. // getCurrentPlatform() === "darwin"
  105. return false;
  106. }
  107. function getChannelFilename(channel) {
  108. return `${channel}.yml`;
  109. }
  110. const DOWNLOAD_PROGRESS = "download-progress";
  111. exports.DOWNLOAD_PROGRESS = DOWNLOAD_PROGRESS;
  112. const UPDATE_DOWNLOADED = "update-downloaded";
  113. exports.UPDATE_DOWNLOADED = UPDATE_DOWNLOADED;
  114. class UpdaterSignal {
  115. constructor(emitter) {
  116. this.emitter = emitter;
  117. }
  118. /**
  119. * Emitted when an authenticating proxy is [asking for user credentials](https://github.com/electron/electron/blob/master/docs/api/client-request.md#event-login).
  120. */
  121. login(handler) {
  122. addHandler(this.emitter, "login", handler);
  123. }
  124. progress(handler) {
  125. addHandler(this.emitter, DOWNLOAD_PROGRESS, handler);
  126. }
  127. updateDownloaded(handler) {
  128. addHandler(this.emitter, UPDATE_DOWNLOADED, handler);
  129. }
  130. updateCancelled(handler) {
  131. addHandler(this.emitter, "update-cancelled", handler);
  132. }
  133. }
  134. exports.UpdaterSignal = UpdaterSignal;
  135. const isLogEvent = false;
  136. function addHandler(emitter, event, handler) {
  137. if (isLogEvent) {
  138. emitter.on(event, (...args) => {
  139. console.log("%s %s", event, args);
  140. handler.apply(null, args);
  141. });
  142. } else {
  143. emitter.on(event, handler);
  144. }
  145. } // if baseUrl path doesn't ends with /, this path will be not prepended to passed pathname for new URL(input, base)
  146. /** @internal */
  147. function newBaseUrl(url) {
  148. const result = new (_url().URL)(url);
  149. if (!result.pathname.endsWith("/")) {
  150. result.pathname += "/";
  151. }
  152. return result;
  153. } // addRandomQueryToAvoidCaching is false by default because in most cases URL already contains version number,
  154. // so, it makes sense only for Generic Provider for channel files
  155. function newUrlFromBase(pathname, baseUrl, addRandomQueryToAvoidCaching = false) {
  156. const result = new (_url().URL)(pathname, baseUrl); // search is not propagated (search is an empty string if not specified)
  157. const search = baseUrl.search;
  158. if (search != null && search.length !== 0) {
  159. result.search = search;
  160. } else if (addRandomQueryToAvoidCaching) {
  161. result.search = `noCache=${Date.now().toString(32)}`;
  162. }
  163. return result;
  164. }
  165. //# sourceMappingURL=main.js.map