electron-updater 4.3.5 → 4.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +22 -0
  2. package/out/AppAdapter.js +19 -28
  3. package/out/AppAdapter.js.map +1 -1
  4. package/out/AppImageUpdater.js +103 -173
  5. package/out/AppImageUpdater.js.map +1 -1
  6. package/out/AppUpdater.d.ts +1 -3
  7. package/out/AppUpdater.js +517 -773
  8. package/out/AppUpdater.js.map +1 -1
  9. package/out/BaseUpdater.js +79 -103
  10. package/out/BaseUpdater.js.map +1 -1
  11. package/out/DownloadedUpdateHelper.js +150 -224
  12. package/out/DownloadedUpdateHelper.js.map +1 -1
  13. package/out/ElectronAppAdapter.js +35 -63
  14. package/out/ElectronAppAdapter.js.map +1 -1
  15. package/out/MacUpdater.d.ts +1 -1
  16. package/out/MacUpdater.js +132 -182
  17. package/out/MacUpdater.js.map +1 -1
  18. package/out/NoOpLogger.d.ts +6 -0
  19. package/out/NoOpLogger.js +19 -0
  20. package/out/NoOpLogger.js.map +1 -0
  21. package/out/NsisUpdater.js +199 -331
  22. package/out/NsisUpdater.js.map +1 -1
  23. package/out/differentialDownloader/DataSplitter.js +180 -252
  24. package/out/differentialDownloader/DataSplitter.js.map +1 -1
  25. package/out/differentialDownloader/DifferentialDownloader.d.ts +3 -0
  26. package/out/differentialDownloader/DifferentialDownloader.js +243 -308
  27. package/out/differentialDownloader/DifferentialDownloader.js.map +1 -1
  28. package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js +29 -65
  29. package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js.map +1 -1
  30. package/out/differentialDownloader/GenericDifferentialDownloader.js +7 -21
  31. package/out/differentialDownloader/GenericDifferentialDownloader.js.map +1 -1
  32. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.d.ts +32 -0
  33. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js +90 -0
  34. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js.map +1 -0
  35. package/out/differentialDownloader/downloadPlanBuilder.js +99 -124
  36. package/out/differentialDownloader/downloadPlanBuilder.js.map +1 -1
  37. package/out/differentialDownloader/multipleRangeDownloader.js +99 -148
  38. package/out/differentialDownloader/multipleRangeDownloader.js.map +1 -1
  39. package/out/electronHttpExecutor.js +73 -106
  40. package/out/electronHttpExecutor.js.map +1 -1
  41. package/out/event.d.ts +35 -0
  42. package/out/event.js +39 -0
  43. package/out/event.js.map +1 -0
  44. package/out/log.d.ts +11 -0
  45. package/out/log.js +19 -0
  46. package/out/log.js.map +1 -0
  47. package/out/main.d.ts +1 -4
  48. package/out/main.js +60 -212
  49. package/out/main.js.map +1 -1
  50. package/out/providerFactory.js +49 -105
  51. package/out/providerFactory.js.map +1 -1
  52. package/out/providers/BintrayProvider.d.ts +2 -2
  53. package/out/providers/BintrayProvider.js +40 -95
  54. package/out/providers/BintrayProvider.js.map +1 -1
  55. package/out/providers/GenericProvider.d.ts +2 -2
  56. package/out/providers/GenericProvider.js +46 -80
  57. package/out/providers/GenericProvider.js.map +1 -1
  58. package/out/providers/GitHubProvider.d.ts +2 -2
  59. package/out/providers/GitHubProvider.js +122 -201
  60. package/out/providers/GitHubProvider.js.map +1 -1
  61. package/out/providers/PrivateGitHubProvider.js +87 -165
  62. package/out/providers/PrivateGitHubProvider.js.map +1 -1
  63. package/out/providers/Provider.js +122 -173
  64. package/out/providers/Provider.js.map +1 -1
  65. package/out/util.d.ts +5 -0
  66. package/out/util.js +42 -0
  67. package/out/util.js.map +1 -0
  68. package/out/windowsExecutableCodeSignatureVerifier.js +99 -139
  69. package/out/windowsExecutableCodeSignatureVerifier.js.map +1 -1
  70. package/package.json +33 -31
@@ -1,161 +1,112 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.executeTasksUsingMultipleRangeRequests = executeTasksUsingMultipleRangeRequests;
7
- exports.checkIsRangesSupported = checkIsRangesSupported;
8
-
9
- function _builderUtilRuntime() {
10
- const data = require("builder-util-runtime");
11
-
12
- _builderUtilRuntime = function () {
13
- return data;
14
- };
15
-
16
- return data;
17
- }
18
-
19
- function _DataSplitter() {
20
- const data = require("./DataSplitter");
21
-
22
- _DataSplitter = function () {
23
- return data;
24
- };
25
-
26
- return data;
27
- }
28
-
29
- function _downloadPlanBuilder() {
30
- const data = require("./downloadPlanBuilder");
31
-
32
- _downloadPlanBuilder = function () {
33
- return data;
34
- };
35
-
36
- return data;
37
- }
38
-
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIsRangesSupported = exports.executeTasksUsingMultipleRangeRequests = void 0;
4
+ const builder_util_runtime_1 = require("builder-util-runtime");
5
+ const DataSplitter_1 = require("./DataSplitter");
6
+ const downloadPlanBuilder_1 = require("./downloadPlanBuilder");
39
7
  function executeTasksUsingMultipleRangeRequests(differentialDownloader, tasks, out, oldFileFd, reject) {
40
- const w = taskOffset => {
41
- if (taskOffset >= tasks.length) {
42
- if (differentialDownloader.fileMetadataBuffer != null) {
43
- out.write(differentialDownloader.fileMetadataBuffer);
44
- }
45
-
46
- out.end();
47
- return;
48
- }
49
-
50
- const nextOffset = taskOffset + 1000;
51
- doExecuteTasks(differentialDownloader, {
52
- tasks,
53
- start: taskOffset,
54
- end: Math.min(tasks.length, nextOffset),
55
- oldFileFd
56
- }, out, () => w(nextOffset), reject);
57
- };
58
-
59
- return w;
8
+ const w = (taskOffset) => {
9
+ if (taskOffset >= tasks.length) {
10
+ if (differentialDownloader.fileMetadataBuffer != null) {
11
+ out.write(differentialDownloader.fileMetadataBuffer);
12
+ }
13
+ out.end();
14
+ return;
15
+ }
16
+ const nextOffset = taskOffset + 1000;
17
+ doExecuteTasks(differentialDownloader, {
18
+ tasks,
19
+ start: taskOffset,
20
+ end: Math.min(tasks.length, nextOffset),
21
+ oldFileFd,
22
+ }, out, () => w(nextOffset), reject);
23
+ };
24
+ return w;
60
25
  }
