custom-electron-titlebar 3.2.6 → 3.2.10

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 (239) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/README.md +15 -24
  3. package/_config.yml +1 -0
  4. package/{lib → build}/browser/browser.d.ts +0 -0
  5. package/{lib → build}/browser/browser.js +0 -0
  6. package/{lib → build}/browser/browser.js.map +0 -0
  7. package/{lib → build}/browser/event.d.ts +0 -0
  8. package/{lib → build}/browser/event.js +2 -1
  9. package/{lib → build}/browser/event.js.map +1 -1
  10. package/{lib → build}/browser/iframe.d.ts +0 -0
  11. package/{lib → build}/browser/iframe.js +0 -0
  12. package/{lib → build}/browser/iframe.js.map +0 -0
  13. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  14. package/{lib → build}/browser/keyboardEvent.js +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js.map +0 -0
  16. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  17. package/{lib → build}/browser/mouseEvent.js +0 -0
  18. package/{lib → build}/browser/mouseEvent.js.map +0 -0
  19. package/{lib → build}/common/arrays.d.ts +0 -0
  20. package/{lib → build}/common/arrays.js +0 -0
  21. package/{lib → build}/common/arrays.js.map +0 -0
  22. package/{lib → build}/common/async.d.ts +0 -0
  23. package/{lib → build}/common/async.js +0 -0
  24. package/{lib → build}/common/async.js.map +0 -0
  25. package/{lib → build}/common/charCode.d.ts +0 -0
  26. package/{lib → build}/common/charCode.js +0 -0
  27. package/{lib → build}/common/charCode.js.map +0 -0
  28. package/{lib → build}/common/color.d.ts +0 -0
  29. package/{lib → build}/common/color.js +0 -0
  30. package/{lib → build}/common/color.js.map +0 -0
  31. package/{lib → build}/common/dom.d.ts +0 -0
  32. package/{lib → build}/common/dom.js +16 -14
  33. package/build/common/dom.js.map +1 -0
  34. package/{lib → build}/common/event.d.ts +0 -0
  35. package/{lib → build}/common/event.js +1 -1
  36. package/build/common/event.js.map +1 -0
  37. package/{lib → build}/common/iterator.d.ts +0 -0
  38. package/{lib → build}/common/iterator.js +0 -0
  39. package/{lib → build}/common/iterator.js.map +0 -0
  40. package/{lib → build}/common/keyCodes.d.ts +0 -0
  41. package/{lib → build}/common/keyCodes.js +0 -0
  42. package/{lib → build}/common/keyCodes.js.map +0 -0
  43. package/{lib → build}/common/lifecycle.d.ts +0 -0
  44. package/{lib → build}/common/lifecycle.js +0 -0
  45. package/{lib → build}/common/lifecycle.js.map +0 -0
  46. package/{lib → build}/common/linkedList.d.ts +0 -0
  47. package/{lib → build}/common/linkedList.js +0 -0
  48. package/{lib → build}/common/linkedList.js.map +0 -0
  49. package/{lib → build}/common/platform.d.ts +0 -0
  50. package/{lib → build}/common/platform.js +0 -0
  51. package/{lib → build}/common/platform.js.map +0 -0
  52. package/{lib → build}/index.d.ts +0 -0
  53. package/{lib → build}/index.js +0 -0
  54. package/{lib → build}/index.js.map +0 -0
  55. package/{lib → build}/menu/menu.d.ts +0 -0
  56. package/{lib → build}/menu/menu.js +38 -38
  57. package/build/menu/menu.js.map +1 -0
  58. package/{lib → build}/menu/menuitem.d.ts +10 -2
  59. package/{lib → build}/menu/menuitem.js +70 -34
  60. package/build/menu/menuitem.js.map +1 -0
  61. package/{lib → build}/menubar.d.ts +0 -0
  62. package/{lib → build}/menubar.js +29 -30
  63. package/build/menubar.js.map +1 -0
  64. package/{lib → build}/themebar.d.ts +0 -0
  65. package/{lib → build}/themebar.js +2 -2
  66. package/build/themebar.js.map +1 -0
  67. package/{lib → build}/titlebar.d.ts +0 -0
  68. package/{lib → build}/titlebar.js +61 -58
  69. package/build/titlebar.js.map +1 -0
  70. package/package.json +13 -7
  71. package/lib/common/dom.js.map +0 -1
  72. package/lib/common/enableNativeMenuCommands.d.ts +0 -1
  73. package/lib/common/enableNativeMenuCommands.js +0 -32
  74. package/lib/common/enableNativeMenuCommands.js.map +0 -1
  75. package/lib/common/event.js.map +0 -1
  76. package/lib/main.d.ts +0 -1
  77. package/lib/main.js +0 -14
  78. package/lib/main.js.map +0 -1
  79. package/lib/menu/menu.js.map +0 -1
  80. package/lib/menu/menuitem.js.map +0 -1
  81. package/lib/menubar.js.map +0 -1
  82. package/lib/themebar.js.map +0 -1
  83. package/lib/titlebar.js.map +0 -1
  84. package/lib/vs/base/browser/browser.js +0 -150
  85. package/lib/vs/base/browser/canIUse.js +0 -58
  86. package/lib/vs/base/browser/codicons.js +0 -37
  87. package/lib/vs/base/browser/contextmenu.js +0 -9
  88. package/lib/vs/base/browser/dnd.js +0 -113
  89. package/lib/vs/base/browser/dom.js +0 -1417
  90. package/lib/vs/base/browser/event.js +0 -36
  91. package/lib/vs/base/browser/fastDomNode.js +0 -265
  92. package/lib/vs/base/browser/formattedTextRenderer.js +0 -248
  93. package/lib/vs/base/browser/globalMouseMoveMonitor.js +0 -137
  94. package/lib/vs/base/browser/history.js +0 -9
  95. package/lib/vs/base/browser/iframe.js +0 -126
  96. package/lib/vs/base/browser/keyboardEvent.js +0 -599
  97. package/lib/vs/base/browser/mouseEvent.js +0 -155
  98. package/lib/vs/base/browser/touch.js +0 -315
  99. package/lib/vs/base/browser/ui/actionbar/actionViewItems.js +0 -397
  100. package/lib/vs/base/browser/ui/actionbar/actionbar.js +0 -583
  101. package/lib/vs/base/browser/ui/checkbox/checkbox.js +0 -251
  102. package/lib/vs/base/browser/ui/codicons/codiconLabel.js +0 -31
  103. package/lib/vs/base/browser/ui/codicons/codiconStyles.js +0 -47
  104. package/lib/vs/base/browser/ui/contextview/contextview.js +0 -367
  105. package/lib/vs/base/browser/ui/dropdown/dropdown.js +0 -256
  106. package/lib/vs/base/browser/ui/dropdown/dropdownActionViewItem.js +0 -120
  107. package/lib/vs/base/browser/ui/keybindingLabel/keybindingLabel.js +0 -118
  108. package/lib/vs/base/browser/ui/list/list.js +0 -54
  109. package/lib/vs/base/browser/ui/list/listPaging.js +0 -322
  110. package/lib/vs/base/browser/ui/list/listView.js +0 -1388
  111. package/lib/vs/base/browser/ui/list/listWidget.js +0 -1709
  112. package/lib/vs/base/browser/ui/list/rangeMap.js +0 -223
  113. package/lib/vs/base/browser/ui/list/rowCache.js +0 -113
  114. package/lib/vs/base/browser/ui/list/splice.js +0 -23
  115. package/lib/vs/base/browser/ui/menu/menu.js +0 -1371
  116. package/lib/vs/base/browser/ui/menu/menubar.js +0 -1139
  117. package/lib/vs/base/browser/ui/scrollbar/abstractScrollbar.js +0 -278
  118. package/lib/vs/base/browser/ui/scrollbar/horizontalScrollbar.js +0 -115
  119. package/lib/vs/base/browser/ui/scrollbar/scrollableElement.js +0 -646
  120. package/lib/vs/base/browser/ui/scrollbar/scrollableElementOptions.js +0 -9
  121. package/lib/vs/base/browser/ui/scrollbar/scrollbarArrow.js +0 -106
  122. package/lib/vs/base/browser/ui/scrollbar/scrollbarState.js +0 -184
  123. package/lib/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.js +0 -116
  124. package/lib/vs/base/browser/ui/scrollbar/verticalScrollbar.js +0 -114
  125. package/lib/vs/base/browser/ui/selectBox/selectBox.js +0 -85
  126. package/lib/vs/base/browser/ui/selectBox/selectBoxCustom.js +0 -985
  127. package/lib/vs/base/browser/ui/selectBox/selectBoxNative.js +0 -188
  128. package/lib/vs/base/browser/ui/toolbar/toolbar.js +0 -206
  129. package/lib/vs/base/browser/ui/widget.js +0 -69
  130. package/lib/vs/base/common/actions.js +0 -224
  131. package/lib/vs/base/common/amd.js +0 -31
  132. package/lib/vs/base/common/arrays.js +0 -641
  133. package/lib/vs/base/common/assert.js +0 -21
  134. package/lib/vs/base/common/async.js +0 -966
  135. package/lib/vs/base/common/buffer.js +0 -250
  136. package/lib/vs/base/common/cache.js +0 -40
  137. package/lib/vs/base/common/cancellation.js +0 -146
  138. package/lib/vs/base/common/charCode.js +0 -9
  139. package/lib/vs/base/common/codicon.js +0 -136
  140. package/lib/vs/base/common/codicons.js +0 -1378
  141. package/lib/vs/base/common/collections.js +0 -133
  142. package/lib/vs/base/common/color.js +0 -716
  143. package/lib/vs/base/common/comparers.js +0 -280
  144. package/lib/vs/base/common/console.js +0 -142
  145. package/lib/vs/base/common/date.js +0 -113
  146. package/lib/vs/base/common/decorators.js +0 -169
  147. package/lib/vs/base/common/errorMessage.js +0 -93
  148. package/lib/vs/base/common/errors.js +0 -213
  149. package/lib/vs/base/common/errorsWithActions.js +0 -28
  150. package/lib/vs/base/common/event.js +0 -873
  151. package/lib/vs/base/common/extpath.js +0 -401
  152. package/lib/vs/base/common/filters.js +0 -948
  153. package/lib/vs/base/common/functional.js +0 -28
  154. package/lib/vs/base/common/fuzzyScorer.js +0 -811
  155. package/lib/vs/base/common/glob.js +0 -696
  156. package/lib/vs/base/common/hash.js +0 -359
  157. package/lib/vs/base/common/history.js +0 -116
  158. package/lib/vs/base/common/htmlContent.js +0 -162
  159. package/lib/vs/base/common/idGenerator.js +0 -25
  160. package/lib/vs/base/common/iterator.js +0 -118
  161. package/lib/vs/base/common/json.js +0 -1624
  162. package/lib/vs/base/common/jsonEdit.js +0 -272
  163. package/lib/vs/base/common/jsonErrorMessages.js +0 -69
  164. package/lib/vs/base/common/jsonFormatter.js +0 -316
  165. package/lib/vs/base/common/jsonSchema.js +0 -9
  166. package/lib/vs/base/common/keyCodes.js +0 -591
  167. package/lib/vs/base/common/keybindingLabels.js +0 -231
  168. package/lib/vs/base/common/keybindingParser.js +0 -142
  169. package/lib/vs/base/common/labels.js +0 -430
  170. package/lib/vs/base/common/lazy.js +0 -71
  171. package/lib/vs/base/common/lifecycle.js +0 -308
  172. package/lib/vs/base/common/linkedList.js +0 -152
  173. package/lib/vs/base/common/linkedText.js +0 -73
  174. package/lib/vs/base/common/map.js +0 -1108
  175. package/lib/vs/base/common/marshalling.js +0 -80
  176. package/lib/vs/base/common/mime.js +0 -321
  177. package/lib/vs/base/common/navigator.js +0 -50
  178. package/lib/vs/base/common/network.js +0 -160
  179. package/lib/vs/base/common/normalization.js +0 -78
  180. package/lib/vs/base/common/numbers.js +0 -55
  181. package/lib/vs/base/common/objects.js +0 -268
  182. package/lib/vs/base/common/paging.js +0 -190
  183. package/lib/vs/base/common/parsers.js +0 -78
  184. package/lib/vs/base/common/path.js +0 -1550
  185. package/lib/vs/base/common/platform.js +0 -245
  186. package/lib/vs/base/common/process.js +0 -52
  187. package/lib/vs/base/common/processes.js +0 -32
  188. package/lib/vs/base/common/range.js +0 -79
  189. package/lib/vs/base/common/resourceTree.js +0 -185
  190. package/lib/vs/base/common/resources.js +0 -421
  191. package/lib/vs/base/common/scanCode.js +0 -1472
  192. package/lib/vs/base/common/scrollable.js +0 -397
  193. package/lib/vs/base/common/search.js +0 -55
  194. package/lib/vs/base/common/sequence.js +0 -64
  195. package/lib/vs/base/common/severity.js +0 -55
  196. package/lib/vs/base/common/skipList.js +0 -234
  197. package/lib/vs/base/common/stopwatch.js +0 -45
  198. package/lib/vs/base/common/stream.js +0 -418
  199. package/lib/vs/base/common/strings.js +0 -1283
  200. package/lib/vs/base/common/styler.js +0 -9
  201. package/lib/vs/base/common/types.js +0 -296
  202. package/lib/vs/base/common/uint.js +0 -46
  203. package/lib/vs/base/common/uri.js +0 -756
  204. package/lib/vs/base/common/uriIpc.js +0 -154
  205. package/lib/vs/base/common/uuid.js +0 -70
  206. package/lib/vs/nls.mock.js +0 -31
  207. package/lib/vs/platform/actions/browser/menuEntryActionViewItem.js +0 -342
  208. package/lib/vs/platform/actions/common/actions.js +0 -456
  209. package/lib/vs/platform/actions/common/menuService.js +0 -194
  210. package/lib/vs/platform/clipboard/browser/clipboardService.js +0 -99
  211. package/lib/vs/platform/clipboard/common/clipboardService.js +0 -14
  212. package/lib/vs/platform/contextkey/common/contextkey.js +0 -1210
  213. package/lib/vs/platform/contextkey/common/contextkeys.js +0 -23
  214. package/lib/vs/platform/contextview/browser/contextView.js +0 -15
  215. package/lib/vs/platform/contextview/browser/contextViewService.js +0 -96
  216. package/lib/vs/platform/environment/common/argv.js +0 -9
  217. package/lib/vs/platform/environment/common/environment.js +0 -15
  218. package/lib/vs/platform/instantiation/common/descriptors.js +0 -25
  219. package/lib/vs/platform/instantiation/common/extensions.js +0 -26
  220. package/lib/vs/platform/instantiation/common/graph.js +0 -93
  221. package/lib/vs/platform/instantiation/common/instantiation.js +0 -84
  222. package/lib/vs/platform/instantiation/common/instantiationService.js +0 -361
  223. package/lib/vs/platform/instantiation/common/serviceCollection.js +0 -39
  224. package/lib/vs/platform/keybinding/common/baseResolvedKeybinding.js +0 -73
  225. package/lib/vs/platform/keybinding/common/keybinding.js +0 -14
  226. package/lib/vs/platform/keybinding/common/keybindingResolver.js +0 -391
  227. package/lib/vs/platform/keybinding/common/keybindingsRegistry.js +0 -229
  228. package/lib/vs/platform/keybinding/common/resolvedKeybindingItem.js +0 -47
  229. package/lib/vs/platform/keybinding/common/usLayoutResolvedKeybinding.js +0 -160
  230. package/lib/vs/platform/layout/browser/layoutService.js +0 -14
  231. package/lib/vs/platform/menubar/common/menubar.js +0 -34
  232. package/lib/vs/platform/registry/common/platform.js +0 -38
  233. package/lib/vs/platform/theme/browser/checkbox.js +0 -32
  234. package/lib/vs/platform/theme/common/colorRegistry.js +0 -1154
  235. package/lib/vs/platform/theme/common/styler.js +0 -290
  236. package/lib/vs/platform/theme/common/theme.js +0 -21
  237. package/lib/vs/platform/theme/common/themeService.js +0 -176
  238. package/lib/vs/platform/theme/common/tokenClassificationRegistry.js +0 -540
  239. package/lib/vs/platform/theme/test/common/testThemeService.js +0 -98
