@lvce-editor/about-view 1.0.0
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/aboutWorkerMain.js +1215 -0
- package/package.json +10 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Lvce Editor
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,1215 @@
|
|
1
|
+
const commands = Object.create(null);
|
2
|
+
const registerCommand = (key, fn) => {
|
3
|
+
commands[key] = fn;
|
4
|
+
};
|
5
|
+
const register = commandMap => {
|
6
|
+
for (const [key, value] of Object.entries(commandMap)) {
|
7
|
+
registerCommand(key, value);
|
8
|
+
}
|
9
|
+
};
|
10
|
+
const getCommand = key => {
|
11
|
+
return commands[key];
|
12
|
+
};
|
13
|
+
const execute = (command, ...args) => {
|
14
|
+
const fn = getCommand(command);
|
15
|
+
if (!fn) {
|
16
|
+
throw new Error(`command not found ${command}`);
|
17
|
+
}
|
18
|
+
return fn(...args);
|
19
|
+
};
|
20
|
+
|
21
|
+
const emptyObject = {};
|
22
|
+
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
23
|
+
const i18nString = (key, placeholders = emptyObject) => {
|
24
|
+
if (placeholders === emptyObject) {
|
25
|
+
return key;
|
26
|
+
}
|
27
|
+
const replacer = (match, rest) => {
|
28
|
+
// @ts-ignore
|
29
|
+
return placeholders[rest];
|
30
|
+
};
|
31
|
+
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
32
|
+
};
|
33
|
+
|
34
|
+
// based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
|
35
|
+
|
36
|
+
/**
|
37
|
+
* @enum {string}
|
38
|
+
*/
|
39
|
+
const UiStrings$1 = {
|
40
|
+
OneSecondAgo: '1 second ago',
|
41
|
+
SomeSecondsAgo: '{PH1} seconds ago',
|
42
|
+
OneMinuteAgo: '1 minute ago',
|
43
|
+
SomeMinutesAgo: '{PH1} minutes ago',
|
44
|
+
OneHourAgo: '1 hour ago',
|
45
|
+
SomeHoursAgo: '{PH1} hours ago',
|
46
|
+
OneDayAgo: '1 day ago',
|
47
|
+
SomeDaysAgo: '{PH1} days ago',
|
48
|
+
OneWeekAgo: '1 week ago',
|
49
|
+
SomeWeeksAgo: '{PH1} weeks ago',
|
50
|
+
OneMonthAgo: '1 month ago',
|
51
|
+
SomeMonthsAgo: '{PH1} months ago',
|
52
|
+
OneYearAgo: '1 year ago',
|
53
|
+
SomeYearsAgo: '{PH1} years ago',
|
54
|
+
InOneSecond: 'in 1 second',
|
55
|
+
InSomeSeconds: 'in {PH1} seconds',
|
56
|
+
InOneMinute: 'in 1 minute',
|
57
|
+
InSomeMinutes: 'in {PH1} minutes',
|
58
|
+
InOneHour: 'in 1 hour',
|
59
|
+
InSomeHours: 'in {PH1} hours',
|
60
|
+
InOneDay: 'in 1 day',
|
61
|
+
InSomeDays: 'in {PH1} days',
|
62
|
+
InOneWeek: 'in 1 week',
|
63
|
+
InSomeWeeks: 'in {PH1} weeks',
|
64
|
+
InOneMonth: 'in 1 month',
|
65
|
+
InSomeMonths: 'in {PH1} months',
|
66
|
+
InOneYear: 'in 1 year',
|
67
|
+
InSomeYears: 'in {PH1} years'
|
68
|
+
};
|
69
|
+
const oneSecondAgo = () => {
|
70
|
+
return i18nString(UiStrings$1.OneSecondAgo);
|
71
|
+
};
|
72
|
+
const someSecondsAgo = seconds => {
|
73
|
+
return i18nString(UiStrings$1.SomeSecondsAgo, {
|
74
|
+
PH1: seconds
|
75
|
+
});
|
76
|
+
};
|
77
|
+
const oneMinuteAgo = () => {
|
78
|
+
return i18nString(UiStrings$1.OneMinuteAgo);
|
79
|
+
};
|
80
|
+
const someMinutesAgo = minutes => {
|
81
|
+
return i18nString(UiStrings$1.SomeMinutesAgo, {
|
82
|
+
PH1: minutes
|
83
|
+
});
|
84
|
+
};
|
85
|
+
const oneHourAgo = () => {
|
86
|
+
return i18nString(UiStrings$1.OneHourAgo);
|
87
|
+
};
|
88
|
+
const someHoursAgo = hours => {
|
89
|
+
return i18nString(UiStrings$1.SomeHoursAgo, {
|
90
|
+
PH1: hours
|
91
|
+
});
|
92
|
+
};
|
93
|
+
const oneDayAgo = () => {
|
94
|
+
return i18nString(UiStrings$1.OneDayAgo);
|
95
|
+
};
|
96
|
+
const someDaysAgo = days => {
|
97
|
+
return i18nString(UiStrings$1.SomeDaysAgo, {
|
98
|
+
PH1: days
|
99
|
+
});
|
100
|
+
};
|
101
|
+
const oneWeekAgo = () => {
|
102
|
+
return i18nString(UiStrings$1.OneWeekAgo);
|
103
|
+
};
|
104
|
+
const someWeeksAgo = weeks => {
|
105
|
+
return i18nString(UiStrings$1.SomeWeeksAgo, {
|
106
|
+
PH1: weeks
|
107
|
+
});
|
108
|
+
};
|
109
|
+
const oneMonthAgo = () => {
|
110
|
+
return i18nString(UiStrings$1.OneMonthAgo);
|
111
|
+
};
|
112
|
+
const someMonthsAgo = months => {
|
113
|
+
return i18nString(UiStrings$1.SomeMonthsAgo, {
|
114
|
+
PH1: months
|
115
|
+
});
|
116
|
+
};
|
117
|
+
const oneYearAgo = () => {
|
118
|
+
return i18nString(UiStrings$1.OneYearAgo);
|
119
|
+
};
|
120
|
+
const someYearsAgo = years => {
|
121
|
+
return i18nString(UiStrings$1.SomeYearsAgo, {
|
122
|
+
PH1: years
|
123
|
+
});
|
124
|
+
};
|
125
|
+
const inOneSecond = () => {
|
126
|
+
return i18nString(UiStrings$1.InOneSecond);
|
127
|
+
};
|
128
|
+
const inSomeSeconds = seconds => {
|
129
|
+
return i18nString(UiStrings$1.InSomeSeconds, {
|
130
|
+
PH1: seconds
|
131
|
+
});
|
132
|
+
};
|
133
|
+
const inOneMinute = () => {
|
134
|
+
return i18nString(UiStrings$1.InOneMinute);
|
135
|
+
};
|
136
|
+
const inSomeMinutes = minutes => {
|
137
|
+
return i18nString(UiStrings$1.InSomeMinutes, {
|
138
|
+
PH1: minutes
|
139
|
+
});
|
140
|
+
};
|
141
|
+
const inOneHour = () => {
|
142
|
+
return i18nString(UiStrings$1.InOneHour);
|
143
|
+
};
|
144
|
+
const inSomeHours = hours => {
|
145
|
+
return i18nString(UiStrings$1.InSomeHours, {
|
146
|
+
PH1: hours
|
147
|
+
});
|
148
|
+
};
|
149
|
+
const inOneDay = () => {
|
150
|
+
return i18nString(UiStrings$1.InOneDay);
|
151
|
+
};
|
152
|
+
const inSomeDays = days => {
|
153
|
+
return i18nString(UiStrings$1.InSomeDays, {
|
154
|
+
PH1: days
|
155
|
+
});
|
156
|
+
};
|
157
|
+
const inOneWeek = () => {
|
158
|
+
return i18nString(UiStrings$1.InOneWeek);
|
159
|
+
};
|
160
|
+
const inSomeWeeks = weeks => {
|
161
|
+
return i18nString(UiStrings$1.InSomeWeeks, {
|
162
|
+
PH1: weeks
|
163
|
+
});
|
164
|
+
};
|
165
|
+
const inOneMonth = () => {
|
166
|
+
return i18nString(UiStrings$1.InOneMonth);
|
167
|
+
};
|
168
|
+
const inSomeMonths = months => {
|
169
|
+
return i18nString(UiStrings$1.InSomeMonths, {
|
170
|
+
PH1: months
|
171
|
+
});
|
172
|
+
};
|
173
|
+
const inOneYear = () => {
|
174
|
+
return i18nString(UiStrings$1.InOneYear);
|
175
|
+
};
|
176
|
+
const inSomeYears = years => {
|
177
|
+
return i18nString(UiStrings$1.InSomeYears, {
|
178
|
+
PH1: years
|
179
|
+
});
|
180
|
+
};
|
181
|
+
|
182
|
+
// based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
|
183
|
+
const minute = 60;
|
184
|
+
const hour = minute * 60;
|
185
|
+
const day = hour * 24;
|
186
|
+
const week = day * 7;
|
187
|
+
const month = day * 30;
|
188
|
+
const year = day * 365;
|
189
|
+
const formatDatePast = seconds => {
|
190
|
+
if (seconds < minute) {
|
191
|
+
if (seconds === 1) {
|
192
|
+
return oneSecondAgo();
|
193
|
+
}
|
194
|
+
return someSecondsAgo(seconds);
|
195
|
+
}
|
196
|
+
if (seconds < hour) {
|
197
|
+
const minutes = Math.floor(seconds / minute);
|
198
|
+
if (minutes === 1) {
|
199
|
+
return oneMinuteAgo();
|
200
|
+
}
|
201
|
+
return someMinutesAgo(minutes);
|
202
|
+
}
|
203
|
+
if (seconds < day) {
|
204
|
+
const days = Math.floor(seconds / hour);
|
205
|
+
if (days === 1) {
|
206
|
+
return oneHourAgo();
|
207
|
+
}
|
208
|
+
return someHoursAgo(days);
|
209
|
+
}
|
210
|
+
if (seconds < week) {
|
211
|
+
const days = Math.floor(seconds / day);
|
212
|
+
if (days === 1) {
|
213
|
+
return oneDayAgo();
|
214
|
+
}
|
215
|
+
return someDaysAgo(days);
|
216
|
+
}
|
217
|
+
if (seconds < month) {
|
218
|
+
const weeks = Math.floor(seconds / week);
|
219
|
+
if (weeks === 1) {
|
220
|
+
return oneWeekAgo();
|
221
|
+
}
|
222
|
+
return someWeeksAgo(weeks);
|
223
|
+
}
|
224
|
+
if (seconds < year) {
|
225
|
+
const months = Math.floor(seconds / month);
|
226
|
+
if (months === 1) {
|
227
|
+
return oneMonthAgo();
|
228
|
+
}
|
229
|
+
return someMonthsAgo(months);
|
230
|
+
}
|
231
|
+
const years = Math.floor(seconds / year);
|
232
|
+
if (years === 1) {
|
233
|
+
return oneYearAgo();
|
234
|
+
}
|
235
|
+
return someYearsAgo(years);
|
236
|
+
};
|
237
|
+
const formatDateFuture = seconds => {
|
238
|
+
if (seconds < minute) {
|
239
|
+
if (seconds === 1) {
|
240
|
+
return inOneSecond();
|
241
|
+
}
|
242
|
+
return inSomeSeconds(seconds);
|
243
|
+
}
|
244
|
+
if (seconds < hour) {
|
245
|
+
const minutes = Math.floor(seconds / minute);
|
246
|
+
if (minutes === 1) {
|
247
|
+
return inOneMinute();
|
248
|
+
}
|
249
|
+
return inSomeMinutes(minutes);
|
250
|
+
}
|
251
|
+
if (seconds < day) {
|
252
|
+
const days = Math.floor(seconds / hour);
|
253
|
+
if (days === 1) {
|
254
|
+
return inOneHour();
|
255
|
+
}
|
256
|
+
return inSomeHours(days);
|
257
|
+
}
|
258
|
+
if (seconds < week) {
|
259
|
+
const days = Math.floor(seconds / day);
|
260
|
+
if (days === 1) {
|
261
|
+
return inOneDay();
|
262
|
+
}
|
263
|
+
return inSomeDays(days);
|
264
|
+
}
|
265
|
+
if (seconds < month) {
|
266
|
+
const weeks = Math.floor(seconds / week);
|
267
|
+
if (weeks === 1) {
|
268
|
+
return inOneWeek();
|
269
|
+
}
|
270
|
+
return inSomeWeeks(weeks);
|
271
|
+
}
|
272
|
+
if (seconds < year) {
|
273
|
+
const months = Math.floor(seconds / month);
|
274
|
+
if (months === 1) {
|
275
|
+
return inOneMonth();
|
276
|
+
}
|
277
|
+
return inSomeMonths(months);
|
278
|
+
}
|
279
|
+
const years = Math.floor(seconds / year);
|
280
|
+
if (years === 1) {
|
281
|
+
return inOneYear();
|
282
|
+
}
|
283
|
+
return inSomeYears(years);
|
284
|
+
};
|
285
|
+
const formatDate = (date, now) => {
|
286
|
+
const difference = now - date;
|
287
|
+
const seconds = Math.round(difference / 1000);
|
288
|
+
if (seconds >= 0) {
|
289
|
+
return formatDatePast(seconds);
|
290
|
+
}
|
291
|
+
return formatDateFuture(-seconds);
|
292
|
+
};
|
293
|
+
|
294
|
+
const formatAboutDate = isoDate => {
|
295
|
+
if (!isoDate) {
|
296
|
+
return 'unknown';
|
297
|
+
}
|
298
|
+
const date = new Date(isoDate).getTime();
|
299
|
+
if (isNaN(date)) {
|
300
|
+
return `Invalid Date: ${isoDate}`;
|
301
|
+
}
|
302
|
+
const now = Date.now();
|
303
|
+
const ago = formatDate(date, now);
|
304
|
+
return `${isoDate} (${ago})`;
|
305
|
+
};
|
306
|
+
|
307
|
+
const NewLine$2 = '\n';
|
308
|
+
|
309
|
+
const joinLines$1 = lines => {
|
310
|
+
return lines.join(NewLine$2);
|
311
|
+
};
|
312
|
+
|
313
|
+
const version = '0.0.0-dev';
|
314
|
+
const commit = 'unknown commit';
|
315
|
+
const date = '';
|
316
|
+
const getElectronVersion = () => {
|
317
|
+
return '';
|
318
|
+
};
|
319
|
+
const getNodeVersion = () => {
|
320
|
+
return '';
|
321
|
+
};
|
322
|
+
const getChromeVersion = () => {
|
323
|
+
return '';
|
324
|
+
};
|
325
|
+
const getVersion = () => {
|
326
|
+
return version;
|
327
|
+
};
|
328
|
+
const getCommit = () => {
|
329
|
+
return commit;
|
330
|
+
};
|
331
|
+
const getV8Version = () => {
|
332
|
+
return '';
|
333
|
+
};
|
334
|
+
const getDate = () => {
|
335
|
+
return date;
|
336
|
+
};
|
337
|
+
|
338
|
+
const getDetailString = async () => {
|
339
|
+
const [electronVersion, nodeVersion, chromeVersion, version, commit, v8Version, date] = await Promise.all([getElectronVersion(), getNodeVersion(), getChromeVersion(), getVersion(), getCommit(), getV8Version(), getDate()]);
|
340
|
+
const formattedDate = formatAboutDate(date);
|
341
|
+
const lines = [`Version: ${version}`, `Commit: ${commit}`, `Date: ${formattedDate}`, `Electron: ${electronVersion}`, `Chromium: ${chromeVersion}`, `Node: ${nodeVersion}`, `V8: ${v8Version}`];
|
342
|
+
return joinLines$1(lines);
|
343
|
+
};
|
344
|
+
|
345
|
+
const getBrowser = () => {
|
346
|
+
return `${navigator.userAgent}`;
|
347
|
+
};
|
348
|
+
|
349
|
+
const getDetailStringWeb = () => {
|
350
|
+
const version$1 = version;
|
351
|
+
const commit$1 = commit;
|
352
|
+
const date$1 = date;
|
353
|
+
const formattedDate = formatAboutDate(date$1);
|
354
|
+
const browser = getBrowser();
|
355
|
+
const lines = [`Version: ${version$1}`, `Commit: ${commit$1}`, `Date: ${formattedDate}`, `Browser: ${browser}`];
|
356
|
+
return lines;
|
357
|
+
};
|
358
|
+
|
359
|
+
const HandleClickClose = 'handleClickClose';
|
360
|
+
const HandleClickCopy = 'handleClickCopy';
|
361
|
+
const HandleClickOk = 'handleClickOk';
|
362
|
+
const HandleContextMenu = 'handleContextMenu';
|
363
|
+
const HandleFocusIn = 'handleFocusIn';
|
364
|
+
|
365
|
+
const Button$2 = 1;
|
366
|
+
const Div = 4;
|
367
|
+
const Text = 12;
|
368
|
+
const Br = 55;
|
369
|
+
|
370
|
+
const Button$1 = 'Button';
|
371
|
+
const ButtonPrimary = 'ButtonPrimary';
|
372
|
+
const ButtonSecondary = 'ButtonSecondary';
|
373
|
+
const DialogButtonsRow = 'DialogButtonsRow';
|
374
|
+
const DialogClose = 'DialogClose';
|
375
|
+
const DialogContent = 'DialogContent';
|
376
|
+
const DialogContentRight = 'DialogContentRight';
|
377
|
+
const DialogHeading = 'DialogHeading';
|
378
|
+
const DialogMessage = 'DialogMessage';
|
379
|
+
const DialogMessageRow = 'DialogMessageRow';
|
380
|
+
const DialogToolBarRow = 'DialogToolBarRow';
|
381
|
+
|
382
|
+
const text = data => {
|
383
|
+
return {
|
384
|
+
type: Text,
|
385
|
+
text: data,
|
386
|
+
childCount: 0
|
387
|
+
};
|
388
|
+
};
|
389
|
+
|
390
|
+
const br = {
|
391
|
+
type: Br,
|
392
|
+
childCount: 0
|
393
|
+
};
|
394
|
+
const renderLine = (line, index) => {
|
395
|
+
if (index === 0) {
|
396
|
+
return [text(line)];
|
397
|
+
}
|
398
|
+
return [br, text(line)];
|
399
|
+
};
|
400
|
+
const getAboutContentVirtualDom = lines => {
|
401
|
+
const dom = [{
|
402
|
+
type: Div,
|
403
|
+
className: DialogMessage,
|
404
|
+
childCount: lines.length * 2 - 1
|
405
|
+
}, ...lines.flatMap(renderLine)];
|
406
|
+
return dom;
|
407
|
+
};
|
408
|
+
|
409
|
+
const Button = 'button';
|
410
|
+
const Dialog = 'dialog';
|
411
|
+
|
412
|
+
const getPrimaryButtonVirtualDom = (message, onClick) => {
|
413
|
+
return [{
|
414
|
+
type: Button$2,
|
415
|
+
className: `${Button$1} ${ButtonPrimary}`,
|
416
|
+
onClick,
|
417
|
+
childCount: 1
|
418
|
+
}, text(message)];
|
419
|
+
};
|
420
|
+
const getSecondaryButtonVirtualDom = (message, onClick) => {
|
421
|
+
return [{
|
422
|
+
type: Button$2,
|
423
|
+
className: `${Button$1} ${ButtonSecondary}`,
|
424
|
+
onClick,
|
425
|
+
childCount: 1
|
426
|
+
}, text(message)];
|
427
|
+
};
|
428
|
+
|
429
|
+
const Focusable = -1;
|
430
|
+
|
431
|
+
const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copyMessage, productName) => {
|
432
|
+
const dom = [{
|
433
|
+
type: Div,
|
434
|
+
className: DialogContent,
|
435
|
+
tabIndex: Focusable,
|
436
|
+
role: Dialog,
|
437
|
+
ariaModal: 'true',
|
438
|
+
ariaLabelledBy: 'DialogIcon DialogHeading',
|
439
|
+
onFocusIn: HandleFocusIn,
|
440
|
+
childCount: 3
|
441
|
+
}, {
|
442
|
+
type: Div,
|
443
|
+
className: DialogToolBarRow,
|
444
|
+
childCount: 1
|
445
|
+
}, {
|
446
|
+
type: Div,
|
447
|
+
className: DialogClose,
|
448
|
+
ariaLabel: closeMessage,
|
449
|
+
role: Button,
|
450
|
+
onClick: HandleClickClose,
|
451
|
+
childCount: 1
|
452
|
+
}, {
|
453
|
+
type: Div,
|
454
|
+
className: 'MaskIcon MaskIconClose',
|
455
|
+
childCount: 0
|
456
|
+
}, {
|
457
|
+
type: Div,
|
458
|
+
className: DialogMessageRow,
|
459
|
+
childCount: 2
|
460
|
+
}, {
|
461
|
+
type: Div,
|
462
|
+
className: 'DialogIcon DialogInfoIcon MaskIcon MaskIconInfo',
|
463
|
+
id: 'DialogIcon',
|
464
|
+
ariaLabel: infoMessage,
|
465
|
+
childCount: 0
|
466
|
+
}, {
|
467
|
+
type: Div,
|
468
|
+
className: DialogContentRight,
|
469
|
+
childCount: 2
|
470
|
+
}, {
|
471
|
+
type: Div,
|
472
|
+
id: 'DialogHeading',
|
473
|
+
className: DialogHeading,
|
474
|
+
childCount: 1
|
475
|
+
}, text(productName), ...content, {
|
476
|
+
type: Div,
|
477
|
+
className: DialogButtonsRow,
|
478
|
+
childCount: 2
|
479
|
+
}, ...getSecondaryButtonVirtualDom(okMessage, HandleClickOk), ...getPrimaryButtonVirtualDom(copyMessage, HandleClickCopy)];
|
480
|
+
return dom;
|
481
|
+
};
|
482
|
+
|
483
|
+
const getAboutVirtualDom = (productName, lines, closeMessage, okMessage, copyMessage, infoMessage) => {
|
484
|
+
const content = getAboutContentVirtualDom(lines);
|
485
|
+
return [{
|
486
|
+
type: Div,
|
487
|
+
className: 'Viewlet About',
|
488
|
+
onContextMenu: HandleContextMenu,
|
489
|
+
childCount: 1
|
490
|
+
}, ...getDialogVirtualDom(content, closeMessage, infoMessage, okMessage, copyMessage, productName)];
|
491
|
+
};
|
492
|
+
|
493
|
+
const Ok = 1;
|
494
|
+
const Copy = 2;
|
495
|
+
|
496
|
+
/**
|
497
|
+
* @enum {string}
|
498
|
+
*/
|
499
|
+
const UiStrings = {
|
500
|
+
Ok: 'Ok',
|
501
|
+
Copy: 'Copy',
|
502
|
+
Version: 'Version',
|
503
|
+
Commit: 'Commit',
|
504
|
+
Date: 'Date',
|
505
|
+
Browser: 'Browser',
|
506
|
+
Info: 'Info',
|
507
|
+
Close: 'Close',
|
508
|
+
CloseDialog: 'Close Dialog'
|
509
|
+
};
|
510
|
+
const ok = () => {
|
511
|
+
return i18nString(UiStrings.Ok);
|
512
|
+
};
|
513
|
+
const copy = () => {
|
514
|
+
return i18nString(UiStrings.Copy);
|
515
|
+
};
|
516
|
+
const info = () => {
|
517
|
+
return i18nString(UiStrings.Info);
|
518
|
+
};
|
519
|
+
const closeDialog = () => {
|
520
|
+
return i18nString(UiStrings.CloseDialog);
|
521
|
+
};
|
522
|
+
|
523
|
+
const renderDialog = {
|
524
|
+
isEqual(oldState, newState) {
|
525
|
+
return oldState.productName === newState.productName && oldState.lines === newState.lines;
|
526
|
+
},
|
527
|
+
apply(oldState, newState) {
|
528
|
+
const okMessage = ok();
|
529
|
+
const copyMessage = copy();
|
530
|
+
const closeMessage = closeDialog();
|
531
|
+
const infoMessage = info();
|
532
|
+
const dom = getAboutVirtualDom(newState.productName, newState.lines, closeMessage, okMessage, copyMessage, infoMessage);
|
533
|
+
return ['Viewlet.setDom2', dom];
|
534
|
+
}
|
535
|
+
};
|
536
|
+
const getFocusSelector = focusId => {
|
537
|
+
switch (focusId) {
|
538
|
+
case Copy:
|
539
|
+
return '.ButtonPrimary';
|
540
|
+
case Ok:
|
541
|
+
return '.ButtonSecondary';
|
542
|
+
default:
|
543
|
+
return '';
|
544
|
+
}
|
545
|
+
};
|
546
|
+
const renderFocus = {
|
547
|
+
isEqual(oldState, newState) {
|
548
|
+
return oldState.focusId === newState.focusId;
|
549
|
+
},
|
550
|
+
apply(oldState, newState) {
|
551
|
+
const selector = getFocusSelector(newState.focusId);
|
552
|
+
return ['setFocused', selector];
|
553
|
+
}
|
554
|
+
};
|
555
|
+
const render = [renderDialog, renderFocus];
|
556
|
+
const doRender = (oldState, newState) => {
|
557
|
+
const commands = [];
|
558
|
+
for (const fn of render) {
|
559
|
+
if (!fn.isEqual(oldState, newState)) {
|
560
|
+
commands.push(fn.apply(oldState, newState));
|
561
|
+
}
|
562
|
+
}
|
563
|
+
return commands;
|
564
|
+
};
|
565
|
+
|
566
|
+
const commandMap = {
|
567
|
+
'About.getVirtualDom': getAboutVirtualDom,
|
568
|
+
'About.getDetailStringWeb': getDetailStringWeb(),
|
569
|
+
'About.getDetailString': getDetailString(),
|
570
|
+
'About.render': doRender
|
571
|
+
};
|
572
|
+
|
573
|
+
const Two = '2.0';
|
574
|
+
class AssertionError extends Error {
|
575
|
+
constructor(message) {
|
576
|
+
super(message);
|
577
|
+
this.name = 'AssertionError';
|
578
|
+
}
|
579
|
+
}
|
580
|
+
const getType$1 = value => {
|
581
|
+
switch (typeof value) {
|
582
|
+
case 'number':
|
583
|
+
return 'number';
|
584
|
+
case 'function':
|
585
|
+
return 'function';
|
586
|
+
case 'string':
|
587
|
+
return 'string';
|
588
|
+
case 'object':
|
589
|
+
if (value === null) {
|
590
|
+
return 'null';
|
591
|
+
}
|
592
|
+
if (Array.isArray(value)) {
|
593
|
+
return 'array';
|
594
|
+
}
|
595
|
+
return 'object';
|
596
|
+
case 'boolean':
|
597
|
+
return 'boolean';
|
598
|
+
default:
|
599
|
+
return 'unknown';
|
600
|
+
}
|
601
|
+
};
|
602
|
+
const number = value => {
|
603
|
+
const type = getType$1(value);
|
604
|
+
if (type !== 'number') {
|
605
|
+
throw new AssertionError('expected value to be of type number');
|
606
|
+
}
|
607
|
+
};
|
608
|
+
const state$1 = {
|
609
|
+
callbacks: Object.create(null)
|
610
|
+
};
|
611
|
+
const get = id => {
|
612
|
+
return state$1.callbacks[id];
|
613
|
+
};
|
614
|
+
const remove = id => {
|
615
|
+
delete state$1.callbacks[id];
|
616
|
+
};
|
617
|
+
const warn = (...args) => {
|
618
|
+
console.warn(...args);
|
619
|
+
};
|
620
|
+
const resolve = (id, args) => {
|
621
|
+
number(id);
|
622
|
+
const fn = get(id);
|
623
|
+
if (!fn) {
|
624
|
+
console.log(args);
|
625
|
+
warn(`callback ${id} may already be disposed`);
|
626
|
+
return;
|
627
|
+
}
|
628
|
+
fn(args);
|
629
|
+
remove(id);
|
630
|
+
};
|
631
|
+
class JsonRpcError extends Error {
|
632
|
+
constructor(message) {
|
633
|
+
super(message);
|
634
|
+
this.name = 'JsonRpcError';
|
635
|
+
}
|
636
|
+
}
|
637
|
+
const MethodNotFound = -32601;
|
638
|
+
const Custom = -32001;
|
639
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
640
|
+
const getType = prettyError => {
|
641
|
+
if (prettyError && prettyError.type) {
|
642
|
+
return prettyError.type;
|
643
|
+
}
|
644
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
645
|
+
return prettyError.constructor.name;
|
646
|
+
}
|
647
|
+
return undefined;
|
648
|
+
};
|
649
|
+
const getErrorProperty = (error, prettyError) => {
|
650
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
651
|
+
return {
|
652
|
+
code: MethodNotFound,
|
653
|
+
message: error.message,
|
654
|
+
data: error.stack
|
655
|
+
};
|
656
|
+
}
|
657
|
+
return {
|
658
|
+
code: Custom,
|
659
|
+
message: prettyError.message,
|
660
|
+
data: {
|
661
|
+
stack: prettyError.stack,
|
662
|
+
codeFrame: prettyError.codeFrame,
|
663
|
+
type: getType(prettyError),
|
664
|
+
code: prettyError.code,
|
665
|
+
name: prettyError.name
|
666
|
+
}
|
667
|
+
};
|
668
|
+
};
|
669
|
+
const create$1 = (message, error) => {
|
670
|
+
return {
|
671
|
+
jsonrpc: Two,
|
672
|
+
id: message.id,
|
673
|
+
error
|
674
|
+
};
|
675
|
+
};
|
676
|
+
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
677
|
+
const prettyError = preparePrettyError(error);
|
678
|
+
logError(error, prettyError);
|
679
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
680
|
+
return create$1(message, errorProperty);
|
681
|
+
};
|
682
|
+
const create = (message, result) => {
|
683
|
+
return {
|
684
|
+
jsonrpc: Two,
|
685
|
+
id: message.id,
|
686
|
+
result: result ?? null
|
687
|
+
};
|
688
|
+
};
|
689
|
+
const getSuccessResponse = (message, result) => {
|
690
|
+
const resultProperty = result ?? null;
|
691
|
+
return create(message, resultProperty);
|
692
|
+
};
|
693
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
694
|
+
try {
|
695
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
696
|
+
return getSuccessResponse(message, result);
|
697
|
+
} catch (error) {
|
698
|
+
return getErrorResponse(message, error, preparePrettyError, logError);
|
699
|
+
}
|
700
|
+
};
|
701
|
+
const defaultPreparePrettyError = error => {
|
702
|
+
return error;
|
703
|
+
};
|
704
|
+
const defaultLogError = () => {
|
705
|
+
// ignore
|
706
|
+
};
|
707
|
+
const defaultRequiresSocket = () => {
|
708
|
+
return false;
|
709
|
+
};
|
710
|
+
const defaultResolve = resolve;
|
711
|
+
const handleJsonRpcMessage = async (...args) => {
|
712
|
+
let message;
|
713
|
+
let ipc;
|
714
|
+
let execute;
|
715
|
+
let preparePrettyError;
|
716
|
+
let logError;
|
717
|
+
let resolve;
|
718
|
+
let requiresSocket;
|
719
|
+
if (args.length === 1) {
|
720
|
+
const arg = args[0];
|
721
|
+
message = arg.message;
|
722
|
+
ipc = arg.ipc;
|
723
|
+
execute = arg.execute;
|
724
|
+
preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
|
725
|
+
logError = arg.logError || defaultLogError;
|
726
|
+
requiresSocket = arg.requiresSocket || defaultRequiresSocket;
|
727
|
+
resolve = arg.resolve || defaultResolve;
|
728
|
+
} else {
|
729
|
+
ipc = args[0];
|
730
|
+
message = args[1];
|
731
|
+
execute = args[2];
|
732
|
+
resolve = args[3];
|
733
|
+
preparePrettyError = args[4];
|
734
|
+
logError = args[5];
|
735
|
+
requiresSocket = args[6];
|
736
|
+
}
|
737
|
+
if ('id' in message) {
|
738
|
+
if ('method' in message) {
|
739
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
740
|
+
try {
|
741
|
+
ipc.send(response);
|
742
|
+
} catch (error) {
|
743
|
+
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
744
|
+
ipc.send(errorResponse);
|
745
|
+
}
|
746
|
+
return;
|
747
|
+
}
|
748
|
+
resolve(message.id, message);
|
749
|
+
return;
|
750
|
+
}
|
751
|
+
if ('method' in message) {
|
752
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
753
|
+
return;
|
754
|
+
}
|
755
|
+
throw new JsonRpcError('unexpected message');
|
756
|
+
};
|
757
|
+
|
758
|
+
const requiresSocket = () => {
|
759
|
+
return false;
|
760
|
+
};
|
761
|
+
const preparePrettyError = error => {
|
762
|
+
return error;
|
763
|
+
};
|
764
|
+
const logError = error => {
|
765
|
+
// handled by renderer worker
|
766
|
+
};
|
767
|
+
const handleMessage = event => {
|
768
|
+
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
|
769
|
+
};
|
770
|
+
|
771
|
+
const handleIpc = ipc => {
|
772
|
+
ipc.addEventListener('message', handleMessage);
|
773
|
+
};
|
774
|
+
|
775
|
+
const MessagePort$1 = 1;
|
776
|
+
const ModuleWorker = 2;
|
777
|
+
const ReferencePort = 3;
|
778
|
+
const ModuleWorkerAndMessagePort = 8;
|
779
|
+
const Auto = () => {
|
780
|
+
// @ts-ignore
|
781
|
+
if (globalThis.acceptPort) {
|
782
|
+
return MessagePort$1;
|
783
|
+
}
|
784
|
+
// @ts-ignore
|
785
|
+
if (globalThis.acceptReferencePort) {
|
786
|
+
return ReferencePort;
|
787
|
+
}
|
788
|
+
return ModuleWorkerAndMessagePort;
|
789
|
+
};
|
790
|
+
|
791
|
+
const getData$1 = event => {
|
792
|
+
return event.data;
|
793
|
+
};
|
794
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
795
|
+
if (!value) {
|
796
|
+
return;
|
797
|
+
}
|
798
|
+
if (isTransferrable(value)) {
|
799
|
+
transferrables.push(value);
|
800
|
+
return;
|
801
|
+
}
|
802
|
+
if (Array.isArray(value)) {
|
803
|
+
for (const item of value) {
|
804
|
+
walkValue(item, transferrables, isTransferrable);
|
805
|
+
}
|
806
|
+
return;
|
807
|
+
}
|
808
|
+
if (typeof value === 'object') {
|
809
|
+
for (const property of Object.values(value)) {
|
810
|
+
walkValue(property, transferrables, isTransferrable);
|
811
|
+
}
|
812
|
+
return;
|
813
|
+
}
|
814
|
+
};
|
815
|
+
const isMessagePort = value => {
|
816
|
+
return value && value instanceof MessagePort;
|
817
|
+
};
|
818
|
+
const isMessagePortMain = value => {
|
819
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
820
|
+
};
|
821
|
+
const isOffscreenCanvas = value => {
|
822
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
823
|
+
};
|
824
|
+
const isInstanceOf = (value, constructorName) => {
|
825
|
+
return value?.constructor?.name === constructorName;
|
826
|
+
};
|
827
|
+
const isSocket = value => {
|
828
|
+
return isInstanceOf(value, 'Socket');
|
829
|
+
};
|
830
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
831
|
+
const isTransferrable = value => {
|
832
|
+
for (const fn of transferrables) {
|
833
|
+
if (fn(value)) {
|
834
|
+
return true;
|
835
|
+
}
|
836
|
+
}
|
837
|
+
return false;
|
838
|
+
};
|
839
|
+
const getTransferrables = value => {
|
840
|
+
const transferrables = [];
|
841
|
+
walkValue(value, transferrables, isTransferrable);
|
842
|
+
return transferrables;
|
843
|
+
};
|
844
|
+
const attachEvents = that => {
|
845
|
+
const handleMessage = (...args) => {
|
846
|
+
const data = that.getData(...args);
|
847
|
+
that.dispatchEvent(new MessageEvent('message', {
|
848
|
+
data
|
849
|
+
}));
|
850
|
+
};
|
851
|
+
that.onMessage(handleMessage);
|
852
|
+
const handleClose = event => {
|
853
|
+
that.dispatchEvent(new Event('close'));
|
854
|
+
};
|
855
|
+
that.onClose(handleClose);
|
856
|
+
};
|
857
|
+
class Ipc extends EventTarget {
|
858
|
+
constructor(rawIpc) {
|
859
|
+
super();
|
860
|
+
this._rawIpc = rawIpc;
|
861
|
+
attachEvents(this);
|
862
|
+
}
|
863
|
+
}
|
864
|
+
const readyMessage = 'ready';
|
865
|
+
const listen$4 = () => {
|
866
|
+
// @ts-ignore
|
867
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
868
|
+
throw new TypeError('module is not in web worker scope');
|
869
|
+
}
|
870
|
+
return globalThis;
|
871
|
+
};
|
872
|
+
const signal$3 = global => {
|
873
|
+
global.postMessage(readyMessage);
|
874
|
+
};
|
875
|
+
class IpcChildWithModuleWorker extends Ipc {
|
876
|
+
getData(event) {
|
877
|
+
return getData$1(event);
|
878
|
+
}
|
879
|
+
send(message) {
|
880
|
+
// @ts-ignore
|
881
|
+
this._rawIpc.postMessage(message);
|
882
|
+
}
|
883
|
+
sendAndTransfer(message) {
|
884
|
+
const transfer = getTransferrables(message);
|
885
|
+
// @ts-ignore
|
886
|
+
this._rawIpc.postMessage(message, transfer);
|
887
|
+
}
|
888
|
+
dispose() {
|
889
|
+
// ignore
|
890
|
+
}
|
891
|
+
onClose(callback) {
|
892
|
+
// ignore
|
893
|
+
}
|
894
|
+
onMessage(callback) {
|
895
|
+
this._rawIpc.addEventListener('message', callback);
|
896
|
+
}
|
897
|
+
}
|
898
|
+
const wrap$6 = global => {
|
899
|
+
return new IpcChildWithModuleWorker(global);
|
900
|
+
};
|
901
|
+
const IpcChildWithModuleWorker$1 = {
|
902
|
+
__proto__: null,
|
903
|
+
listen: listen$4,
|
904
|
+
signal: signal$3,
|
905
|
+
wrap: wrap$6
|
906
|
+
};
|
907
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
908
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
909
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
910
|
+
const NewLine$1 = '\n';
|
911
|
+
const joinLines = lines => {
|
912
|
+
return lines.join(NewLine$1);
|
913
|
+
};
|
914
|
+
const splitLines = lines => {
|
915
|
+
return lines.split(NewLine$1);
|
916
|
+
};
|
917
|
+
const isModuleNotFoundMessage = line => {
|
918
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
919
|
+
};
|
920
|
+
const getModuleNotFoundError = stderr => {
|
921
|
+
const lines = splitLines(stderr);
|
922
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
923
|
+
const message = lines[messageIndex];
|
924
|
+
return {
|
925
|
+
message,
|
926
|
+
code: ERR_MODULE_NOT_FOUND
|
927
|
+
};
|
928
|
+
};
|
929
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
930
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
931
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
932
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
933
|
+
const RE_AT = /^\s+at/;
|
934
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
935
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
936
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
937
|
+
};
|
938
|
+
const isMessageCodeBlockStartIndex = line => {
|
939
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
940
|
+
};
|
941
|
+
const isMessageCodeBlockEndIndex = line => {
|
942
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
943
|
+
};
|
944
|
+
const getMessageCodeBlock = stderr => {
|
945
|
+
const lines = splitLines(stderr);
|
946
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
947
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
948
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
949
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
950
|
+
return relevantMessage;
|
951
|
+
};
|
952
|
+
const getNativeModuleErrorMessage = stderr => {
|
953
|
+
const message = getMessageCodeBlock(stderr);
|
954
|
+
return {
|
955
|
+
message: `Incompatible native node module: ${message}`,
|
956
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE
|
957
|
+
};
|
958
|
+
};
|
959
|
+
const isModulesSyntaxError = stderr => {
|
960
|
+
if (!stderr) {
|
961
|
+
return false;
|
962
|
+
}
|
963
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
964
|
+
};
|
965
|
+
const getModuleSyntaxError = () => {
|
966
|
+
return {
|
967
|
+
message: `ES Modules are not supported in electron`,
|
968
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
969
|
+
};
|
970
|
+
};
|
971
|
+
const isModuleNotFoundError = stderr => {
|
972
|
+
if (!stderr) {
|
973
|
+
return false;
|
974
|
+
}
|
975
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
976
|
+
};
|
977
|
+
const isNormalStackLine = line => {
|
978
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
979
|
+
};
|
980
|
+
const getDetails = lines => {
|
981
|
+
const index = lines.findIndex(isNormalStackLine);
|
982
|
+
if (index === -1) {
|
983
|
+
return {
|
984
|
+
actualMessage: joinLines(lines),
|
985
|
+
rest: []
|
986
|
+
};
|
987
|
+
}
|
988
|
+
let lastIndex = index - 1;
|
989
|
+
while (++lastIndex < lines.length) {
|
990
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
991
|
+
break;
|
992
|
+
}
|
993
|
+
}
|
994
|
+
return {
|
995
|
+
actualMessage: lines[index - 1],
|
996
|
+
rest: lines.slice(index, lastIndex)
|
997
|
+
};
|
998
|
+
};
|
999
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
1000
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
1001
|
+
return getNativeModuleErrorMessage(stderr);
|
1002
|
+
}
|
1003
|
+
if (isModulesSyntaxError(stderr)) {
|
1004
|
+
return getModuleSyntaxError();
|
1005
|
+
}
|
1006
|
+
if (isModuleNotFoundError(stderr)) {
|
1007
|
+
return getModuleNotFoundError(stderr);
|
1008
|
+
}
|
1009
|
+
const lines = splitLines(stderr);
|
1010
|
+
const {
|
1011
|
+
actualMessage,
|
1012
|
+
rest
|
1013
|
+
} = getDetails(lines);
|
1014
|
+
return {
|
1015
|
+
message: `${actualMessage}`,
|
1016
|
+
code: '',
|
1017
|
+
stack: rest
|
1018
|
+
};
|
1019
|
+
};
|
1020
|
+
const normalizeLine = line => {
|
1021
|
+
if (line.startsWith('Error: ')) {
|
1022
|
+
return line.slice(`Error: `.length);
|
1023
|
+
}
|
1024
|
+
if (line.startsWith('VError: ')) {
|
1025
|
+
return line.slice(`VError: `.length);
|
1026
|
+
}
|
1027
|
+
return line;
|
1028
|
+
};
|
1029
|
+
const getCombinedMessage = (error, message) => {
|
1030
|
+
const stringifiedError = normalizeLine(`${error}`);
|
1031
|
+
if (message) {
|
1032
|
+
return `${message}: ${stringifiedError}`;
|
1033
|
+
}
|
1034
|
+
return stringifiedError;
|
1035
|
+
};
|
1036
|
+
const NewLine = '\n';
|
1037
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
1038
|
+
return string.indexOf(NewLine, startIndex);
|
1039
|
+
};
|
1040
|
+
const mergeStacks = (parent, child) => {
|
1041
|
+
if (!child) {
|
1042
|
+
return parent;
|
1043
|
+
}
|
1044
|
+
const parentNewLineIndex = getNewLineIndex(parent);
|
1045
|
+
const childNewLineIndex = getNewLineIndex(child);
|
1046
|
+
if (childNewLineIndex === -1) {
|
1047
|
+
return parent;
|
1048
|
+
}
|
1049
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
1050
|
+
const childRest = child.slice(childNewLineIndex);
|
1051
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
1052
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
1053
|
+
return parentFirstLine + childRest;
|
1054
|
+
}
|
1055
|
+
return child;
|
1056
|
+
};
|
1057
|
+
class VError extends Error {
|
1058
|
+
constructor(error, message) {
|
1059
|
+
const combinedMessage = getCombinedMessage(error, message);
|
1060
|
+
super(combinedMessage);
|
1061
|
+
this.name = 'VError';
|
1062
|
+
if (error instanceof Error) {
|
1063
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
1064
|
+
}
|
1065
|
+
if (error.codeFrame) {
|
1066
|
+
// @ts-ignore
|
1067
|
+
this.codeFrame = error.codeFrame;
|
1068
|
+
}
|
1069
|
+
if (error.code) {
|
1070
|
+
// @ts-ignore
|
1071
|
+
this.code = error.code;
|
1072
|
+
}
|
1073
|
+
}
|
1074
|
+
}
|
1075
|
+
class IpcError extends VError {
|
1076
|
+
// @ts-ignore
|
1077
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
1078
|
+
if (stdout || stderr) {
|
1079
|
+
// @ts-ignore
|
1080
|
+
const {
|
1081
|
+
message,
|
1082
|
+
code,
|
1083
|
+
stack
|
1084
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
1085
|
+
const cause = new Error(message);
|
1086
|
+
// @ts-ignore
|
1087
|
+
cause.code = code;
|
1088
|
+
cause.stack = stack;
|
1089
|
+
super(cause, betterMessage);
|
1090
|
+
} else {
|
1091
|
+
super(betterMessage);
|
1092
|
+
}
|
1093
|
+
// @ts-ignore
|
1094
|
+
this.name = 'IpcError';
|
1095
|
+
// @ts-ignore
|
1096
|
+
this.stdout = stdout;
|
1097
|
+
// @ts-ignore
|
1098
|
+
this.stderr = stderr;
|
1099
|
+
}
|
1100
|
+
}
|
1101
|
+
const withResolvers = () => {
|
1102
|
+
let _resolve;
|
1103
|
+
const promise = new Promise(resolve => {
|
1104
|
+
_resolve = resolve;
|
1105
|
+
});
|
1106
|
+
return {
|
1107
|
+
resolve: _resolve,
|
1108
|
+
promise
|
1109
|
+
};
|
1110
|
+
};
|
1111
|
+
const waitForFirstMessage = async port => {
|
1112
|
+
const {
|
1113
|
+
resolve,
|
1114
|
+
promise
|
1115
|
+
} = withResolvers();
|
1116
|
+
port.addEventListener('message', resolve, {
|
1117
|
+
once: true
|
1118
|
+
});
|
1119
|
+
const event = await promise;
|
1120
|
+
// @ts-ignore
|
1121
|
+
return event.data;
|
1122
|
+
};
|
1123
|
+
const listen$3 = async () => {
|
1124
|
+
const parentIpcRaw = listen$4();
|
1125
|
+
signal$3(parentIpcRaw);
|
1126
|
+
const parentIpc = wrap$6(parentIpcRaw);
|
1127
|
+
const firstMessage = await waitForFirstMessage(parentIpc);
|
1128
|
+
if (firstMessage.method !== 'initialize') {
|
1129
|
+
throw new IpcError('unexpected first message');
|
1130
|
+
}
|
1131
|
+
const type = firstMessage.params[0];
|
1132
|
+
if (type === 'message-port') {
|
1133
|
+
parentIpc.send({
|
1134
|
+
jsonrpc: '2.0',
|
1135
|
+
id: firstMessage.id,
|
1136
|
+
result: null
|
1137
|
+
});
|
1138
|
+
parentIpc.dispose();
|
1139
|
+
const port = firstMessage.params[1];
|
1140
|
+
return port;
|
1141
|
+
}
|
1142
|
+
return globalThis;
|
1143
|
+
};
|
1144
|
+
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
1145
|
+
constructor(port) {
|
1146
|
+
super(port);
|
1147
|
+
}
|
1148
|
+
getData(event) {
|
1149
|
+
return getData$1(event);
|
1150
|
+
}
|
1151
|
+
send(message) {
|
1152
|
+
this._rawIpc.postMessage(message);
|
1153
|
+
}
|
1154
|
+
sendAndTransfer(message) {
|
1155
|
+
const transfer = getTransferrables(message);
|
1156
|
+
this._rawIpc.postMessage(message, transfer);
|
1157
|
+
}
|
1158
|
+
dispose() {
|
1159
|
+
if (this._rawIpc.close) {
|
1160
|
+
this._rawIpc.close();
|
1161
|
+
}
|
1162
|
+
}
|
1163
|
+
onClose(callback) {
|
1164
|
+
// ignore
|
1165
|
+
}
|
1166
|
+
onMessage(callback) {
|
1167
|
+
this._rawIpc.addEventListener('message', callback);
|
1168
|
+
this._rawIpc.start();
|
1169
|
+
}
|
1170
|
+
}
|
1171
|
+
const wrap$5 = port => {
|
1172
|
+
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
1173
|
+
};
|
1174
|
+
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
1175
|
+
__proto__: null,
|
1176
|
+
listen: listen$3,
|
1177
|
+
wrap: wrap$5
|
1178
|
+
};
|
1179
|
+
|
1180
|
+
const getModule = method => {
|
1181
|
+
switch (method) {
|
1182
|
+
case ModuleWorker:
|
1183
|
+
return IpcChildWithModuleWorker$1;
|
1184
|
+
case ModuleWorkerAndMessagePort:
|
1185
|
+
return IpcChildWithModuleWorkerAndMessagePort$1;
|
1186
|
+
default:
|
1187
|
+
throw new Error('unexpected ipc type');
|
1188
|
+
}
|
1189
|
+
};
|
1190
|
+
|
1191
|
+
const listen$1 = async ({
|
1192
|
+
method
|
1193
|
+
}) => {
|
1194
|
+
const module = await getModule(method);
|
1195
|
+
const rawIpc = await module.listen();
|
1196
|
+
if (module.signal) {
|
1197
|
+
module.signal(rawIpc);
|
1198
|
+
}
|
1199
|
+
const ipc = module.wrap(rawIpc);
|
1200
|
+
return ipc;
|
1201
|
+
};
|
1202
|
+
|
1203
|
+
const listen = async () => {
|
1204
|
+
register(commandMap);
|
1205
|
+
const ipc = await listen$1({
|
1206
|
+
method: Auto()
|
1207
|
+
});
|
1208
|
+
handleIpc(ipc);
|
1209
|
+
};
|
1210
|
+
|
1211
|
+
const main = async () => {
|
1212
|
+
await listen();
|
1213
|
+
};
|
1214
|
+
|
1215
|
+
main();
|