api.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.UpdaterSignal = exports.DOWNLOAD_PROGRESS = exports.Provider = undefined;
  6. exports.getDefaultChannelName = getDefaultChannelName;
  7. exports.getCustomChannelName = getCustomChannelName;
  8. exports.getCurrentPlatform = getCurrentPlatform;
  9. exports.getChannelFilename = getChannelFilename;
  10. exports.formatUrl = formatUrl;
  11. var _url;
  12. function _load_url() {
  13. return _url = require("url");
  14. }
  15. class Provider {
  16. setRequestHeaders(value) {
  17. this.requestHeaders = value;
  18. }
  19. }
  20. exports.Provider = Provider; // due to historical reasons for windows we use channel name without platform specifier
  21. function getDefaultChannelName() {
  22. return `latest${getChannelFilePrefix()}`;
  23. }
  24. function getChannelFilePrefix() {
  25. return getCurrentPlatform() === "darwin" ? "-mac" : "";
  26. }
  27. function getCustomChannelName(channel) {
  28. return `${channel}${getChannelFilePrefix()}`;
  29. }
  30. function getCurrentPlatform() {
  31. return process.env.TEST_UPDATER_PLATFORM || process.platform;
  32. }
  33. function getChannelFilename(channel) {
  34. return `${channel}.${getCurrentPlatform() === "darwin" ? "json" : "yml"}`;
  35. }
  36. const DOWNLOAD_PROGRESS = exports.DOWNLOAD_PROGRESS = "download-progress";
  37. class UpdaterSignal {
  38. constructor(emitter) {
  39. this.emitter = emitter;
  40. }
  41. /**
  42. * Emitted when an authenticating proxy is asking for user credentials.
  43. * @see [Electron docs](https://github.com/electron/electron/blob/master/docs/api/client-request.md#event-login)
  44. */
  45. login(handler) {
  46. addHandler(this.emitter, "login", handler);
  47. }
  48. progress(handler) {
  49. addHandler(this.emitter, DOWNLOAD_PROGRESS, handler);
  50. }
  51. updateDownloaded(handler) {
  52. addHandler(this.emitter, "update-downloaded", handler);
  53. }
  54. updateCancelled(handler) {
  55. addHandler(this.emitter, "update-cancelled", handler);
  56. }
  57. }
  58. exports.UpdaterSignal = UpdaterSignal;
  59. const isLogEvent = false;
  60. function addHandler(emitter, event, handler) {
  61. if (isLogEvent) {
  62. emitter.on(event, function () {
  63. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  64. args[_key] = arguments[_key];
  65. }
  66. console.log("%s %s", event, args);
  67. handler.apply(null, args);
  68. });
  69. } else {
  70. emitter.on(event, handler);
  71. }
  72. }
  73. // url.format doesn't correctly use path and requires explicit pathname
  74. function formatUrl(url) {
  75. if (url.path != null && url.pathname == null) {
  76. url.pathname = url.path;
  77. }
  78. return (0, (_url || _load_url()).format)(url);
  79. }
  80. //# sourceMappingURL=api.js.map