61
-
26
+ exports.executeTasksUsingMultipleRangeRequests = executeTasksUsingMultipleRangeRequests;
62
27
  function doExecuteTasks(differentialDownloader, options, out, resolve, reject) {
63
- let ranges = "bytes=";
64
- let partCount = 0;
65
- const partIndexToTaskIndex = new Map();
66
- const partIndexToLength = [];
67
-
68
- for (let i = options.start; i < options.end; i++) {
69
- const task = options.tasks[i];
70
-
71
- if (task.kind === _downloadPlanBuilder().OperationKind.DOWNLOAD) {
72
- ranges += `${task.start}-${task.end - 1}, `;
73
- partIndexToTaskIndex.set(partCount, i);
74
- partCount++;
75
- partIndexToLength.push(task.end - task.start);
28
+ let ranges = "bytes=";
29
+ let partCount = 0;
30
+ const partIndexToTaskIndex = new Map();
31
+ const partIndexToLength = [];
32
+ for (let i = options.start; i < options.end; i++) {
33
+ const task = options.tasks[i];
34
+ if (task.kind === downloadPlanBuilder_1.OperationKind.DOWNLOAD) {
35
+ ranges += `${task.start}-${task.end - 1}, `;
36
+ partIndexToTaskIndex.set(partCount, i);
37
+ partCount++;
38
+ partIndexToLength.push(task.end - task.start);
39
+ }
76
40
  }
77
- }
78
-
79
- if (partCount <= 1) {
80
- // the only remote range - copy
81
- const w = index => {
82
- if (index >= options.end) {
83
- resolve();
41
+ if (partCount <= 1) {
42
+ // the only remote range - copy
43
+ const w = (index) => {
44
+ if (index >= options.end) {
45
+ resolve();
46
+ return;
47
+ }
48
+ const task = options.tasks[index++];
49
+ if (task.kind === downloadPlanBuilder_1.OperationKind.COPY) {
50
+ DataSplitter_1.copyData(task, out, options.oldFileFd, reject, () => w(index));
51
+ }
52
+ else {
53
+ const requestOptions = differentialDownloader.createRequestOptions();
54
+ requestOptions.headers.Range = `bytes=${task.start}-${task.end - 1}`;
55
+ const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
56
+ if (!checkIsRangesSupported(response, reject)) {
57
+ return;
58
+ }
59
+ response.pipe(out, {
60
+ end: false,
61
+ });
62
+ response.once("end", () => w(index));
63
+ });
64
+ differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
65
+ request.end();
66
+ }
67
+ };
68
+ w(options.start);
84
69
  return;
85
- }
86
-
87
- const task = options.tasks[index++];
88
-
89
- if (task.kind === _downloadPlanBuilder().OperationKind.COPY) {
90
- (0, _DataSplitter().copyData)(task, out, options.oldFileFd, reject, () => w(index));
91
- } else {
92
- const requestOptions = differentialDownloader.createRequestOptions();
93
- requestOptions.headers.Range = `bytes=${task.start}-${task.end - 1}`;
94
- const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
95
- if (!checkIsRangesSupported(response, reject)) {
70
+ }
71
+ const requestOptions = differentialDownloader.createRequestOptions();
72
+ requestOptions.headers.Range = ranges.substring(0, ranges.length - 2);
73
+ const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
74
+ if (!checkIsRangesSupported(response, reject)) {
75
+ return;
76
+ }
77
+ const contentType = builder_util_runtime_1.safeGetHeader(response, "content-type");
78
+ const m = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i.exec(contentType);
79
+ if (m == null) {
80
+ reject(new Error(`Content-Type "multipart/byteranges" is expected, but got "${contentType}"`));
96
81
  return;
97
- }
98
-
99
- response.pipe(out, {
100
- end: false
101
- });
102
- response.once("end", () => w(index));
82
+ }
83
+ const dicer = new DataSplitter_1.DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve);
84
+ dicer.on("error", reject);
85
+ response.pipe(dicer);
86
+ response.on("end", () => {
87
+ setTimeout(() => {
88
+ request.abort();
89
+ reject(new Error("Response ends without calling any handlers"));
90
+ }, 10000);
103
91
  });
104
- differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
105
- request.end();
106
- }
107
- };
108
-
109
- w(options.start);
110
- return;
111
- }
112
-
113
- const requestOptions = differentialDownloader.createRequestOptions();
114
- requestOptions.headers.Range = ranges.substring(0, ranges.length - 2);
115
- const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
116
- if (!checkIsRangesSupported(response, reject)) {
117
- return;
118
- }
119
-
120
- const contentType = (0, _builderUtilRuntime().safeGetHeader)(response, "content-type");
121
- const m = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i.exec(contentType);
122
-
123
- if (m == null) {
124
- reject(new Error(`Content-Type "multipart/byteranges" is expected, but got "${contentType}"`));
125
- return;
126
- }
127
-
128
- const dicer = new (_DataSplitter().DataSplitter)(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve);
129
- dicer.on("error", reject);
130
- response.pipe(dicer);
131
- response.on('end', () => {
132
- setTimeout(() => {
133
- request.abort();
134
- reject(new Error("Response ends without calling any handlers"));
135
- }, 10000);
136
92
  });
