custom-electron-titlebar 3.2.5 → 3.2.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.
- package/.vscode/launch.json +49 -0
- package/.vscode/tasks.json +34 -0
- package/README.md +15 -24
- package/_config.yml +1 -0
- package/{lib → build}/browser/browser.d.ts +0 -0
- package/{lib → build}/browser/browser.js +1 -0
- package/build/browser/browser.js.map +1 -0
- package/{lib → build}/browser/event.d.ts +0 -0
- package/{lib → build}/browser/event.js +3 -1
- package/build/browser/event.js.map +1 -0
- package/{lib → build}/browser/iframe.d.ts +0 -0
- package/{lib/base → build}/browser/iframe.js +1 -0
- package/build/browser/iframe.js.map +1 -0
- package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
- package/{lib → build}/browser/keyboardEvent.js +1 -0
- package/build/browser/keyboardEvent.js.map +1 -0
- package/{lib → build}/browser/mouseEvent.d.ts +0 -0
- package/{lib → build}/browser/mouseEvent.js +1 -0
- package/build/browser/mouseEvent.js.map +1 -0
- package/{lib → build}/common/arrays.d.ts +0 -0
- package/{lib → build}/common/arrays.js +1 -0
- package/build/common/arrays.js.map +1 -0
- package/{lib → build}/common/async.d.ts +0 -0
- package/{lib → build}/common/async.js +1 -0
- package/build/common/async.js.map +1 -0
- package/{lib → build}/common/charCode.d.ts +0 -0
- package/{lib/base → build}/common/charCode.js +1 -0
- package/build/common/charCode.js.map +1 -0
- package/{lib → build}/common/color.d.ts +0 -0
- package/{lib → build}/common/color.js +1 -0
- package/build/common/color.js.map +1 -0
- package/{lib → build}/common/dom.d.ts +0 -0
- package/{lib → build}/common/dom.js +17 -14
- package/build/common/dom.js.map +1 -0
- package/{lib → build}/common/event.d.ts +0 -0
- package/{lib → build}/common/event.js +2 -1
- package/build/common/event.js.map +1 -0
- package/{lib → build}/common/iterator.d.ts +0 -0
- package/{lib → build}/common/iterator.js +1 -0
- package/build/common/iterator.js.map +1 -0
- package/{lib → build}/common/keyCodes.d.ts +0 -0
- package/{lib → build}/common/keyCodes.js +1 -0
- package/build/common/keyCodes.js.map +1 -0
- package/{lib → build}/common/lifecycle.d.ts +0 -0
- package/{lib → build}/common/lifecycle.js +1 -0
- package/build/common/lifecycle.js.map +1 -0
- package/{lib → build}/common/linkedList.d.ts +0 -0
- package/{lib → build}/common/linkedList.js +1 -0
- package/build/common/linkedList.js.map +1 -0
- package/{lib → build}/common/platform.d.ts +0 -0
- package/{lib → build}/common/platform.js +1 -0
- package/build/common/platform.js.map +1 -0
- package/{lib → build}/index.d.ts +0 -0
- package/{lib → build}/index.js +1 -0
- package/build/index.js.map +1 -0
- package/{lib → build}/menu/menu.d.ts +0 -0
- package/{lib → build}/menu/menu.js +39 -38
- package/build/menu/menu.js.map +1 -0
- package/{lib → build}/menu/menuitem.d.ts +10 -2
- package/{lib → build}/menu/menuitem.js +71 -29
- package/build/menu/menuitem.js.map +1 -0
- package/{lib → build}/menubar.d.ts +0 -0
- package/{lib → build}/menubar.js +38 -34
- package/build/menubar.js.map +1 -0
- package/{lib → build}/themebar.d.ts +0 -0
- package/{lib → build}/themebar.js +31 -2
- package/build/themebar.js.map +1 -0
- package/{lib → build}/titlebar.d.ts +0 -0
- package/{lib → build}/titlebar.js +72 -59
- package/build/titlebar.js.map +1 -0
- package/package.json +13 -7
- package/lib/base/browser/browser.d.ts +0 -25
- package/lib/base/browser/browser.js +0 -117
- package/lib/base/browser/canIUse.d.ts +0 -18
- package/lib/base/browser/canIUse.js +0 -63
- package/lib/base/browser/dom.d.ts +0 -230
- package/lib/base/browser/dom.js +0 -1080
- package/lib/base/browser/event.d.ts +0 -12
- package/lib/base/browser/event.js +0 -28
- package/lib/base/browser/iframe.d.ts +0 -33
- package/lib/base/browser/keyboardEvent.d.ts +0 -40
- package/lib/base/browser/keyboardEvent.js +0 -256
- package/lib/base/browser/mouseEvent.d.ts +0 -69
- package/lib/base/browser/mouseEvent.js +0 -146
- package/lib/base/common/arrays.d.ts +0 -149
- package/lib/base/common/arrays.js +0 -549
- package/lib/base/common/async.d.ts +0 -259
- package/lib/base/common/async.js +0 -728
- package/lib/base/common/cancellation.d.ts +0 -29
- package/lib/base/common/cancellation.js +0 -114
- package/lib/base/common/charCode.d.ts +0 -415
- package/lib/base/common/color.d.ts +0 -163
- package/lib/base/common/color.js +0 -495
- package/lib/base/common/errors.d.ts +0 -65
- package/lib/base/common/errors.js +0 -164
- package/lib/base/common/event.d.ts +0 -248
- package/lib/base/common/event.js +0 -703
- package/lib/base/common/functional.d.ts +0 -1
- package/lib/base/common/functional.js +0 -21
- package/lib/base/common/iterator.d.ts +0 -16
- package/lib/base/common/iterator.js +0 -82
- package/lib/base/common/keyCodes.d.ts +0 -268
- package/lib/base/common/keyCodes.js +0 -292
- package/lib/base/common/lifecycle.d.ts +0 -67
- package/lib/base/common/lifecycle.js +0 -234
- package/lib/base/common/linkedList.d.ts +0 -16
- package/lib/base/common/linkedList.js +0 -128
- package/lib/base/common/network.d.ts +0 -65
- package/lib/base/common/network.js +0 -124
- package/lib/base/common/path.d.ts +0 -39
- package/lib/base/common/path.js +0 -1407
- package/lib/base/common/platform.d.ts +0 -53
- package/lib/base/common/platform.js +0 -176
- package/lib/base/common/process.d.ts +0 -5
- package/lib/base/common/process.js +0 -18
- package/lib/base/common/sequence.d.ts +0 -27
- package/lib/base/common/sequence.js +0 -32
- package/lib/base/common/uri.d.ts +0 -153
- package/lib/base/common/uri.js +0 -612
- package/lib/browser/iframe.js +0 -109
- package/lib/common/charCode.js +0 -6
- package/lib/menu.d.ts +0 -53
- package/lib/menu.js +0 -532
- package/lib/menuitem.d.ts +0 -46
- package/lib/menuitem.js +0 -295
- package/lib/vs/base/browser/browser.d.ts +0 -25
- package/lib/vs/base/browser/browser.js +0 -117
- package/lib/vs/base/browser/canIUse.d.ts +0 -18
- package/lib/vs/base/browser/canIUse.js +0 -63
- package/lib/vs/base/browser/dom.d.ts +0 -230
- package/lib/vs/base/browser/dom.js +0 -1080
- package/lib/vs/base/browser/event.d.ts +0 -12
- package/lib/vs/base/browser/event.js +0 -28
- package/lib/vs/base/browser/iframe.d.ts +0 -33
- package/lib/vs/base/browser/iframe.js +0 -109
- package/lib/vs/base/browser/keyboardEvent.d.ts +0 -40
- package/lib/vs/base/browser/keyboardEvent.js +0 -256
- package/lib/vs/base/browser/mouseEvent.d.ts +0 -69
- package/lib/vs/base/browser/mouseEvent.js +0 -146
- package/lib/vs/base/common/arrays.d.ts +0 -149
- package/lib/vs/base/common/arrays.js +0 -549
- package/lib/vs/base/common/async.d.ts +0 -259
- package/lib/vs/base/common/async.js +0 -728
- package/lib/vs/base/common/cancellation.d.ts +0 -29
- package/lib/vs/base/common/cancellation.js +0 -114
- package/lib/vs/base/common/charCode.d.ts +0 -415
- package/lib/vs/base/common/charCode.js +0 -6
- package/lib/vs/base/common/color.d.ts +0 -163
- package/lib/vs/base/common/color.js +0 -495
- package/lib/vs/base/common/errors.d.ts +0 -65
- package/lib/vs/base/common/errors.js +0 -164
- package/lib/vs/base/common/event.d.ts +0 -248
- package/lib/vs/base/common/event.js +0 -703
- package/lib/vs/base/common/functional.d.ts +0 -1
- package/lib/vs/base/common/functional.js +0 -21
- package/lib/vs/base/common/iterator.d.ts +0 -16
- package/lib/vs/base/common/iterator.js +0 -82
- package/lib/vs/base/common/keyCodes.d.ts +0 -268
- package/lib/vs/base/common/keyCodes.js +0 -292
- package/lib/vs/base/common/lifecycle.d.ts +0 -67
- package/lib/vs/base/common/lifecycle.js +0 -234
- package/lib/vs/base/common/linkedList.d.ts +0 -16
- package/lib/vs/base/common/linkedList.js +0 -128
- package/lib/vs/base/common/network.d.ts +0 -65
- package/lib/vs/base/common/network.js +0 -124
- package/lib/vs/base/common/path.d.ts +0 -39
- package/lib/vs/base/common/path.js +0 -1407
- package/lib/vs/base/common/platform.d.ts +0 -53
- package/lib/vs/base/common/platform.js +0 -176
- package/lib/vs/base/common/process.d.ts +0 -5
- package/lib/vs/base/common/process.js +0 -18
- package/lib/vs/base/common/sequence.d.ts +0 -27
- package/lib/vs/base/common/sequence.js +0 -32
- package/lib/vs/base/common/uri.d.ts +0 -153
- package/lib/vs/base/common/uri.js +0 -612
|
@@ -1,728 +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
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
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.Sequencer = exports.Throttler = exports.asPromise = exports.raceTimeout = exports.raceCancellation = exports.createCancelablePromise = exports.isThenable = void 0;
|
|
27
|
-
const cancellation_1 = require("vs/base/common/cancellation");
|
|
28
|
-
const errors = __importStar(require("vs/base/common/errors"));
|
|
29
|
-
const event_1 = require("vs/base/common/event");
|
|
30
|
-
const lifecycle_1 = require("vs/base/common/lifecycle");
|
|
31
|
-
function isThenable(obj) {
|
|
32
|
-
return obj && typeof obj.then === 'function';
|
|
33
|
-
}
|
|
34
|
-
exports.isThenable = isThenable;
|
|
35
|
-
function createCancelablePromise(callback) {
|
|
36
|
-
const source = new cancellation_1.CancellationTokenSource();
|
|
37
|
-
const thenable = callback(source.token);
|
|
38
|
-
const promise = new Promise((resolve, reject) => {
|
|
39
|
-
source.token.onCancellationRequested(() => {
|
|
40
|
-
reject(errors.canceled());
|
|
41
|
-
});
|
|
42
|
-
Promise.resolve(thenable).then(value => {
|
|
43
|
-
source.dispose();
|
|
44
|
-
resolve(value);
|
|
45
|
-
}, err => {
|
|
46
|
-
source.dispose();
|
|
47
|
-
reject(err);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
return new class {
|
|
51
|
-
cancel() {
|
|
52
|
-
source.cancel();
|
|
53
|
-
}
|
|
54
|
-
then(resolve, reject) {
|
|
55
|
-
return promise.then(resolve, reject);
|
|
56
|
-
}
|
|
57
|
-
catch(reject) {
|
|
58
|
-
return this.then(undefined, reject);
|
|
59
|
-
}
|
|
60
|
-
finally(onfinally) {
|
|
61
|
-
return promise.finally(onfinally);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
exports.createCancelablePromise = createCancelablePromise;
|
|
66
|
-
function raceCancellation(promise, token, defaultValue) {
|
|
67
|
-
return Promise.race([promise, new Promise(resolve => token.onCancellationRequested(() => resolve(defaultValue)))]);
|
|
68
|
-
}
|
|
69
|
-
exports.raceCancellation = raceCancellation;
|
|
70
|
-
function raceTimeout(promise, timeout, onTimeout) {
|
|
71
|
-
let promiseResolve = undefined;
|
|
72
|
-
const timer = setTimeout(() => {
|
|
73
|
-
if (promiseResolve)
|
|
74
|
-
promiseResolve();
|
|
75
|
-
if (onTimeout)
|
|
76
|
-
onTimeout();
|
|
77
|
-
}, timeout);
|
|
78
|
-
return Promise.race([
|
|
79
|
-
promise.finally(() => clearTimeout(timer)),
|
|
80
|
-
new Promise(resolve => promiseResolve = resolve)
|
|
81
|
-
]);
|
|
82
|
-
}
|
|
83
|
-
exports.raceTimeout = raceTimeout;
|
|
84
|
-
function asPromise(callback) {
|
|
85
|
-
return new Promise((resolve, reject) => {
|
|
86
|
-
const item = callback();
|
|
87
|
-
if (isThenable(item)) {
|
|
88
|
-
item.then(resolve, reject);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
resolve(item);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
exports.asPromise = asPromise;
|
|
96
|
-
/**
|
|
97
|
-
* A helper to prevent accumulation of sequential async tasks.
|
|
98
|
-
*
|
|
99
|
-
* Imagine a mail man with the sole task of delivering letters. As soon as
|
|
100
|
-
* a letter submitted for delivery, he drives to the destination, delivers it
|
|
101
|
-
* and returns to his base. Imagine that during the trip, N more letters were submitted.
|
|
102
|
-
* When the mail man returns, he picks those N letters and delivers them all in a
|
|
103
|
-
* single trip. Even though N+1 submissions occurred, only 2 deliveries were made.
|
|
104
|
-
*
|
|
105
|
-
* The throttler implements this via the queue() method, by providing it a task
|
|
106
|
-
* factory. Following the example:
|
|
107
|
-
*
|
|
108
|
-
* const throttler = new Throttler();
|
|
109
|
-
* const letters = [];
|
|
110
|
-
*
|
|
111
|
-
* function deliver() {
|
|
112
|
-
* const lettersToDeliver = letters;
|
|
113
|
-
* letters = [];
|
|
114
|
-
* return makeTheTrip(lettersToDeliver);
|
|
115
|
-
* }
|
|
116
|
-
*
|
|
117
|
-
* function onLetterReceived(l) {
|
|
118
|
-
* letters.push(l);
|
|
119
|
-
* throttler.queue(deliver);
|
|
120
|
-
* }
|
|
121
|
-
*/
|
|
122
|
-
class Throttler {
|
|
123
|
-
constructor() {
|
|
124
|
-
this.activePromise = null;
|
|
125
|
-
this.queuedPromise = null;
|
|
126
|
-
this.queuedPromiseFactory = null;
|
|
127
|
-
}
|
|
128
|
-
queue(promiseFactory) {
|
|
129
|
-
if (this.activePromise) {
|
|
130
|
-
this.queuedPromiseFactory = promiseFactory;
|
|
131
|
-
if (!this.queuedPromise) {
|
|
132
|
-
const onComplete = () => {
|
|
133
|
-
this.queuedPromise = null;
|
|
134
|
-
const result = this.queue(this.queuedPromiseFactory);
|
|
135
|
-
this.queuedPromiseFactory = null;
|
|
136
|
-
return result;
|
|
137
|
-
};
|
|
138
|
-
this.queuedPromise = new Promise(c => {
|
|
139
|
-
this.activePromise.then(onComplete, onComplete).then(c);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return new Promise((c, e) => {
|
|
143
|
-
this.queuedPromise.then(c, e);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
this.activePromise = promiseFactory();
|
|
147
|
-
return new Promise((c, e) => {
|
|
148
|
-
this.activePromise.then((result) => {
|
|
149
|
-
this.activePromise = null;
|
|
150
|
-
c(result);
|
|
151
|
-
}, (err) => {
|
|
152
|
-
this.activePromise = null;
|
|
153
|
-
e(err);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
exports.Throttler = Throttler;
|
|
159
|
-
class Sequencer {
|
|
160
|
-
constructor() {
|
|
161
|
-
this.current = Promise.resolve(null);
|
|
162
|
-
}
|
|
163
|
-
queue(promiseTask) {
|
|
164
|
-
return this.current = this.current.then(() => promiseTask());
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
exports.Sequencer = Sequencer;
|
|
168
|
-
/**
|
|
169
|
-
* A helper to delay execution of a task that is being requested often.
|
|
170
|
-
*
|
|
171
|
-
* Following the throttler, now imagine the mail man wants to optimize the number of
|
|
172
|
-
* trips proactively. The trip itself can be long, so he decides not to make the trip
|
|
173
|
-
* as soon as a letter is submitted. Instead he waits a while, in case more
|
|
174
|
-
* letters are submitted. After said waiting period, if no letters were submitted, he
|
|
175
|
-
* decides to make the trip. Imagine that N more letters were submitted after the first
|
|
176
|
-
* one, all within a short period of time between each other. Even though N+1
|
|
177
|
-
* submissions occurred, only 1 delivery was made.
|
|
178
|
-
*
|
|
179
|
-
* The delayer offers this behavior via the trigger() method, into which both the task
|
|
180
|
-
* to be executed and the waiting period (delay) must be passed in as arguments. Following
|
|
181
|
-
* the example:
|
|
182
|
-
*
|
|
183
|
-
* const delayer = new Delayer(WAITING_PERIOD);
|
|
184
|
-
* const letters = [];
|
|
185
|
-
*
|
|
186
|
-
* function letterReceived(l) {
|
|
187
|
-
* letters.push(l);
|
|
188
|
-
* delayer.trigger(() => { return makeTheTrip(); });
|
|
189
|
-
* }
|
|
190
|
-
*/
|
|
191
|
-
class Delayer {
|
|
192
|
-
constructor(defaultDelay) {
|
|
193
|
-
this.defaultDelay = defaultDelay;
|
|
194
|
-
this.timeout = null;
|
|
195
|
-
this.completionPromise = null;
|
|
196
|
-
this.doResolve = null;
|
|
197
|
-
this.doReject = null;
|
|
198
|
-
this.task = null;
|
|
199
|
-
}
|
|
200
|
-
trigger(task, delay = this.defaultDelay) {
|
|
201
|
-
this.task = task;
|
|
202
|
-
this.cancelTimeout();
|
|
203
|
-
if (!this.completionPromise) {
|
|
204
|
-
this.completionPromise = new Promise((c, e) => {
|
|
205
|
-
this.doResolve = c;
|
|
206
|
-
this.doReject = e;
|
|
207
|
-
}).then(() => {
|
|
208
|
-
this.completionPromise = null;
|
|
209
|
-
this.doResolve = null;
|
|
210
|
-
if (this.task) {
|
|
211
|
-
const task = this.task;
|
|
212
|
-
this.task = null;
|
|
213
|
-
return task();
|
|
214
|
-
}
|
|
215
|
-
return undefined;
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
this.timeout = setTimeout(() => {
|
|
219
|
-
this.timeout = null;
|
|
220
|
-
if (this.doResolve) {
|
|
221
|
-
this.doResolve(null);
|
|
222
|
-
}
|
|
223
|
-
}, delay);
|
|
224
|
-
return this.completionPromise;
|
|
225
|
-
}
|
|
226
|
-
isTriggered() {
|
|
227
|
-
return this.timeout !== null;
|
|
228
|
-
}
|
|
229
|
-
cancel() {
|
|
230
|
-
this.cancelTimeout();
|
|
231
|
-
if (this.completionPromise) {
|
|
232
|
-
if (this.doReject) {
|
|
233
|
-
this.doReject(errors.canceled());
|
|
234
|
-
}
|
|
235
|
-
this.completionPromise = null;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
cancelTimeout() {
|
|
239
|
-
if (this.timeout !== null) {
|
|
240
|
-
clearTimeout(this.timeout);
|
|
241
|
-
this.timeout = null;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
dispose() {
|
|
245
|
-
this.cancelTimeout();
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
exports.Delayer = Delayer;
|
|
249
|
-
/**
|
|
250
|
-
* A helper to delay execution of a task that is being requested often, while
|
|
251
|
-
* preventing accumulation of consecutive executions, while the task runs.
|
|
252
|
-
*
|
|
253
|
-
* The mail man is clever and waits for a certain amount of time, before going
|
|
254
|
-
* out to deliver letters. While the mail man is going out, more letters arrive
|
|
255
|
-
* and can only be delivered once he is back. Once he is back the mail man will
|
|
256
|
-
* do one more trip to deliver the letters that have accumulated while he was out.
|
|
257
|
-
*/
|
|
258
|
-
class ThrottledDelayer {
|
|
259
|
-
constructor(defaultDelay) {
|
|
260
|
-
this.delayer = new Delayer(defaultDelay);
|
|
261
|
-
this.throttler = new Throttler();
|
|
262
|
-
}
|
|
263
|
-
trigger(promiseFactory, delay) {
|
|
264
|
-
return this.delayer.trigger(() => this.throttler.queue(promiseFactory), delay);
|
|
265
|
-
}
|
|
266
|
-
isTriggered() {
|
|
267
|
-
return this.delayer.isTriggered();
|
|
268
|
-
}
|
|
269
|
-
cancel() {
|
|
270
|
-
this.delayer.cancel();
|
|
271
|
-
}
|
|
272
|
-
dispose() {
|
|
273
|
-
this.delayer.dispose();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
exports.ThrottledDelayer = ThrottledDelayer;
|
|
277
|
-
/**
|
|
278
|
-
* A barrier that is initially closed and then becomes opened permanently.
|
|
279
|
-
*/
|
|
280
|
-
class Barrier {
|
|
281
|
-
constructor() {
|
|
282
|
-
this._isOpen = false;
|
|
283
|
-
this._promise = new Promise((c, e) => {
|
|
284
|
-
this._completePromise = c;
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
isOpen() {
|
|
288
|
-
return this._isOpen;
|
|
289
|
-
}
|
|
290
|
-
open() {
|
|
291
|
-
this._isOpen = true;
|
|
292
|
-
this._completePromise(true);
|
|
293
|
-
}
|
|
294
|
-
wait() {
|
|
295
|
-
return this._promise;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
exports.Barrier = Barrier;
|
|
299
|
-
function timeout(millis, token) {
|
|
300
|
-
if (!token) {
|
|
301
|
-
return createCancelablePromise(token => timeout(millis, token));
|
|
302
|
-
}
|
|
303
|
-
return new Promise((resolve, reject) => {
|
|
304
|
-
const handle = setTimeout(resolve, millis);
|
|
305
|
-
token.onCancellationRequested(() => {
|
|
306
|
-
clearTimeout(handle);
|
|
307
|
-
reject(errors.canceled());
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
exports.timeout = timeout;
|
|
312
|
-
function disposableTimeout(handler, timeout = 0) {
|
|
313
|
-
const timer = setTimeout(handler, timeout);
|
|
314
|
-
return lifecycle_1.toDisposable(() => clearTimeout(timer));
|
|
315
|
-
}
|
|
316
|
-
exports.disposableTimeout = disposableTimeout;
|
|
317
|
-
function ignoreErrors(promise) {
|
|
318
|
-
return promise.then(undefined, _ => undefined);
|
|
319
|
-
}
|
|
320
|
-
exports.ignoreErrors = ignoreErrors;
|
|
321
|
-
/**
|
|
322
|
-
* Runs the provided list of promise factories in sequential order. The returned
|
|
323
|
-
* promise will complete to an array of results from each promise.
|
|
324
|
-
*/
|
|
325
|
-
function sequence(promiseFactories) {
|
|
326
|
-
const results = [];
|
|
327
|
-
let index = 0;
|
|
328
|
-
const len = promiseFactories.length;
|
|
329
|
-
function next() {
|
|
330
|
-
return index < len ? promiseFactories[index++]() : null;
|
|
331
|
-
}
|
|
332
|
-
function thenHandler(result) {
|
|
333
|
-
if (result !== undefined && result !== null) {
|
|
334
|
-
results.push(result);
|
|
335
|
-
}
|
|
336
|
-
const n = next();
|
|
337
|
-
if (n) {
|
|
338
|
-
return n.then(thenHandler);
|
|
339
|
-
}
|
|
340
|
-
return Promise.resolve(results);
|
|
341
|
-
}
|
|
342
|
-
return Promise.resolve(null).then(thenHandler);
|
|
343
|
-
}
|
|
344
|
-
exports.sequence = sequence;
|
|
345
|
-
function first(promiseFactories, shouldStop = t => !!t, defaultValue = null) {
|
|
346
|
-
let index = 0;
|
|
347
|
-
const len = promiseFactories.length;
|
|
348
|
-
const loop = () => {
|
|
349
|
-
if (index >= len) {
|
|
350
|
-
return Promise.resolve(defaultValue);
|
|
351
|
-
}
|
|
352
|
-
const factory = promiseFactories[index++];
|
|
353
|
-
const promise = Promise.resolve(factory());
|
|
354
|
-
return promise.then(result => {
|
|
355
|
-
if (shouldStop(result)) {
|
|
356
|
-
return Promise.resolve(result);
|
|
357
|
-
}
|
|
358
|
-
return loop();
|
|
359
|
-
});
|
|
360
|
-
};
|
|
361
|
-
return loop();
|
|
362
|
-
}
|
|
363
|
-
exports.first = first;
|
|
364
|
-
/**
|
|
365
|
-
* A helper to queue N promises and run them all with a max degree of parallelism. The helper
|
|
366
|
-
* ensures that at any time no more than M promises are running at the same time.
|
|
367
|
-
*/
|
|
368
|
-
class Limiter {
|
|
369
|
-
constructor(maxDegreeOfParalellism) {
|
|
370
|
-
this._size = 0;
|
|
371
|
-
this.maxDegreeOfParalellism = maxDegreeOfParalellism;
|
|
372
|
-
this.outstandingPromises = [];
|
|
373
|
-
this.runningPromises = 0;
|
|
374
|
-
this._onFinished = new event_1.Emitter();
|
|
375
|
-
}
|
|
376
|
-
get onFinished() {
|
|
377
|
-
return this._onFinished.event;
|
|
378
|
-
}
|
|
379
|
-
get size() {
|
|
380
|
-
return this._size;
|
|
381
|
-
// return this.runningPromises + this.outstandingPromises.length;
|
|
382
|
-
}
|
|
383
|
-
queue(factory) {
|
|
384
|
-
this._size++;
|
|
385
|
-
return new Promise((c, e) => {
|
|
386
|
-
this.outstandingPromises.push({ factory, c, e });
|
|
387
|
-
this.consume();
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
consume() {
|
|
391
|
-
while (this.outstandingPromises.length && this.runningPromises < this.maxDegreeOfParalellism) {
|
|
392
|
-
const iLimitedTask = this.outstandingPromises.shift();
|
|
393
|
-
this.runningPromises++;
|
|
394
|
-
const promise = iLimitedTask.factory();
|
|
395
|
-
promise.then(iLimitedTask.c, iLimitedTask.e);
|
|
396
|
-
promise.then(() => this.consumed(), () => this.consumed());
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
consumed() {
|
|
400
|
-
this._size--;
|
|
401
|
-
this.runningPromises--;
|
|
402
|
-
if (this.outstandingPromises.length > 0) {
|
|
403
|
-
this.consume();
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
this._onFinished.fire();
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
dispose() {
|
|
410
|
-
this._onFinished.dispose();
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
exports.Limiter = Limiter;
|
|
414
|
-
/**
|
|
415
|
-
* A queue is handles one promise at a time and guarantees that at any time only one promise is executing.
|
|
416
|
-
*/
|
|
417
|
-
class Queue extends Limiter {
|
|
418
|
-
constructor() {
|
|
419
|
-
super(1);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
exports.Queue = Queue;
|
|
423
|
-
/**
|
|
424
|
-
* A helper to organize queues per resource. The ResourceQueue makes sure to manage queues per resource
|
|
425
|
-
* by disposing them once the queue is empty.
|
|
426
|
-
*/
|
|
427
|
-
class ResourceQueue {
|
|
428
|
-
constructor() {
|
|
429
|
-
this.queues = new Map();
|
|
430
|
-
}
|
|
431
|
-
queueFor(resource) {
|
|
432
|
-
const key = resource.toString();
|
|
433
|
-
if (!this.queues.has(key)) {
|
|
434
|
-
const queue = new Queue();
|
|
435
|
-
queue.onFinished(() => {
|
|
436
|
-
queue.dispose();
|
|
437
|
-
this.queues.delete(key);
|
|
438
|
-
});
|
|
439
|
-
this.queues.set(key, queue);
|
|
440
|
-
}
|
|
441
|
-
return this.queues.get(key);
|
|
442
|
-
}
|
|
443
|
-
dispose() {
|
|
444
|
-
this.queues.forEach(queue => queue.dispose());
|
|
445
|
-
this.queues.clear();
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
exports.ResourceQueue = ResourceQueue;
|
|
449
|
-
class TimeoutTimer {
|
|
450
|
-
constructor(runner, timeout) {
|
|
451
|
-
this._token = -1;
|
|
452
|
-
if (typeof runner === 'function' && typeof timeout === 'number') {
|
|
453
|
-
this.setIfNotSet(runner, timeout);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
dispose() {
|
|
457
|
-
this.cancel();
|
|
458
|
-
}
|
|
459
|
-
cancel() {
|
|
460
|
-
if (this._token !== -1) {
|
|
461
|
-
clearTimeout(this._token);
|
|
462
|
-
this._token = -1;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
cancelAndSet(runner, timeout) {
|
|
466
|
-
this.cancel();
|
|
467
|
-
this._token = setTimeout(() => {
|
|
468
|
-
this._token = -1;
|
|
469
|
-
runner();
|
|
470
|
-
}, timeout);
|
|
471
|
-
}
|
|
472
|
-
setIfNotSet(runner, timeout) {
|
|
473
|
-
if (this._token !== -1) {
|
|
474
|
-
// timer is already set
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
this._token = setTimeout(() => {
|
|
478
|
-
this._token = -1;
|
|
479
|
-
runner();
|
|
480
|
-
}, timeout);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
exports.TimeoutTimer = TimeoutTimer;
|
|
484
|
-
class IntervalTimer {
|
|
485
|
-
constructor() {
|
|
486
|
-
this._token = -1;
|
|
487
|
-
}
|
|
488
|
-
dispose() {
|
|
489
|
-
this.cancel();
|
|
490
|
-
}
|
|
491
|
-
cancel() {
|
|
492
|
-
if (this._token !== -1) {
|
|
493
|
-
clearInterval(this._token);
|
|
494
|
-
this._token = -1;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
cancelAndSet(runner, interval) {
|
|
498
|
-
this.cancel();
|
|
499
|
-
this._token = setInterval(() => {
|
|
500
|
-
runner();
|
|
501
|
-
}, interval);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
exports.IntervalTimer = IntervalTimer;
|
|
505
|
-
class RunOnceScheduler {
|
|
506
|
-
constructor(runner, timeout) {
|
|
507
|
-
this.timeoutToken = -1;
|
|
508
|
-
this.runner = runner;
|
|
509
|
-
this.timeout = timeout;
|
|
510
|
-
this.timeoutHandler = this.onTimeout.bind(this);
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* Dispose RunOnceScheduler
|
|
514
|
-
*/
|
|
515
|
-
dispose() {
|
|
516
|
-
this.cancel();
|
|
517
|
-
this.runner = null;
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Cancel current scheduled runner (if any).
|
|
521
|
-
*/
|
|
522
|
-
cancel() {
|
|
523
|
-
if (this.isScheduled()) {
|
|
524
|
-
clearTimeout(this.timeoutToken);
|
|
525
|
-
this.timeoutToken = -1;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Cancel previous runner (if any) & schedule a new runner.
|
|
530
|
-
*/
|
|
531
|
-
schedule(delay = this.timeout) {
|
|
532
|
-
this.cancel();
|
|
533
|
-
this.timeoutToken = setTimeout(this.timeoutHandler, delay);
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Returns true if scheduled.
|
|
537
|
-
*/
|
|
538
|
-
isScheduled() {
|
|
539
|
-
return this.timeoutToken !== -1;
|
|
540
|
-
}
|
|
541
|
-
onTimeout() {
|
|
542
|
-
this.timeoutToken = -1;
|
|
543
|
-
if (this.runner) {
|
|
544
|
-
this.doRun();
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
doRun() {
|
|
548
|
-
if (this.runner) {
|
|
549
|
-
this.runner();
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
exports.RunOnceScheduler = RunOnceScheduler;
|
|
554
|
-
class RunOnceWorker extends RunOnceScheduler {
|
|
555
|
-
constructor(runner, timeout) {
|
|
556
|
-
super(runner, timeout);
|
|
557
|
-
this.units = [];
|
|
558
|
-
}
|
|
559
|
-
work(unit) {
|
|
560
|
-
this.units.push(unit);
|
|
561
|
-
if (!this.isScheduled()) {
|
|
562
|
-
this.schedule();
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
doRun() {
|
|
566
|
-
const units = this.units;
|
|
567
|
-
this.units = [];
|
|
568
|
-
if (this.runner) {
|
|
569
|
-
this.runner(units);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
dispose() {
|
|
573
|
-
this.units = [];
|
|
574
|
-
super.dispose();
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
exports.RunOnceWorker = RunOnceWorker;
|
|
578
|
-
(function () {
|
|
579
|
-
if (typeof requestIdleCallback !== 'function' || typeof cancelIdleCallback !== 'function') {
|
|
580
|
-
const dummyIdle = Object.freeze({
|
|
581
|
-
didTimeout: true,
|
|
582
|
-
timeRemaining() { return 15; }
|
|
583
|
-
});
|
|
584
|
-
exports.runWhenIdle = (runner) => {
|
|
585
|
-
const handle = setTimeout(() => runner(dummyIdle));
|
|
586
|
-
let disposed = false;
|
|
587
|
-
return {
|
|
588
|
-
dispose() {
|
|
589
|
-
if (disposed) {
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
disposed = true;
|
|
593
|
-
clearTimeout(handle);
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
else {
|
|
599
|
-
exports.runWhenIdle = (runner, timeout) => {
|
|
600
|
-
const handle = requestIdleCallback(runner, typeof timeout === 'number' ? { timeout } : undefined);
|
|
601
|
-
let disposed = false;
|
|
602
|
-
return {
|
|
603
|
-
dispose() {
|
|
604
|
-
if (disposed) {
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
disposed = true;
|
|
608
|
-
cancelIdleCallback(handle);
|
|
609
|
-
}
|
|
610
|
-
};
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
})();
|
|
614
|
-
/**
|
|
615
|
-
* An implementation of the "idle-until-urgent"-strategy as introduced
|
|
616
|
-
* here: https://philipwalton.com/articles/idle-until-urgent/
|
|
617
|
-
*/
|
|
618
|
-
class IdleValue {
|
|
619
|
-
constructor(executor) {
|
|
620
|
-
this._didRun = false;
|
|
621
|
-
this._executor = () => {
|
|
622
|
-
try {
|
|
623
|
-
this._value = executor();
|
|
624
|
-
}
|
|
625
|
-
catch (err) {
|
|
626
|
-
this._error = err;
|
|
627
|
-
}
|
|
628
|
-
finally {
|
|
629
|
-
this._didRun = true;
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
this._handle = exports.runWhenIdle(() => this._executor());
|
|
633
|
-
}
|
|
634
|
-
dispose() {
|
|
635
|
-
this._handle.dispose();
|
|
636
|
-
}
|
|
637
|
-
get value() {
|
|
638
|
-
if (!this._didRun) {
|
|
639
|
-
this._handle.dispose();
|
|
640
|
-
this._executor();
|
|
641
|
-
}
|
|
642
|
-
if (this._error) {
|
|
643
|
-
throw this._error;
|
|
644
|
-
}
|
|
645
|
-
return this._value;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
exports.IdleValue = IdleValue;
|
|
649
|
-
//#endregion
|
|
650
|
-
async function retry(task, delay, retries) {
|
|
651
|
-
let lastError;
|
|
652
|
-
for (let i = 0; i < retries; i++) {
|
|
653
|
-
try {
|
|
654
|
-
return await task();
|
|
655
|
-
}
|
|
656
|
-
catch (error) {
|
|
657
|
-
lastError = error;
|
|
658
|
-
await timeout(delay);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
throw lastError;
|
|
662
|
-
}
|
|
663
|
-
exports.retry = retry;
|
|
664
|
-
class TaskSequentializer {
|
|
665
|
-
hasPending(taskId) {
|
|
666
|
-
if (!this._pending) {
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
if (typeof taskId === 'number') {
|
|
670
|
-
return this._pending.taskId === taskId;
|
|
671
|
-
}
|
|
672
|
-
return !!this._pending;
|
|
673
|
-
}
|
|
674
|
-
get pending() {
|
|
675
|
-
return this._pending ? this._pending.promise : undefined;
|
|
676
|
-
}
|
|
677
|
-
cancelPending() {
|
|
678
|
-
if (this._pending)
|
|
679
|
-
this._pending.cancel();
|
|
680
|
-
}
|
|
681
|
-
setPending(taskId, promise, onCancel) {
|
|
682
|
-
this._pending = { taskId: taskId, cancel: () => onCancel === null || onCancel === void 0 ? void 0 : onCancel(), promise };
|
|
683
|
-
promise.then(() => this.donePending(taskId), () => this.donePending(taskId));
|
|
684
|
-
return promise;
|
|
685
|
-
}
|
|
686
|
-
donePending(taskId) {
|
|
687
|
-
if (this._pending && taskId === this._pending.taskId) {
|
|
688
|
-
// only set pending to done if the promise finished that is associated with that taskId
|
|
689
|
-
this._pending = undefined;
|
|
690
|
-
// schedule the next task now that we are free if we have any
|
|
691
|
-
this.triggerNext();
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
triggerNext() {
|
|
695
|
-
if (this._next) {
|
|
696
|
-
const next = this._next;
|
|
697
|
-
this._next = undefined;
|
|
698
|
-
// Run next task and complete on the associated promise
|
|
699
|
-
next.run().then(next.promiseResolve, next.promiseReject);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
setNext(run) {
|
|
703
|
-
// this is our first next task, so we create associated promise with it
|
|
704
|
-
// so that we can return a promise that completes when the task has
|
|
705
|
-
// completed.
|
|
706
|
-
if (!this._next) {
|
|
707
|
-
let promiseResolve;
|
|
708
|
-
let promiseReject;
|
|
709
|
-
const promise = new Promise((resolve, reject) => {
|
|
710
|
-
promiseResolve = resolve;
|
|
711
|
-
promiseReject = reject;
|
|
712
|
-
});
|
|
713
|
-
this._next = {
|
|
714
|
-
run,
|
|
715
|
-
promise,
|
|
716
|
-
promiseResolve: promiseResolve,
|
|
717
|
-
promiseReject: promiseReject
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
// we have a previous next task, just overwrite it
|
|
721
|
-
else {
|
|
722
|
-
this._next.run = run;
|
|
723
|
-
}
|
|
724
|
-
return this._next.promise;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
exports.TaskSequentializer = TaskSequentializer;
|
|
728
|
-
//#endregion
|