This repository has been archived by the owner on Jun 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
app.vuetify.js
92 lines (76 loc) · 1.72 KB
/
app.vuetify.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Checks if a value is (null) or (undefined).
*
* @param {any} val The balue to check.
*
* @return {Boolean} Is (null) or (undefined).
*/
function ego_is_nil(val) {
return 'undefined' === typeof val ||
null === val;
}
/**
* Asks the user in Visual Studio Code, if an external URL should be opened.
*
* @param {String} url The requested URL to open.
* @param {String} text The display text.
*/
function ego_open_external_url(url, text) {
ego_post('openExternalUrl', {
text: ego_to_string(text),
url: ego_to_string(url)
});
}
/**
* Converts a value to a string, which is not (null) and (undefined), if needed.
*
* @param {any} val The value to convert.
*
* @return {String} The value as string.
*/
function ego_to_string(val) {
if ('string' === typeof val) {
return val;
}
if (ego_is_nil(val)) {
return '';
}
if (val instanceof Error) {
return `[${val.name}] '${val.message}'
${val.stack}`;
}
if ('function' === typeof val['toString']) {
return String(val.toString());
}
return String(val);
}
// message from VSCode (code behind)
window.addEventListener('message', (e) => {
if (!e) {
return;
}
const MESSAGE = e.data;
if (!MESSAGE) {
return;
}
const COMMAND = ego_to_string(MESSAGE.command)
.trim();
if ('' === COMMAND) {
return;
}
if ('undefined' === typeof EGO_VUE) {
return;
}
if (!EGO_VUE.$onCommand) {
return;
}
try {
Promise.resolve(
EGO_VUE.$onCommand(COMMAND, MESSAGE.data)
).catch((err) => {
ego_log(err);
});
} catch (e) {
ego_log(e);
}
});