137
- });
138
- differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
139
- request.end();
93
+ differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
94
+ request.end();
140
95
  }
141
-
142
96
  function checkIsRangesSupported(response, reject) {
143
- // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.
144
- if (response.statusCode >= 400) {
145
- reject((0, _builderUtilRuntime().createHttpError)(response));
146
- return false;
147
- }
148
-
149
- if (response.statusCode !== 206) {
150
- const acceptRanges = (0, _builderUtilRuntime().safeGetHeader)(response, "accept-ranges");
151
-
152
- if (acceptRanges == null || acceptRanges === "none") {
153
- reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`));
154
- return false;
97
+ // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.
98
+ if (response.statusCode >= 400) {
99
+ reject(builder_util_runtime_1.createHttpError(response));
100
+ return false;
101
+ }
102
+ if (response.statusCode !== 206) {
103
+ const acceptRanges = builder_util_runtime_1.safeGetHeader(response, "accept-ranges");
104
+ if (acceptRanges == null || acceptRanges === "none") {
105
+ reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`));
106
+ return false;
107
+ }
155
108
  }
156
- }
157
-
158
- return true;
159
- }
160
- // __ts-babel@6.0.4
109
+ return true;
110
+ }
111
+ exports.checkIsRangesSupported = checkIsRangesSupported;
161
112
  //# sourceMappingURL=multipleRangeDownloader.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/differentialDownloader/multipleRangeDownloader.ts"],"names":[],"mappings":";;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEM,SAAU,sCAAV,CAAiD,sBAAjD,EAAiG,KAAjG,EAA0H,GAA1H,EAAyI,SAAzI,EAA4J,MAA5J,EAA0L;AAC9L,QAAM,CAAC,GAAI,UAAD,IAA6B;AACrC,QAAI,UAAU,IAAI,KAAK,CAAC,MAAxB,EAAgC;AAC9B,UAAI,sBAAsB,CAAC,kBAAvB,IAA6C,IAAjD,EAAuD;AACrD,QAAA,GAAG,CAAC,KAAJ,CAAU,sBAAsB,CAAC,kBAAjC;AACD;;AACD,MAAA,GAAG,CAAC,GAAJ;AACA;AACD;;AAED,UAAM,UAAU,GAAG,UAAU,GAAG,IAAhC;AACA,IAAA,cAAc,CAAC,sBAAD,EAAyB;AACrC,MAAA,KADqC;AAErC,MAAA,KAAK,EAAE,UAF8B;AAGrC,MAAA,GAAG,EAAE,IAAI,CAAC,GAAL,CAAS,KAAK,CAAC,MAAf,EAAuB,UAAvB,CAHgC;AAIrC,MAAA;AAJqC,KAAzB,EAKX,GALW,EAKN,MAAM,CAAC,CAAC,UAAD,CALD,EAKe,MALf,CAAd;AAMD,GAhBD;;AAiBA,SAAO,CAAP;AACD;;AAED,SAAS,cAAT,CAAwB,sBAAxB,EAAwE,OAAxE,EAAmG,GAAnG,EAAkH,OAAlH,EAAuI,MAAvI,EAAqK;AACnK,MAAI,MAAM,GAAG,QAAb;AACA,MAAI,SAAS,GA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OAAtF,CAAd;AACA,IAAA,KAAK,CAAC,EAAN,CAAS,OAAT,EAAkB,MAAlB;AACA,IAAA,QAAQ,CAAC,IAAT,CAAc,KAAd;AAEA,IAAA,QAAQ,CAAC,EAAT,CAAY,KAAZ,EAAmB,MAAK;AACtB,MAAA,UAAU,CAAC,MAAK;AACd,QAAA,OAAO,CAAC,KAAR;AACA,QAAA,MAAM,CAAC,IAAI,KAAJ,CAAU,4CAAV,CAAD,CAAN;AACD,OAHS,EAGP,KAHO,CAAV;AAID,KALD;AAMD,GAtBe,CAAhB;AAuBA,EAAA,sBAAsB,CAAC,YAAvB,CAAoC,0BAApC,CAA+D,OAA/D,EAAwE,MAAxE;AACA,EAAA,OAAO,CAAC,GAAR;AACD;;AAEK,SAAU,sBAAV,CAAiC,QAAjC,EAA4D,MAA5D,EAA0F;AAC9F;AACA,MAAI,QAAQ,CAAC,UAAT,IAAyB,GAA7B,EAAkC;AAChC,IAAA,MAAM,CAAC,2CAAgB,QAAhB,CAAD,CAAN;AACA,WAAO,KAAP;AACD;;AAED,MAAI,QAAQ,CAAC,UAAT,KAAwB,GAA5B,EAAiC;AAC/B,UAAM,YAAY,GAAG,yCAAc,QAAd,EAAwB,eAAxB,CAArB;;AACA,QAAI,YAAY,IAAI,IAAhB,IAAwB,YAAY,KAAK,MAA7C,EAAqD;AACnD,MAAA,MAAM,CAAC,IAAI,KAAJ,CAAU,uDAAuD,QAAQ,CAAC,UAAU,GAApF,CAAD,CAAN;AACA,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD,C","sourcesContent":["import { createHttpError, safeGetHeader } from \"builder-util-runtime\"\nimport { IncomingMessage } from \"http\"\nimport { Writable } from \"stream\"\nimport { copyData, DataSplitter, PartListDataTask } from \"./DataSplitter\"\nimport { DifferentialDownloader } from \"./DifferentialDownloader\"\nimport { Operation, OperationKind } from \"./downloadPlanBuilder\"\n\nexport function executeTasksUsingMultipleRangeRequests(differentialDownloader: DifferentialDownloader, tasks: Array<Operation>, out: Writable, oldFileFd: number, reject: (error: Error) => void): (taskOffset: number) => void {\n const w = (taskOffset: number): void => {\n if (taskOffset >= tasks.length) {\n if (differentialDownloader.fileMetadataBuffer != null) {\n out.write(differentialDownloader.fileMetadataBuffer)\n }\n out.end()\n return\n }\n\n const nextOffset = taskOffset + 1000\n doExecuteTasks(differentialDownloader, {\n tasks,\n start: taskOffset,\n end: Math.min(tasks.length, nextOffset),\n oldFileFd,\n }, out, () => w(nextOffset), reject)\n }\n return w\n}\n\nfunction doExecuteTasks(differentialDownloader: DifferentialDownloader, options: PartListDataTask, out: Writable, resolve: () => void, reject: (error: Error) => void): void {\n let ranges = \"bytes=\"\n let partCount = 0\n const partIndexToTaskIndex = new Map<number, number>()\n const partIndexToLength: Array<number> = []\n for (let i = options.start; i < options.end; i++) {\n const task = options.tasks[i]\n if (task.kind === OperationKind.DOWNLOAD) {\n ranges += `${task.start}-${task.end - 1}, `\n partIndexToTaskIndex.set(partCount, i)\n partCount++\n partIndexToLength.push(task.end - task.start)\n }\n }\n\n if (partCount <= 1) {\n // the only remote range - copy\n const w = (index: number): void => {\n if (index >= options.end) {\n resolve()\n return\n }\n\n const task = options.tasks[index++]\n\n if (task.kind === OperationKind.COPY) {\n copyData(task, out, options.oldFileFd, reject, () => w(index))\n }\n else {\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!!.Range = `bytes=${task.start}-${task.end - 1}`\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n response.pipe(out, {\n end: false\n })\n response.once(\"end\", () => w(index))\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n }\n }\n\n w(options.start)\n return\n }\n\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!!.Range = ranges.substring(0, ranges.length - 2)\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n const contentType = safeGetHeader(response, \"content-type\")\n const m = /^multipart\\/.+?(?:; boundary=(?:(?:\"(.+)\")|(?:([^\\s]+))))$/i.exec(contentType)\n if (m == null) {\n reject(new Error(`Content-Type \"multipart/byteranges\" is expected, but got \"${contentType}\"`))\n return\n }\n\n const dicer = new DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve)\n dicer.on(\"error\", reject)\n response.pipe(dicer)\n\n response.on('end', () => {\n setTimeout(() => {\n request.abort()\n reject(new Error(\"Response ends without calling any handlers\"))\n }, 10000)\n })\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n}\n\nexport function checkIsRangesSupported(response: IncomingMessage, reject: (error: Error) => void): boolean {\n // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.\n if (response.statusCode!! >= 400) {\n reject(createHttpError(response))\n return false\n }\n\n if (response.statusCode !== 206) {\n const acceptRanges = safeGetHeader(response, \"accept-ranges\")\n if (acceptRanges == null || acceptRanges === \"none\") {\n reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`))\n return false\n }\n }\n return true\n}\n"],"sourceRoot":""}