@@ -1,966 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.IntervalCounter = exports.TaskSequentializer = exports.retry = exports.IdleValue = exports.runWhenIdle = exports.RunOnceWorker = exports.RunOnceScheduler = exports.IntervalTimer = exports.TimeoutTimer = exports.ResourceQueue = exports.Queue = exports.Limiter = exports.first = exports.sequence = exports.ignoreErrors = exports.disposableTimeout = exports.timeout = exports.Barrier = exports.ThrottledDelayer = exports.Delayer = exports.SequencerByKey = exports.Sequencer = exports.Throttler = exports.asPromise = exports.raceTimeout = exports.raceCancellablePromises = exports.raceCancellation = exports.createCancelablePromise = exports.isThenable = void 0;
11
-
12
- const cancellation_1 = require("./cancellation");
13
-
14
- const errors = require("./errors");
15
-
16
- const event_1 = require("./event");
17
-
18
- const lifecycle_1 = require("./lifecycle");
19
-
20
- function isThenable(obj) {
21
- return obj && typeof obj.then === 'function';
22
- }
23
-
24
- exports.isThenable = isThenable;
25
-
26
- function createCancelablePromise(callback) {
27
- const source = new cancellation_1.CancellationTokenSource();
28
- const thenable = callback(source.token);
29
- const promise = new Promise((resolve, reject) => {
30
- source.token.onCancellationRequested(() => {
31
- reject(errors.canceled());
32
- });
33
- Promise.resolve(thenable).then(value => {
34
- source.dispose();
35
- resolve(value);
36
- }, err => {
37
- source.dispose();
38
- reject(err);
39
- });
40
- });
41
- return new class {
42
- cancel() {
43
- source.cancel();
44
- }
45
-
46
- then(resolve, reject) {
47
- return promise.then(resolve, reject);
48
- }
49
-
50
- catch(reject) {
51
- return this.then(undefined, reject);
52
- }
53
-
54
- finally(onfinally) {
55
- return promise.finally(onfinally);
56
- }
57
-
58
- }();
59
- }
60
-
61
- exports.createCancelablePromise = createCancelablePromise;
62
-
63
- function raceCancellation(promise, token, defaultValue) {
64
- return Promise.race([promise, new Promise(resolve => token.onCancellationRequested(() => resolve(defaultValue)))]);
65
- }
66
-
67
- exports.raceCancellation = raceCancellation;
68
- /**
69
- * Returns as soon as one of the promises is resolved and cancels remaining promises
70
- */
71
-
72
- async function raceCancellablePromises(cancellablePromises) {
73
- let resolvedPromiseIndex = -1;
74
- const promises = cancellablePromises.map((promise, index) => promise.then(result => {
75
- resolvedPromiseIndex = index;
76
- return result;
77
- }));
78
- const result = await Promise.race(promises);
79
- cancellablePromises.forEach((cancellablePromise, index) => {
80
- if (index !== resolvedPromiseIndex) {
81
- cancellablePromise.cancel();
82
- }
83
- });
84
- return result;
85
- }
86
-
87
- exports.raceCancellablePromises = raceCancellablePromises;
88
-
89
- function raceTimeout(promise, timeout, onTimeout) {
90
- let promiseResolve = undefined;
91
- const timer = setTimeout(() => {
92
- promiseResolve === null || promiseResolve === void 0 ? void 0 : promiseResolve(undefined);
93
- onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout();
94
- }, timeout);
95
- return Promise.race([promise.finally(() => clearTimeout(timer)), new Promise(resolve => promiseResolve = resolve)]);
96
- }
97
-
98
- exports.raceTimeout = raceTimeout;
99
-
100
- function asPromise(callback) {
101
- return new Promise((resolve, reject) => {
102
- const item = callback();
103
-
104
- if (isThenable(item)) {
105
- item.then(resolve, reject);
106
- } else {
107
- resolve(item);
108
- }
109
- });
110
- }
111
-
112
- exports.asPromise = asPromise;
113
- /**
114
- * A helper to prevent accumulation of sequential async tasks.
115
- *
116
- * Imagine a mail man with the sole task of delivering letters. As soon as
117
- * a letter submitted for delivery, he drives to the destination, delivers it
118
- * and returns to his base. Imagine that during the trip, N more letters were submitted.
119
- * When the mail man returns, he picks those N letters and delivers them all in a
120
- * single trip. Even though N+1 submissions occurred, only 2 deliveries were made.
121
- *
122
- * The throttler implements this via the queue() method, by providing it a task
123
- * factory. Following the example:
124
- *
125
- * const throttler = new Throttler();
126
- * const letters = [];
127
- *
128
- * function deliver() {
129
- * const lettersToDeliver = letters;
130
- * letters = [];
131
- * return makeTheTrip(lettersToDeliver);
132
- * }
133
- *
134
- * function onLetterReceived(l) {
135
- * letters.push(l);
136
- * throttler.queue(deliver);
137
- * }
138
- */
139
-
140
- class Throttler {
141
- constructor() {
142
- this.activePromise = null;
143
- this.queuedPromise = null;
144
- this.queuedPromiseFactory = null;
145
- }
146
-
147
- queue(promiseFactory) {
148
- if (this.activePromise) {
149
- this.queuedPromiseFactory = promiseFactory;
150
-
151
- if (!this.queuedPromise) {
152
- const onComplete = () => {
153
- this.queuedPromise = null;
154
- const result = this.queue(this.queuedPromiseFactory);
155
- this.queuedPromiseFactory = null;
156
- return result;
157
- };
158
-
159
- this.queuedPromise = new Promise(c => {
160
- this.activePromise.then(onComplete, onComplete).then(c);
161
- });
162
- }
163
-
164
- return new Promise((c, e) => {
165
- this.queuedPromise.then(c, e);
166
- });
167
- }
168
-
169
- this.activePromise = promiseFactory();
170
- return new Promise((resolve, reject) => {
171
- this.activePromise.then(result => {
172
- this.activePromise = null;
173
- resolve(result);
174
- }, err => {
175
- this.activePromise = null;
176
- reject(err);
177
- });
178
- });
179
- }
180
-
181
- }
182
-
183
- exports.Throttler = Throttler;
184
-
185
- class Sequencer {
186
- constructor() {
187
- this.current = Promise.resolve(null);
188
- }
189
-
190
- queue(promiseTask) {
191
- return this.current = this.current.then(() => promiseTask());
192
- }
193
-
194
- }
195
-
196
- exports.Sequencer = Sequencer;
197
-
198
- class SequencerByKey {
199
- constructor() {
200
- this.promiseMap = new Map();
201
- }
202
-
203
- queue(key, promiseTask) {
204
- var _a;
205
-
206
- const runningPromise = (_a = this.promiseMap.get(key)) !== null && _a !== void 0 ? _a : Promise.resolve();
207
- const newPromise = runningPromise.catch(() => {}).then(promiseTask).finally(() => {
208
- if (this.promiseMap.get(key) === newPromise) {
209
- this.promiseMap.delete(key);
210
- }
211
- });
212
- this.promiseMap.set(key, newPromise);
213
- return newPromise;
214
- }
215
-
216
- }
217
-
218
- exports.SequencerByKey = SequencerByKey;
219
- /**
220
- * A helper to delay execution of a task that is being requested often.
221
- *
222
- * Following the throttler, now imagine the mail man wants to optimize the number of
223
- * trips proactively. The trip itself can be long, so he decides not to make the trip
224
- * as soon as a letter is submitted. Instead he waits a while, in case more
225
- * letters are submitted. After said waiting period, if no letters were submitted, he
226
- * decides to make the trip. Imagine that N more letters were submitted after the first
227
- * one, all within a short period of time between each other. Even though N+1
228
- * submissions occurred, only 1 delivery was made.
229
- *
230
- * The delayer offers this behavior via the trigger() method, into which both the task
231
- * to be executed and the waiting period (delay) must be passed in as arguments. Following
232
- * the example:
233
- *
234
- * const delayer = new Delayer(WAITING_PERIOD);
235
- * const letters = [];
236
- *
237
- * function letterReceived(l) {
238
- * letters.push(l);
239
- * delayer.trigger(() => { return makeTheTrip(); });
240
- * }
241
- */
242
-
243
- class Delayer {
244
- constructor(defaultDelay) {
245
- this.defaultDelay = defaultDelay;
246
- this.timeout = null;
247
- this.completionPromise = null;
248
- this.doResolve = null;
249
- this.doReject = null;
250
- this.task = null;
251
- }
252
-
253
- trigger(task, delay = this.defaultDelay) {
254
- this.task = task;
255
- this.cancelTimeout();
256
-
257
- if (!this.completionPromise) {
258
- this.completionPromise = new Promise((c, e) => {
259
- this.doResolve = c;
260
- this.doReject = e;
261
- }).then(() => {
262
- this.completionPromise = null;
263
- this.doResolve = null;
264
-
265
- if (this.task) {
266
- const task = this.task;
267
- this.task = null;
268
- return task();
269
- }
270
-
271
- return undefined;
272
- });
273
- }
274
-
275
- this.timeout = setTimeout(() => {
276
- this.timeout = null;
277
-
278
- if (this.doResolve) {
279
- this.doResolve(null);
280
- }
281
- }, delay);
282
- return this.completionPromise;
283
- }
284
-
285
- isTriggered() {
286
- return this.timeout !== null;
287
- }
288
-
289
- cancel() {
290
- this.cancelTimeout();
291
-
292
- if (this.completionPromise) {
293
- if (this.doReject) {
294
- this.doReject(errors.canceled());
295
- }
296
-
297
- this.completionPromise = null;
298
- }
299
- }
300
-
301
- cancelTimeout() {
302
- if (this.timeout !== null) {
303
- clearTimeout(this.timeout);
304
- this.timeout = null;
305
- }
306
- }
307
-
308
- dispose() {
309
- this.cancelTimeout();
310
- }
311
-
312
- }
313
-
314
- exports.Delayer = Delayer;
315
- /**
316
- * A helper to delay execution of a task that is being requested often, while
317
- * preventing accumulation of consecutive executions, while the task runs.
318
- *
319
- * The mail man is clever and waits for a certain amount of time, before going
320
- * out to deliver letters. While the mail man is going out, more letters arrive
321
- * and can only be delivered once he is back. Once he is back the mail man will
322
- * do one more trip to deliver the letters that have accumulated while he was out.
323
- */
324
-
325
- class ThrottledDelayer {
326
- constructor(defaultDelay) {
327
- this.delayer = new Delayer(defaultDelay);
328
- this.throttler = new Throttler();
329
- }
330
-
331
- trigger(promiseFactory, delay) {
332
- return this.delayer.trigger(() => this.throttler.queue(promiseFactory), delay);
333
- }
334
-
335
- isTriggered() {
336
- return this.delayer.isTriggered();
337
- }
338
-
339
- cancel() {
340
- this.delayer.cancel();
341
- }
342
-
343
- dispose() {
344
- this.delayer.dispose();
345
- }
346
-
347
- }
348
-
349
- exports.ThrottledDelayer = ThrottledDelayer;
350
- /**
351
- * A barrier that is initially closed and then becomes opened permanently.
352
- */
353
-
354
- class Barrier {
355
- constructor() {
356
- this._isOpen = false;
357
- this._promise = new Promise((c, e) => {
358
- this._completePromise = c;
359
- });
360
- }
361
-
362
- isOpen() {
363
- return this._isOpen;
364
- }
365
-
366
- open() {
367
- this._isOpen = true;
368
-
369
- this._completePromise(true);
370
- }
371
-
372
- wait() {
373
- return this._promise;
374
- }
375
-
376
- }
377
-
378
- exports.Barrier = Barrier;
379
-
380
- function timeout(millis, token) {
381
- if (!token) {
382
- return createCancelablePromise(token => timeout(millis, token));
383
- }
384
-
385
- return new Promise((resolve, reject) => {
386
- const handle = setTimeout(resolve, millis);
387
- token.onCancellationRequested(() => {
388
- clearTimeout(handle);
389
- reject(errors.canceled());
390
- });
391
- });
392
- }
393
-
394
- exports.timeout = timeout;
395
-
396
- function disposableTimeout(handler, timeout = 0) {
397
- const timer = setTimeout(handler, timeout);
398
- return lifecycle_1.toDisposable(() => clearTimeout(timer));
399
- }
400
-
401
- exports.disposableTimeout = disposableTimeout;
402
-
403
- function ignoreErrors(promise) {
404
- return promise.then(undefined, _ => undefined);
405
- }
406
-
407
- exports.ignoreErrors = ignoreErrors;
408
- /**
409
- * Runs the provided list of promise factories in sequential order. The returned
410
- * promise will complete to an array of results from each promise.
411
- */
412
-
413
- function sequence(promiseFactories) {
414
- const results = [];
415
- let index = 0;
416
- const len = promiseFactories.length;
417
-
418
- function next() {
419
- return index < len ? promiseFactories[index++]() : null;
420
- }
421
-
422
- function thenHandler(result) {
423
- if (result !== undefined && result !== null) {
424
- results.push(result);
425
- }
426
-
427
- const n = next();
428
-
429
- if (n) {
430
- return n.then(thenHandler);
431
- }
432
-
433
- return Promise.resolve(results);
434
- }
435
-
436
- return Promise.resolve(null).then(thenHandler);
437
- }
438
-
439
- exports.sequence = sequence;
440
-
441
- function first(promiseFactories, shouldStop = t => !!t, defaultValue = null) {
442
- let index = 0;
443
- const len = promiseFactories.length;
444
-
445
- const loop = () => {
446
- if (index >= len) {
447
- return Promise.resolve(defaultValue);
448
- }
449
-
450
- const factory = promiseFactories[index++];
451
- const promise = Promise.resolve(factory());
452
- return promise.then(result => {
453
- if (shouldStop(result)) {
454
- return Promise.resolve(result);
455
- }
456
-
457
- return loop();
458
- });
459
- };
460
-
461
- return loop();
462
- }
463
-
464
- exports.first = first;
465
- /**
466
- * A helper to queue N promises and run them all with a max degree of parallelism. The helper
467
- * ensures that at any time no more than M promises are running at the same time.
468
- */
469
-
470
- class Limiter {
471
- constructor(maxDegreeOfParalellism) {
472
- this._size = 0;
473
- this.maxDegreeOfParalellism = maxDegreeOfParalellism;
474
- this.outstandingPromises = [];
475
- this.runningPromises = 0;
476
- this._onFinished = new event_1.Emitter();
477
- }
478
-
479
- get onFinished() {
480
- return this._onFinished.event;
481
- }
482
-
483
- get size() {
484
- return this._size; // return this.runningPromises + this.outstandingPromises.length;
485
- }
486
-
487
- queue(factory) {
488
- this._size++;
489
- return new Promise((c, e) => {
490
- this.outstandingPromises.push({
491
- factory,
492
- c,
493
- e
494
- });
495
- this.consume();
496
- });
497
- }
498
-
499
- consume() {
500
- while (this.outstandingPromises.length && this.runningPromises < this.maxDegreeOfParalellism) {
501
- const iLimitedTask = this.outstandingPromises.shift();
502
- this.runningPromises++;
503
- const promise = iLimitedTask.factory();
504
- promise.then(iLimitedTask.c, iLimitedTask.e);
505
- promise.then(() => this.consumed(), () => this.consumed());
506
- }
507
- }
508
-
509
- consumed() {
510
- this._size--;
511
- this.runningPromises--;
512
-
513
- if (this.outstandingPromises.length > 0) {
514
- this.consume();
515
- } else {
516
- this._onFinished.fire();
517
- }
518
- }
519
-
520
- dispose() {
521
- this._onFinished.dispose();
522
- }
523
-
524
- }
525
-
526
- exports.Limiter = Limiter;
527
- /**
528
- * A queue is handles one promise at a time and guarantees that at any time only one promise is executing.
529
- */
530
-
531
- class Queue extends Limiter {
532
- constructor() {
533
- super(1);
534
- }
535
-
536
- }
537
-
538
- exports.Queue = Queue;
539
- /**
540
- * A helper to organize queues per resource. The ResourceQueue makes sure to manage queues per resource
541
- * by disposing them once the queue is empty.
542
- */
543
-
544
- class ResourceQueue {
545
- constructor() {
546
- this.queues = new Map();
547
- }
548
-
549
- queueFor(resource) {
550
- const key = resource.toString();
551
-
552
- if (!this.queues.has(key)) {
553
- const queue = new Queue();
554
- queue.onFinished(() => {
555
- queue.dispose();
556
- this.queues.delete(key);
557
- });
558
- this.queues.set(key, queue);
559
- }
560
-
561
- return this.queues.get(key);
562
- }
563
-
564
- dispose() {
565
- this.queues.forEach(queue => queue.dispose());
566
- this.queues.clear();
567
- }
568
-
569
- }
570
-
571
- exports.ResourceQueue = ResourceQueue;
572
-
573
- class TimeoutTimer {
574
- constructor(runner, timeout) {
575
- this._token = -1;
576
-
577
- if (typeof runner === 'function' && typeof timeout === 'number') {
578
- this.setIfNotSet(runner, timeout);
579
- }
580
- }
581
-
582
- dispose() {
583
- this.cancel();
584
- }
585
-
586
- cancel() {
587
- if (this._token !== -1) {
588
- clearTimeout(this._token);
589
- this._token = -1;
590
- }
591
- }
592
-
593
- cancelAndSet(runner, timeout) {
594
- this.cancel();
595
- this._token = setTimeout(() => {
596
- this._token = -1;
597
- runner();
598
- }, timeout);
599
- }
600
-
601
- setIfNotSet(runner, timeout) {
602
- if (this._token !== -1) {
603
- // timer is already set
604
- return;
605
- }
606
-
607
- this._token = setTimeout(() => {
608
- this._token = -1;
609
- runner();
610
- }, timeout);
611
- }
612
-
613
- }
614
-
615
- exports.TimeoutTimer = TimeoutTimer;
616
-
617
- class IntervalTimer {
618
- constructor() {
619
- this._token = -1;
620
- }
621
-
622
- dispose() {
623
- this.cancel();
624
- }
625
-
626
- cancel() {
627
- if (this._token !== -1) {
628
- clearInterval(this._token);
629
- this._token = -1;
630
- }
631
- }
632
-
633
- cancelAndSet(runner, interval) {
634
- this.cancel();
635
- this._token = setInterval(() => {
636
- runner();
637
- }, interval);
638
- }
639
-
640
- }
641
-
642
- exports.IntervalTimer = IntervalTimer;
643
-
644
- class RunOnceScheduler {
645
- constructor(runner, delay) {
646
- this.timeoutToken = -1;
647
- this.runner = runner;
648
- this.timeout = delay;
649
- this.timeoutHandler = this.onTimeout.bind(this);
650
- }
651
- /**
652
- * Dispose RunOnceScheduler
653
- */
654
-
655
-
656
- dispose() {
657
- this.cancel();
658
- this.runner = null;
659
- }
660
- /**
661
- * Cancel current scheduled runner (if any).
662
- */
663
-
664
-
665
- cancel() {
666
- if (this.isScheduled()) {
667
- clearTimeout(this.timeoutToken);
668
- this.timeoutToken = -1;
669
- }
670
- }
671
- /**
672
- * Cancel previous runner (if any) & schedule a new runner.
673
- */
674
-
675
-
676
- schedule(delay = this.timeout) {
677
- this.cancel();
678
- this.timeoutToken = setTimeout(this.timeoutHandler, delay);
679
- }
680
-
681
- get delay() {
682
- return this.timeout;
683
- }
684
-
685
- set delay(value) {
686
- this.timeout = value;
687
- }
688
- /**
689
- * Returns true if scheduled.
690
- */
691
-
692
-
693
- isScheduled() {
694
- return this.timeoutToken !== -1;
695
- }
696
-
697
- onTimeout() {
698
- this.timeoutToken = -1;
699
-
700
- if (this.runner) {
701
- this.doRun();
702
- }
703
- }
704
-
705
- doRun() {
706
- if (this.runner) {
707
- this.runner();
708
- }
709
- }
710
-
711
- }
712
-
713
- exports.RunOnceScheduler = RunOnceScheduler;
714
-
715
- class RunOnceWorker extends RunOnceScheduler {
716
- constructor(runner, timeout) {
717
- super(runner, timeout);
718
- this.units = [];
719
- }
720
-
721
- work(unit) {
722
- this.units.push(unit);
723
-
724
- if (!this.isScheduled()) {
725
- this.schedule();
726
- }
727
- }
728
-
729
- doRun() {
730
- const units = this.units;
731
- this.units = [];
732
-
733
- if (this.runner) {
734
- this.runner(units);
735
- }
736
- }
737
-
738
- dispose() {
739
- this.units = [];
740
- super.dispose();
741
- }
742
-
743
- }
744
-
745
- exports.RunOnceWorker = RunOnceWorker;
746
-
747
- (function () {
748
- if (typeof requestIdleCallback !== 'function' || typeof cancelIdleCallback !== 'function') {
749
- const dummyIdle = Object.freeze({
750
- didTimeout: true,
751
-
752
- timeRemaining() {
753
- return 15;
754
- }
755
-
756
- });
757
-
758
- exports.runWhenIdle = runner => {
759
- const handle = setTimeout(() => runner(dummyIdle));
760
- let disposed = false;
761
- return {
762
- dispose() {
763
- if (disposed) {
764
- return;
765
- }
766
-
767
- disposed = true;
768
- clearTimeout(handle);
769
- }
770
-
771
- };
772
- };
773
- } else {
774
- exports.runWhenIdle = (runner, timeout) => {
775
- const handle = requestIdleCallback(runner, typeof timeout === 'number' ? {
776
- timeout
777
- } : undefined);
778
- let disposed = false;
779
- return {
780
- dispose() {
781
- if (disposed) {
782
- return;
783
- }
784
-
785
- disposed = true;
786
- cancelIdleCallback(handle);
787
- }
788
-
789
- };
790
- };
791
- }
792
- })();
793
- /**
794
- * An implementation of the "idle-until-urgent"-strategy as introduced
795
- * here: https://philipwalton.com/articles/idle-until-urgent/
796
- */
797
-
798
-
799
- class IdleValue {
800
- constructor(executor) {
801
- this._didRun = false;
802
-
803
- this._executor = () => {
804
- try {
805
- this._value = executor();
806
- } catch (err) {
807
- this._error = err;
808
- } finally {
809
- this._didRun = true;
810
- }
811
- };
812
-
813
- this._handle = exports.runWhenIdle(() => this._executor());
814
- }
815
-
816
- dispose() {
817
- this._handle.dispose();
818
- }
819
-
820
- get value() {
821
- if (!this._didRun) {
822
- this._handle.dispose();
823
-
824
- this._executor();
825
- }
826
-
827
- if (this._error) {
828
- throw this._error;
829
- }
830
-
831
- return this._value;
832
- }
833
-
834
- }
835
-
836
- exports.IdleValue = IdleValue; //#endregion
837
-
838
- async function retry(task, delay, retries) {
839
- let lastError;
840
-
841
- for (let i = 0; i < retries; i++) {
842
- try {
843
- return await task();
844
- } catch (error) {
845
- lastError = error;
846
- await timeout(delay);
847
- }
848
- }
849
-
850
- throw lastError;
851
- }
852
-
853
- exports.retry = retry;
854
-
855
- class TaskSequentializer {
856
- hasPending(taskId) {
857
- if (!this._pending) {
858
- return false;
859
- }
860
-
861
- if (typeof taskId === 'number') {
862
- return this._pending.taskId === taskId;
863
- }
864
-
865
- return !!this._pending;
866
- }
867
-
868
- get pending() {
869
- return this._pending ? this._pending.promise : undefined;
870
- }
871
-
872
- cancelPending() {
873
- var _a;
874
-
875
- (_a = this._pending) === null || _a === void 0 ? void 0 : _a.cancel();
876
- }
877
-
878
- setPending(taskId, promise, onCancel) {
879
- this._pending = {
880
- taskId: taskId,
881
- cancel: () => onCancel === null || onCancel === void 0 ? void 0 : onCancel(),
882
- promise
883
- };
884
- promise.then(() => this.donePending(taskId), () => this.donePending(taskId));
885
- return promise;
886
- }
887
-
888
- donePending(taskId) {
889
- if (this._pending && taskId === this._pending.taskId) {
890
- // only set pending to done if the promise finished that is associated with that taskId
891
- this._pending = undefined; // schedule the next task now that we are free if we have any
892
-
893
- this.triggerNext();
894
- }
895
- }
896
-
897
- triggerNext() {
898
- if (this._next) {
899
- const next = this._next;
900
- this._next = undefined; // Run next task and complete on the associated promise
901
-
902
- next.run().then(next.promiseResolve, next.promiseReject);
903
- }
904
- }
905
-
906
- setNext(run) {
907
- // this is our first next task, so we create associated promise with it
908
- // so that we can return a promise that completes when the task has
909
- // completed.
910
- if (!this._next) {
911
- let promiseResolve;
912
- let promiseReject;
913
- const promise = new Promise((resolve, reject) => {
914
- promiseResolve = resolve;
915
- promiseReject = reject;
916
- });
917
- this._next = {
918
- run,
919
- promise,
920
- promiseResolve: promiseResolve,
921
- promiseReject: promiseReject
922
- };
923
- } // we have a previous next task, just overwrite it
924
- else {
925
- this._next.run = run;
926
- }
927
-
928
- return this._next.promise;
929
- }
930
-
931
- }
932
-
933
- exports.TaskSequentializer = TaskSequentializer; //#endregion
934
- //#region
935
-
936
- /**
937
- * The `IntervalCounter` allows to count the number
938
- * of calls to `increment()` over a duration of
939
- * `interval`. This utility can be used to conditionally
940
- * throttle a frequent task when a certain threshold
941
- * is reached.
942
- */
943
-
944
- class IntervalCounter {
945
- constructor(interval) {
946
- this.interval = interval;
947
- this.lastIncrementTime = 0;
948
- this.value = 0;
949
- }
950
-
951
- increment() {
952
- const now = Date.now(); // We are outside of the range of `interval` and as such
953
- // start counting from 0 and remember the time
954
-
955
- if (now - this.lastIncrementTime > this.interval) {
956
- this.lastIncrementTime = now;
957
- this.value = 0;
958
- }
959
-
960
- this.value++;
961
- return this.value;
962
- }
963
-
964
- }
965
-
966
- exports.IntervalCounter = IntervalCounter; //#endregion