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