1
+ {"version":3,"file":"multipleRangeDownloader.js","sourceRoot":"","sources":["../../src/differentialDownloader/multipleRangeDownloader.ts"],"names":[],"mappings":";;;AAAA,+DAAqE;AAGrE,iDAAyE;AAEzE,+DAAgE;AAEhE,SAAgB,sCAAsC,CACpD,sBAA8C,EAC9C,KAAuB,EACvB,GAAa,EACb,SAAiB,EACjB,MAA8B;IAE9B,MAAM,CAAC,GAAG,CAAC,UAAkB,EAAQ,EAAE;QACrC,IAAI,UAAU,IAAI,KAAK,CAAC,MAAM,EAAE;YAC9B,IAAI,sBAAsB,CAAC,kBAAkB,IAAI,IAAI,EAAE;gBACrD,GAAG,CAAC,KAAK,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAA;aACrD;YACD,GAAG,CAAC,GAAG,EAAE,C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,CAAC,QAAyB,EAAE,MAA8B;IAC9F,6HAA6H;IAC7H,IAAI,QAAQ,CAAC,UAAW,IAAI,GAAG,EAAE;QAC/B,MAAM,CAAC,sCAAe,CAAC,QAAQ,CAAC,CAAC,CAAA;QACjC,OAAO,KAAK,CAAA;KACb;IAED,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE;QAC/B,MAAM,YAAY,GAAG,oCAAa,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QAC7D,IAAI,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,MAAM,EAAE;YACnD,MAAM,CAAC,IAAI,KAAK,CAAC,uDAAuD,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;YAChG,OAAO,KAAK,CAAA;SACb;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAfD,wDAeC","sourcesContent":["import { createHttpError, safeGetHeader } from \"builder-util-runtime\"\nimport { IncomingMessage } from \"http\"\nimport { Writable } from \"stream\"\nimport { copyData, DataSplitter, PartListDataTask } from \"./DataSplitter\"\nimport { DifferentialDownloader } from \"./DifferentialDownloader\"\nimport { Operation, OperationKind } from \"./downloadPlanBuilder\"\n\nexport function executeTasksUsingMultipleRangeRequests(\n differentialDownloader: DifferentialDownloader,\n tasks: Array<Operation>,\n out: Writable,\n oldFileFd: number,\n reject: (error: Error) => void\n): (taskOffset: number) => void {\n const w = (taskOffset: number): void => {\n if (taskOffset >= tasks.length) {\n if (differentialDownloader.fileMetadataBuffer != null) {\n out.write(differentialDownloader.fileMetadataBuffer)\n }\n out.end()\n return\n }\n\n const nextOffset = taskOffset + 1000\n doExecuteTasks(\n differentialDownloader,\n {\n tasks,\n start: taskOffset,\n end: Math.min(tasks.length, nextOffset),\n oldFileFd,\n },\n out,\n () => w(nextOffset),\n reject\n )\n }\n return w\n}\n\nfunction doExecuteTasks(differentialDownloader: DifferentialDownloader, options: PartListDataTask, out: Writable, resolve: () => void, reject: (error: Error) => void): void {\n let ranges = \"bytes=\"\n let partCount = 0\n const partIndexToTaskIndex = new Map<number, number>()\n const partIndexToLength: Array<number> = []\n for (let i = options.start; i < options.end; i++) {\n const task = options.tasks[i]\n if (task.kind === OperationKind.DOWNLOAD) {\n ranges += `${task.start}-${task.end - 1}, `\n partIndexToTaskIndex.set(partCount, i)\n partCount++\n partIndexToLength.push(task.end - task.start)\n }\n }\n\n if (partCount <= 1) {\n // the only remote range - copy\n const w = (index: number): void => {\n if (index >= options.end) {\n resolve()\n return\n }\n\n const task = options.tasks[index++]\n\n if (task.kind === OperationKind.COPY) {\n copyData(task, out, options.oldFileFd, reject, () => w(index))\n } else {\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!.Range = `bytes=${task.start}-${task.end - 1}`\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n response.pipe(out, {\n end: false,\n })\n response.once(\"end\", () => w(index))\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n }\n }\n\n w(options.start)\n return\n }\n\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!.Range = ranges.substring(0, ranges.length - 2)\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n const contentType = safeGetHeader(response, \"content-type\")\n const m = /^multipart\\/.+?(?:; boundary=(?:(?:\"(.+)\")|(?:([^\\s]+))))$/i.exec(contentType)\n if (m == null) {\n reject(new Error(`Content-Type \"multipart/byteranges\" is expected, but got \"${contentType}\"`))\n return\n }\n\n const dicer = new DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve)\n dicer.on(\"error\", reject)\n response.pipe(dicer)\n\n response.on(\"end\", () => {\n setTimeout(() => {\n request.abort()\n reject(new Error(\"Response ends without calling any handlers\"))\n }, 10000)\n })\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n}\n\nexport function checkIsRangesSupported(response: IncomingMessage, reject: (error: Error) => void): boolean {\n // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.\n if (response.statusCode! >= 400) {\n reject(createHttpError(response))\n return false\n }\n\n if (response.statusCode !== 206) {\n const acceptRanges = safeGetHeader(response, \"accept-ranges\")\n if (acceptRanges == null || acceptRanges === \"none\") {\n reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`))\n return false\n }\n }\n return true\n}\n"]}
@@ -1,112 +1,79 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getNetSession = getNetSession;
7
- exports.ElectronHttpExecutor = exports.NET_SESSION_NAME = void 0;
8
-
9
- function _builderUtilRuntime() {
10
- const data = require("builder-util-runtime");
11
-
12
- _builderUtilRuntime = function () {
13
- return data;
14
- };
15
-
16
- return data;
17
- }
18
-
19
- function _electron() {
20
- const data = require("electron");
21
-
22
- _electron = function () {
23
- return data;
24
- };
25
-
26
- return data;
27
- }
28
-
29
- const NET_SESSION_NAME = "electron-updater";
30
- exports.NET_SESSION_NAME = NET_SESSION_NAME;
31
-
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ElectronHttpExecutor = exports.getNetSession = exports.NET_SESSION_NAME = void 0;
4
+ const builder_util_runtime_1 = require("builder-util-runtime");
5
+ exports.NET_SESSION_NAME = "electron-updater";
32
6
  function getNetSession() {
33
- return _electron().session.fromPartition(NET_SESSION_NAME, {
34
- cache: false
35
- });
36
- }
37
-
38
- class ElectronHttpExecutor extends _builderUtilRuntime().HttpExecutor {
39
- constructor(proxyLoginCallback) {
40
- super();
41
- this.proxyLoginCallback = proxyLoginCallback;
42
- this.cachedSession = null;
43
- }
44
-
45
- async download(url, destination, options) {
46
- return await options.cancellationToken.createPromise((resolve, reject, onCancel) => {
47
- const requestOptions = {
48
- headers: options.headers || undefined,
49
- redirect: "manual"
50
- };
51
- (0, _builderUtilRuntime().configureRequestUrl)(url, requestOptions);
52
- (0, _builderUtilRuntime().configureRequestOptions)(requestOptions);
53
- this.doDownload(requestOptions, {
54
- destination,
55
- options,
56
- onCancel,
57
- callback: error => {
58
- if (error == null) {
59
- resolve(destination);
60
- } else {
61
- reject(error);
62
- }
63
- },
64
- responseHandler: null
65
- }, 0);
7
+ return require("electron").session.fromPartition(exports.NET_SESSION_NAME, {
8
+ cache: false,
66
9
  });
67
- }
68
-
69
- createRequest(options, callback) {
70
- // fix (node 7+) for making electron updater work when using AWS private buckets, check if headers contain Host property
71
- if (options.headers && options.headers.Host) {
72
- // set host value from headers.Host
73
- options.host = options.headers.Host; // remove header property 'Host', if not removed causes net::ERR_INVALID_ARGUMENT exception
74
-
75
- delete options.headers.Host;
76
- } // differential downloader can call this method very often, so, better to cache session
77
-
78
-
79
- if (this.cachedSession == null) {
80
- this.cachedSession = getNetSession();
10
+ }
11
+ exports.getNetSession = getNetSession;
12
+ class ElectronHttpExecutor extends builder_util_runtime_1.HttpExecutor {
13
+ constructor(proxyLoginCallback) {
14
+ super();
15
+ this.proxyLoginCallback = proxyLoginCallback;
16
+ this.cachedSession = null;
81
17
  }
82
-
83
- const request = _electron().net.request({ ...options,
84
- session: this.cachedSession
85
- });
86
-
87
- request.on("response", callback);
88
-
89
- if (this.proxyLoginCallback != null) {
90
- request.on("login", this.proxyLoginCallback);
18
+ async download(url, destination, options) {
19
+ return await options.cancellationToken.createPromise((resolve, reject, onCancel) => {
20
+ const requestOptions = {
21
+ headers: options.headers || undefined,
22
+ redirect: "manual",
23
+ };
24
+ builder_util_runtime_1.configureRequestUrl(url, requestOptions);
25
+ builder_util_runtime_1.configureRequestOptions(requestOptions);
26
+ this.doDownload(requestOptions, {
27
+ destination,
28
+ options,
29
+ onCancel,
30
+ callback: error => {
31
+ if (error == null) {
32
+ resolve(destination);
33
+ }
34
+ else {
35
+ reject(error);
36
+ }
37
+ },
38
+ responseHandler: null,
39
+ }, 0);
40
+ });
91
41
  }
92
-
93
- return request;
94
- }
95
-
96
- addRedirectHandlers(request, options, reject, redirectCount, handler) {
97
- request.on("redirect", (statusCode, method, redirectUrl) => {
98
- // no way to modify request options, abort old and make a new one
99
- // https://github.com/electron/electron/issues/11505
100
- request.abort();
101
-
102
- if (redirectCount > this.maxRedirects) {
103
- reject(this.createMaxRedirectError());
104
- } else {
105
- handler(_builderUtilRuntime().HttpExecutor.prepareRedirectUrlOptions(redirectUrl, options));
106
- }
107
- });
108
- }
109
-
110
- } exports.ElectronHttpExecutor = ElectronHttpExecutor;
111
- // __ts-babel@6.0.4
42
+ createRequest(options, callback) {
43
+ // fix (node 7+) for making electron updater work when using AWS private buckets, check if headers contain Host property
44
+ if (options.headers && options.headers.Host) {
45
+ // set host value from headers.Host
46
+ options.host = options.headers.Host;
47
+ // remove header property 'Host', if not removed causes net::ERR_INVALID_ARGUMENT exception
48
+ delete options.headers.Host;
49
+ }
50
+ // differential downloader can call this method very often, so, better to cache session
51
+ if (this.cachedSession == null) {
52
+ this.cachedSession = getNetSession();
53
+ }
54
+ const request = require("electron").net.request({
55
+ ...options,
56
+ session: this.cachedSession,
57
+ });
58
+ request.on("response", callback);
59
+ if (this.proxyLoginCallback != null) {
60
+ request.on("login", this.proxyLoginCallback);
61
+ }
62
+ return request;
63
+ }
64
+ addRedirectHandlers(request, options, reject, redirectCount, handler) {
65
+ request.on("redirect", (statusCode, method, redirectUrl) => {
66
+ // no way to modify request options, abort old and make a new one
67
+ // https://github.com/electron/electron/issues/11505
68
+ request.abort();
69
+ if (redirectCount > this.maxRedirects) {
70
+ reject(this.createMaxRedirectError());
71
+ }
72
+ else {
73
+ handler(builder_util_runtime_1.HttpExecutor.prepareRedirectUrlOptions(redirectUrl, options));
74
+ }
75
+ });
76
+ }
77
+ }
78
+ exports.ElectronHttpExecutor = ElectronHttpExecutor;
112
79
  //# sourceMappingURL=electronHttpExecutor.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/electronHttpExecutor.ts"],"names":[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AAC,OAAR,CAAgB,IAAvC,EAA4C;AAC1C;AACA,MAAA,OAAO,CAAC,IAAR,GAAe,OAAO,CAAC,OAAR,CAAgB,IAA/B,CAF0C,CAG1C;;AACA,aAAO,OAAO,CAAC,OAAR,CAAgB,IAAvB;AACD,KAR0D,CAU3D;;;AACA,QAAI,KAAK,aAAL,IAAsB,IAA1B,EAAgC;AAC9B,WAAK,aAAL,GAAqB,aAAa,EAAlC;AACD;;AAED,UAAM,OAAO,GAAG,gBAAI,OAAJ,CAAY,EAC1B,GAAG,OADuB;AAE1B,MAAA,OAAO,EAAE,KAAK;AAFY,KAAZ,CAAhB;;AAIA,IAAA,OAAO,CAAC,EAAR,CAAW,UAAX,EAAuB,QAAvB;;AACA,QAAI,KAAK,kBAAL,IAA2B,IAA/B,EAAqC;AACnC,MAAA,OAAO,CAAC,EAAR,CAAW,OAAX,EAAoB,KAAK,kBAAzB;AACD;;AACD,WAAO,OAAP;AACD;;AAES,EAAA,mBAAmB,CAAC,OAAD,EAAyB,OAAzB,EAAkD,MAAlD,EAAkF,aAAlF,EAAyG,OAAzG,EAAmJ;AAC9K,IAAA,OAAO,CAAC,EAAR,CAAW,UAAX,EAAuB,CAAC,UAAD,EAAqB,MAArB,EAAqC,WAArC,KAA4D;AACjF;AACA;AACA,MAAA,OAAO,CAAC,KAAR;;AAEA,UAAI,aAAa,GAAG,KAAK,YAAzB,EAAuC;AACrC,QAAA,MAAM,CAAC,KAAK,sBAAL,EAAD,CAAN;AACD,OAFD,MAGK;AACH,QAAA,OAAO,CAAC,mCAAa,yBAAb,CAAuC,WAAvC,EAAoD,OAApD,CAAD,CAAP;AACD;AACF,KAXD;AAYD;;AAvE2E,C","sourcesContent":["import { DownloadOptions, HttpExecutor, configureRequestOptions, configureRequestUrl } from \"builder-util-runtime\"\nimport { net, session } from \"electron\"\nimport { RequestOptions } from \"http\"\nimport Session = Electron.Session\nimport ClientRequest = Electron.ClientRequest\n\nexport type LoginCallback = (username: string, password: string) => void\nexport const NET_SESSION_NAME = \"electron-updater\"\n\nexport function getNetSession(): Session {\n return session.fromPartition(NET_SESSION_NAME, {\n cache: false\n })\n}\n\nexport class ElectronHttpExecutor extends HttpExecutor<Electron.ClientRequest> {\n private cachedSession: Session | null = null\n\n constructor(private readonly proxyLoginCallback?: (authInfo: any, callback: LoginCallback) => void) {\n super()\n }\n\n async download(url: URL, destination: string, options: DownloadOptions): Promise<string> {\n return await options.cancellationToken.createPromise<string>((resolve, reject, onCancel) => {\n const requestOptions = {\n headers: options.headers || undefined,\n redirect: \"manual\",\n }\n configureRequestUrl(url, requestOptions)\n configureRequestOptions(requestOptions)\n this.doDownload(requestOptions, {\n destination,\n options,\n onCancel,\n callback: error => {\n if (error == null) {\n resolve(destination)\n }\n else {\n reject(error)\n }\n },\n responseHandler: null,\n }, 0)\n })\n }\n\n createRequest(options: any, callback: (response: any) => void): any {\n\n // fix (node 7+) for making electron updater work when using AWS private buckets, check if headers contain Host property\n if (options.headers && options.headers.Host){\n // set host value from headers.Host\n options.host = options.headers.Host\n // remove header property 'Host', if not removed causes net::ERR_INVALID_ARGUMENT exception\n delete options.headers.Host;\n }\n\n // differential downloader can call this method very often, so, better to cache session\n if (this.cachedSession == null) {\n this.cachedSession = getNetSession()\n }\n\n const request = net.request({\n ...options,\n session: this.cachedSession,\n })\n request.on(\"response\", callback)\n if (this.proxyLoginCallback != null) {\n request.on(\"login\", this.proxyLoginCallback)\n }\n return request\n }\n\n protected addRedirectHandlers(request: ClientRequest, options: RequestOptions, reject: (error: Error) => void, redirectCount: number, handler: (options: RequestOptions) => void): void {\n request.on(\"redirect\", (statusCode: number, method: string, redirectUrl: string) => {\n // no way to modify request options, abort old and make a new one\n // https://github.com/electron/electron/issues/11505\n request.abort()\n\n if (redirectCount > this.maxRedirects) {\n reject(this.createMaxRedirectError())\n }\n else {\n handler(HttpExecutor.prepareRedirectUrlOptions(redirectUrl, options))\n }\n })\n }\n}"],"sourceRoot":""}
1
+ {"version":3,"file":"electronHttpExec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utor, configureRequestOptions, configureRequestUrl } from \"builder-util-runtime\"\nimport { RequestOptions } from \"http\"\nimport Session = Electron.Session\nimport ClientRequest = Electron.ClientRequest\n\nexport type LoginCallback = (username: string, password: string) => void\nexport const NET_SESSION_NAME = \"electron-updater\"\n\nexport function getNetSession(): Session {\n return require(\"electron\").session.fromPartition(NET_SESSION_NAME, {\n cache: false,\n })\n}\n\nexport class ElectronHttpExecutor extends HttpExecutor<Electron.ClientRequest> {\n private cachedSession: Session | null = null\n\n constructor(private readonly proxyLoginCallback?: (authInfo: any, callback: LoginCallback) => void) {\n super()\n }\n\n async download(url: URL, destination: string, options: DownloadOptions): Promise<string> {\n return await options.cancellationToken.createPromise<string>((resolve, reject, onCancel) => {\n const requestOptions = {\n headers: options.headers || undefined,\n redirect: \"manual\",\n }\n configureRequestUrl(url, requestOptions)\n configureRequestOptions(requestOptions)\n this.doDownload(\n requestOptions,\n {\n destination,\n options,\n onCancel,\n callback: error => {\n if (error == null) {\n resolve(destination)\n } else {\n reject(error)\n }\n },\n responseHandler: null,\n },\n 0\n )\n })\n }\n\n createRequest(options: any, callback: (response: any) => void): any {\n // fix (node 7+) for making electron updater work when using AWS private buckets, check if headers contain Host property\n if (options.headers && options.headers.Host) {\n // set host value from headers.Host\n options.host = options.headers.Host\n // remove header property 'Host', if not removed causes net::ERR_INVALID_ARGUMENT exception\n delete options.headers.Host\n }\n\n // differential downloader can call this method very often, so, better to cache session\n if (this.cachedSession == null) {\n this.cachedSession = getNetSession()\n }\n\n const request = require(\"electron\").net.request({\n ...options,\n session: this.cachedSession,\n })\n request.on(\"response\", callback)\n if (this.proxyLoginCallback != null) {\n request.on(\"login\", this.proxyLoginCallback)\n }\n return request\n }\n\n protected addRedirectHandlers(\n request: ClientRequest,\n options: RequestOptions,\n reject: (error: Error) => void,\n redirectCount: number,\n handler: (options: RequestOptions) => void\n ): void {\n request.on(\"redirect\", (statusCode: number, method: string, redirectUrl: string) => {\n // no way to modify request options, abort old and make a new one\n // https://github.com/electron/electron/issues/11505\n request.abort()\n\n if (redirectCount > this.maxRedirects) {\n reject(this.createMaxRedirectError())\n } else {\n handler(HttpExecutor.prepareRedirectUrlOptions(redirectUrl, options))\n }\n })\n }\n}\n"]}
package/out/event.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ import { CancellationToken, PackageFileInfo, ProgressInfo, UpdateFileInfo, UpdateInfo } from "builder-util-runtime";
3
+ import { EventEmitter } from "events";
4
+ import { URL } from "url";
5
+ import { LoginCallback } from "./electronHttpExecutor";
6
+ export declare type UpdaterEvents = "login" | "checking-for-update" | "update-available" | "update-cancelled" | "download-progress" | "update-downloaded" | "error";
7
+ export declare const DOWNLOAD_PROGRESS: UpdaterEvents;
8
+ export declare const UPDATE_DOWNLOADED: UpdaterEvents;
9
+ export declare type LoginHandler = (authInfo: any, callback: LoginCallback) => void;
10
+ export declare class UpdaterSignal {
11
+ private emitter;
12
+ constructor(emitter: EventEmitter);
13
+ /**
14
+ * Emitted when an authenticating proxy is [asking for user credentials](https://github.com/electron/electron/blob/master/docs/api/client-request.md#event-login).
15
+ */
16
+ login(handler: LoginHandler): void;
17
+ progress(handler: (info: ProgressInfo) => void): void;
18
+ updateDownloaded(handler: (info: UpdateDownloadedEvent) => void): void;
19
+ updateCancelled(handler: (info: UpdateInfo) => void): void;
20
+ }
21
+ export interface UpdateCheckResult {
22
+ readonly updateInfo: UpdateInfo;
23
+ readonly downloadPromise?: Promise<Array<string>> | null;
24
+ readonly cancellationToken?: CancellationToken;
25
+ /** @deprecated */
26
+ readonly versionInfo: UpdateInfo;
27
+ }
28
+ export interface ResolvedUpdateFileInfo {
29
+ readonly url: URL;
30
+ readonly info: UpdateFileInfo;
31
+ packageInfo?: PackageFileInfo;
32
+ }
33
+ export interface UpdateDownloadedEvent extends UpdateInfo {
34
+ downloadedFile: string;
35
+ }
package/out/event.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdaterSignal = exports.UPDATE_DOWNLOADED = exports.DOWNLOAD_PROGRESS = void 0;
4
+ exports.DOWNLOAD_PROGRESS = "download-progress";
5
+ exports.UPDATE_DOWNLOADED = "update-downloaded";
6
+ class UpdaterSignal {
7
+ constructor(emitter) {
8
+ this.emitter = emitter;
9
+ }
10
+ /**
11
+ * Emitted when an authenticating proxy is [asking for user credentials](https://github.com/electron/electron/blob/master/docs/api/client-request.md#event-login).
12
+ */
13
+ login(handler) {
14
+ addHandler(this.emitter, "login", handler);
15
+ }
16
+ progress(handler) {
17
+ addHandler(this.emitter, exports.DOWNLOAD_PROGRESS, handler);
18
+ }
19
+ updateDownloaded(handler) {
20
+ addHandler(this.emitter, exports.UPDATE_DOWNLOADED, handler);
21
+ }
22
+ updateCancelled(handler) {
23
+ addHandler(this.emitter, "update-cancelled", handler);
24
+ }
25
+ }
26
+ exports.UpdaterSignal = UpdaterSignal;
27
+ const isLogEvent = false;
28
+ function addHandler(emitter, event, handler) {
29
+ if (isLogEvent) {
30
+ emitter.on(event, (...args) => {
31
+ console.log("%s %s", event, args);
32
+ handler(...args);
33
+ });
34
+ }
35
+ else {
36
+ emitter.on(event, handler);
37
+ }
38
+ }
39
+ //# sourceMappingURL=event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":";;;AAOa,QAAA,iBAAiB,GAAkB,mBAAmB,CAAA;AACtD,QAAA,iBAAiB,GAAkB,mBAAmB,CAAA;AAInE,MAAa,aAAa;IACxB,YAAoB,OAAqB;QAArB,YAAO,GAAP,OAAO,CAAc;IAAG,CAAC;IAE7C;;OAEG;IACH,KAAK,CAAC,OAAqB;QACzB,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5C,CAAC;IAED,QAAQ,CAAC,OAAqC;QAC5C,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,yBAAiB,EAAE,OAAO,CAAC,CAAA;IACtD,CAAC;IAED,gBAAgB,CAAC,OAA8C;QAC7D,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,yBAAiB,EAAE,OAAO,CAAC,CAAA;IACtD,CAAC;IAED,eAAe,CAAC,OAAmC;QACjD,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAA;IACvD,CAAC;CACF;AArBD,sCAqBC;AAED,MAAM,UAAU,GAAG,KAAK,CAAA;AAExB,SAAS,UAAU,CAAC,OAAqB,EAAE,KAAoB,EAAE,OAAsC;IACrG,IAAI,UAAU,EAAE;QACd,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAgB,EAAE,EAAE;YACxC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;YACjC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;KACH;SAAM;QACL,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;KAC3B;AACH,CAAC","sourcesContent":["import { CancellationToken, PackageFileInfo, ProgressInfo, UpdateFileInfo, UpdateInfo } from \"builder-util-runtime\"\nimport { EventEmitter } from \"events\"\nimport { URL } from \"url\"\nimport { LoginCallback } from \"./electronHttpExecutor\"\n\nexport type UpdaterEvents = \"login\" | \"checking-for-update\" | \"update-available\" | \"update-cancelled\" | \"download-progress\" | \"update-downloaded\" | \"error\"\n\nexport const DOWNLOAD_PROGRESS: UpdaterEvents = \"download-progress\"\nexport const UPDATE_DOWNLOADED: UpdaterEvents = \"update-downloaded\"\n\nexport type LoginHandler = (authInfo: any, callback: LoginCallback) => void\n\nexport class UpdaterSignal {\n constructor(private emitter: EventEmitter) {}\n\n /**\n * Emitted when an authenticating proxy is [asking for user credentials](https://github.com/electron/electron/blob/master/docs/api/client-request.md#event-login).\n */\n login(handler: LoginHandler): void {\n addHandler(this.emitter, \"login\", handler)\n }\n\n progress(handler: (info: ProgressInfo) => void): void {\n addHandler(this.emitter, DOWNLOAD_PROGRESS, handler)\n }\n\n updateDownloaded(handler: (info: UpdateDownloadedEvent) => void): void {\n addHandler(this.emitter, UPDATE_DOWNLOADED, handler)\n }\n\n updateCancelled(handler: (info: UpdateInfo) => void): void {\n addHandler(this.emitter, \"update-cancelled\", handler)\n }\n}\n\nconst isLogEvent = false\n\nfunction addHandler(emitter: EventEmitter, event: UpdaterEvents, handler: (...args: Array<any>) => void): void {\n if (isLogEvent) {\n emitter.on(event, (...args: Array<any>) => {\n console.log(\"%s %s\", event, args)\n handler(...args)\n })\n } else {\n emitter.on(event, handler)\n }\n}\n\nexport interface UpdateCheckResult {\n readonly updateInfo: UpdateInfo\n\n readonly downloadPromise?: Promise<Array<string>> | null\n\n readonly cancellationToken?: CancellationToken\n\n /** @deprecated */\n readonly versionInfo: UpdateInfo\n}\n\nexport interface ResolvedUpdateFileInfo {\n readonly url: URL\n readonly info: UpdateFileInfo\n\n packageInfo?: PackageFileInfo\n}\n\nexport interface UpdateDownloadedEvent extends UpdateInfo {\n downloadedFile: string\n}\n"]}