forked from damien122/Autoit-Visual-Studio-Extension
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathai_showMessage.js
57 lines (55 loc) · 1.82 KB
/
ai_showMessage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { window } from 'vscode';
import { performance } from 'node:perf_hooks';
let lastHide = 0;
// accepts new option parameter in second argument: timeout
const initMessage = type => {
const timers = {};
const func = (...args) => {
let timeout;
const [message, options] = args;
if (options && options instanceof Object && !(options instanceof Array)) {
({ timeout } = options);
// not sure if we need to bother sanitize options object or not, seems to work as is
// delete options.timeout;
// if (!options.keys().length)
// args.splice(1,1);
}
const clearTimeoutEx = () => {
clearTimeout(timers[message]);
delete timers[message];
};
clearTimeoutEx();
let isHidden = false;
const callback = () => {
clearTimeoutEx();
// https://github.com/microsoft/vscode/issues/153693
for (
let i = 0;
i < 4;
i += 1 // showing rapidly 4 messages hides the message...an exploit?
)
window[type].apply(window[type], args);
isHidden = true;
lastHide = performance.now();
};
timers[message] = timeout !== undefined && setTimeout(callback, timeout);
// vscode doesn't display new message if previous message was forcibly hidden less then 1 sec ago
const messageTimeout = 900 - (performance.now() - lastHide);
return {
get isHidden() {
return isHidden;
},
hide: callback,
message: new Promise(resolve =>
setTimeout(
() => resolve(window[type].apply(window[type], args).finally(clearTimeoutEx)),
messageTimeout,
),
),
};
};
return func;
};
export const showInformationMessage = initMessage('showInformationMessage');
export const showErrorMessage = initMessage('showErrorMessage');
export const messages = { error: {}, info: {} };