@lvce-editor/about-view 7.1.0 → 7.3.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 +787 -516
- package/package.json +1 -1
package/dist/aboutWorkerMain.js
CHANGED
|
@@ -1,3 +1,277 @@
|
|
|
1
|
+
const toCommandId = key => {
|
|
2
|
+
const dotIndex = key.indexOf('.');
|
|
3
|
+
return key.slice(dotIndex + 1);
|
|
4
|
+
};
|
|
5
|
+
const create$a = () => {
|
|
6
|
+
const states = Object.create(null);
|
|
7
|
+
const commandMapRef = {};
|
|
8
|
+
return {
|
|
9
|
+
clear() {
|
|
10
|
+
for (const key of Object.keys(states)) {
|
|
11
|
+
delete states[key];
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
diff(uid, modules, numbers) {
|
|
15
|
+
const {
|
|
16
|
+
oldState,
|
|
17
|
+
scheduledState
|
|
18
|
+
} = states[uid];
|
|
19
|
+
const diffResult = [];
|
|
20
|
+
for (let i = 0; i < modules.length; i++) {
|
|
21
|
+
const fn = modules[i];
|
|
22
|
+
if (!fn(oldState, scheduledState)) {
|
|
23
|
+
diffResult.push(numbers[i]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return diffResult;
|
|
27
|
+
},
|
|
28
|
+
dispose(uid) {
|
|
29
|
+
delete states[uid];
|
|
30
|
+
},
|
|
31
|
+
get(uid) {
|
|
32
|
+
return states[uid];
|
|
33
|
+
},
|
|
34
|
+
getCommandIds() {
|
|
35
|
+
const keys = Object.keys(commandMapRef);
|
|
36
|
+
const ids = keys.map(toCommandId);
|
|
37
|
+
return ids;
|
|
38
|
+
},
|
|
39
|
+
getKeys() {
|
|
40
|
+
return Object.keys(states).map(Number);
|
|
41
|
+
},
|
|
42
|
+
registerCommands(commandMap) {
|
|
43
|
+
Object.assign(commandMapRef, commandMap);
|
|
44
|
+
},
|
|
45
|
+
set(uid, oldState, newState, scheduledState) {
|
|
46
|
+
states[uid] = {
|
|
47
|
+
newState,
|
|
48
|
+
oldState,
|
|
49
|
+
scheduledState: scheduledState ?? newState
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
wrapCommand(fn) {
|
|
53
|
+
const wrapped = async (uid, ...args) => {
|
|
54
|
+
const {
|
|
55
|
+
newState,
|
|
56
|
+
oldState
|
|
57
|
+
} = states[uid];
|
|
58
|
+
const newerState = await fn(newState, ...args);
|
|
59
|
+
if (oldState === newerState || newState === newerState) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const latestOld = states[uid];
|
|
63
|
+
const latestNew = {
|
|
64
|
+
...latestOld.newState,
|
|
65
|
+
...newerState
|
|
66
|
+
};
|
|
67
|
+
states[uid] = {
|
|
68
|
+
newState: latestNew,
|
|
69
|
+
oldState: latestOld.oldState,
|
|
70
|
+
scheduledState: latestNew
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
return wrapped;
|
|
74
|
+
},
|
|
75
|
+
wrapGetter(fn) {
|
|
76
|
+
const wrapped = (uid, ...args) => {
|
|
77
|
+
const {
|
|
78
|
+
newState
|
|
79
|
+
} = states[uid];
|
|
80
|
+
return fn(newState, ...args);
|
|
81
|
+
};
|
|
82
|
+
return wrapped;
|
|
83
|
+
},
|
|
84
|
+
wrapLoadContent(fn) {
|
|
85
|
+
const wrapped = async (uid, ...args) => {
|
|
86
|
+
const {
|
|
87
|
+
newState,
|
|
88
|
+
oldState
|
|
89
|
+
} = states[uid];
|
|
90
|
+
const result = await fn(newState, ...args);
|
|
91
|
+
const {
|
|
92
|
+
error,
|
|
93
|
+
state
|
|
94
|
+
} = result;
|
|
95
|
+
if (oldState === state || newState === state) {
|
|
96
|
+
return {
|
|
97
|
+
error
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const latestOld = states[uid];
|
|
101
|
+
const latestNew = {
|
|
102
|
+
...latestOld.newState,
|
|
103
|
+
...state
|
|
104
|
+
};
|
|
105
|
+
states[uid] = {
|
|
106
|
+
newState: latestNew,
|
|
107
|
+
oldState: latestOld.oldState,
|
|
108
|
+
scheduledState: latestNew
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
error
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
return wrapped;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const {
|
|
120
|
+
dispose: dispose$1,
|
|
121
|
+
get: get$2,
|
|
122
|
+
getCommandIds,
|
|
123
|
+
registerCommands,
|
|
124
|
+
set: set$3,
|
|
125
|
+
wrapCommand
|
|
126
|
+
} = create$a();
|
|
127
|
+
|
|
128
|
+
const create$9 = uid => {
|
|
129
|
+
const state = {
|
|
130
|
+
focusId: 0,
|
|
131
|
+
lines: [],
|
|
132
|
+
productName: '',
|
|
133
|
+
uid
|
|
134
|
+
};
|
|
135
|
+
set$3(uid, state, state);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const RenderFocus = 2;
|
|
139
|
+
const RenderFocusContext = 4;
|
|
140
|
+
const RenderAbout = 3;
|
|
141
|
+
|
|
142
|
+
const diffType$2 = RenderAbout;
|
|
143
|
+
const isEqual$2 = (oldState, newState) => {
|
|
144
|
+
return oldState.productName === newState.productName && JSON.stringify(oldState.lines) === JSON.stringify(newState.lines);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const diffType$1 = RenderFocus;
|
|
148
|
+
const isEqual$1 = (oldState, newState) => {
|
|
149
|
+
return oldState.focusId === newState.focusId;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const diffType = RenderFocusContext;
|
|
153
|
+
const isEqual = (oldState, newState) => {
|
|
154
|
+
return oldState.focusId === newState.focusId;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const modules = [isEqual$2, isEqual$1, isEqual];
|
|
158
|
+
const numbers = [diffType$2, diffType$1, diffType];
|
|
159
|
+
|
|
160
|
+
const diff = (oldState, newState) => {
|
|
161
|
+
const diffResult = [];
|
|
162
|
+
for (let i = 0; i < modules.length; i++) {
|
|
163
|
+
const fn = modules[i];
|
|
164
|
+
if (!fn(oldState, newState)) {
|
|
165
|
+
diffResult.push(numbers[i]);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return diffResult;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const diff2 = uid => {
|
|
172
|
+
const {
|
|
173
|
+
oldState,
|
|
174
|
+
scheduledState
|
|
175
|
+
} = get$2(uid);
|
|
176
|
+
const diffResult = diff(oldState, scheduledState);
|
|
177
|
+
return diffResult;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const dispose = uid => {
|
|
181
|
+
dispose$1(uid);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const None = 0;
|
|
185
|
+
const Ok$2 = 1;
|
|
186
|
+
const Copy$2 = 2;
|
|
187
|
+
|
|
188
|
+
const getNextFocus = focusId => {
|
|
189
|
+
switch (focusId) {
|
|
190
|
+
case Copy$2:
|
|
191
|
+
return Ok$2;
|
|
192
|
+
case Ok$2:
|
|
193
|
+
return Copy$2;
|
|
194
|
+
default:
|
|
195
|
+
return None;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const focusNext = state => {
|
|
200
|
+
const {
|
|
201
|
+
focusId
|
|
202
|
+
} = state;
|
|
203
|
+
return {
|
|
204
|
+
...state,
|
|
205
|
+
focusId: getNextFocus(focusId)
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const getPreviousFocus = focusId => {
|
|
210
|
+
switch (focusId) {
|
|
211
|
+
case Copy$2:
|
|
212
|
+
return Ok$2;
|
|
213
|
+
case Ok$2:
|
|
214
|
+
return Copy$2;
|
|
215
|
+
default:
|
|
216
|
+
return None;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const focusPrevious = state => {
|
|
221
|
+
const {
|
|
222
|
+
focusId
|
|
223
|
+
} = state;
|
|
224
|
+
return {
|
|
225
|
+
...state,
|
|
226
|
+
focusId: getPreviousFocus(focusId)
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const Button$2 = 1;
|
|
231
|
+
const Div = 4;
|
|
232
|
+
const Text = 12;
|
|
233
|
+
const Br = 55;
|
|
234
|
+
|
|
235
|
+
const TargetName = 'event.target.name';
|
|
236
|
+
|
|
237
|
+
const Tab = 2;
|
|
238
|
+
const Escape = 8;
|
|
239
|
+
|
|
240
|
+
const Shift = 1 << 10 >>> 0;
|
|
241
|
+
|
|
242
|
+
const FileSystemWorker = 209;
|
|
243
|
+
const RendererWorker = 1;
|
|
244
|
+
|
|
245
|
+
const mergeClassNames = (...classNames) => {
|
|
246
|
+
return classNames.filter(Boolean).join(' ');
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const text = data => {
|
|
250
|
+
return {
|
|
251
|
+
childCount: 0,
|
|
252
|
+
text: data,
|
|
253
|
+
type: Text
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const FocusAbout = 4;
|
|
258
|
+
|
|
259
|
+
const getKeyBindings = () => {
|
|
260
|
+
return [{
|
|
261
|
+
command: 'About.handleClickClose',
|
|
262
|
+
key: Escape,
|
|
263
|
+
when: FocusAbout
|
|
264
|
+
}, {
|
|
265
|
+
command: 'About.focusNext',
|
|
266
|
+
key: Tab,
|
|
267
|
+
when: FocusAbout
|
|
268
|
+
}, {
|
|
269
|
+
command: 'About.focusPrevious',
|
|
270
|
+
key: Tab | Shift,
|
|
271
|
+
when: FocusAbout
|
|
272
|
+
}];
|
|
273
|
+
};
|
|
274
|
+
|
|
1
275
|
const normalizeLine = line => {
|
|
2
276
|
if (line.startsWith('Error: ')) {
|
|
3
277
|
return line.slice('Error: '.length);
|
|
@@ -368,37 +642,152 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
368
642
|
listen: listen$6,
|
|
369
643
|
wrap: wrap$e
|
|
370
644
|
};
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
645
|
+
const addListener = (emitter, type, callback) => {
|
|
646
|
+
if ('addEventListener' in emitter) {
|
|
647
|
+
emitter.addEventListener(type, callback);
|
|
648
|
+
} else {
|
|
649
|
+
emitter.on(type, callback);
|
|
650
|
+
}
|
|
376
651
|
};
|
|
377
|
-
const
|
|
378
|
-
|
|
652
|
+
const removeListener = (emitter, type, callback) => {
|
|
653
|
+
if ('removeEventListener' in emitter) {
|
|
654
|
+
emitter.removeEventListener(type, callback);
|
|
655
|
+
} else {
|
|
656
|
+
emitter.off(type, callback);
|
|
657
|
+
}
|
|
379
658
|
};
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
659
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
660
|
+
const {
|
|
661
|
+
promise,
|
|
662
|
+
resolve
|
|
663
|
+
} = Promise.withResolvers();
|
|
664
|
+
const listenerMap = Object.create(null);
|
|
665
|
+
const cleanup = value => {
|
|
666
|
+
for (const event of Object.keys(eventMap)) {
|
|
667
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
668
|
+
}
|
|
669
|
+
resolve(value);
|
|
670
|
+
};
|
|
671
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
672
|
+
const listener = event => {
|
|
673
|
+
cleanup({
|
|
674
|
+
event,
|
|
675
|
+
type
|
|
676
|
+
});
|
|
677
|
+
};
|
|
678
|
+
addListener(eventEmitter, event, listener);
|
|
679
|
+
listenerMap[event] = listener;
|
|
384
680
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
681
|
+
return promise;
|
|
682
|
+
};
|
|
683
|
+
const Message$1 = 3;
|
|
684
|
+
const create$5$1 = async ({
|
|
685
|
+
isMessagePortOpen,
|
|
686
|
+
messagePort
|
|
687
|
+
}) => {
|
|
688
|
+
if (!isMessagePort(messagePort)) {
|
|
689
|
+
throw new IpcError('port must be of type MessagePort');
|
|
690
|
+
}
|
|
691
|
+
if (isMessagePortOpen) {
|
|
692
|
+
return messagePort;
|
|
693
|
+
}
|
|
694
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
695
|
+
message: Message$1
|
|
696
|
+
});
|
|
697
|
+
messagePort.start();
|
|
698
|
+
const {
|
|
699
|
+
event,
|
|
700
|
+
type
|
|
701
|
+
} = await eventPromise;
|
|
702
|
+
if (type !== Message$1) {
|
|
703
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
704
|
+
}
|
|
705
|
+
if (event.data !== readyMessage) {
|
|
706
|
+
throw new IpcError('unexpected first message');
|
|
707
|
+
}
|
|
708
|
+
return messagePort;
|
|
709
|
+
};
|
|
710
|
+
const signal$1 = messagePort => {
|
|
711
|
+
messagePort.start();
|
|
712
|
+
};
|
|
713
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
714
|
+
getData = getData$2;
|
|
715
|
+
send(message) {
|
|
716
|
+
this._rawIpc.postMessage(message);
|
|
717
|
+
}
|
|
718
|
+
sendAndTransfer(message) {
|
|
719
|
+
const transfer = getTransferrables(message);
|
|
720
|
+
this._rawIpc.postMessage(message, transfer);
|
|
721
|
+
}
|
|
722
|
+
dispose() {
|
|
723
|
+
this._rawIpc.close();
|
|
724
|
+
}
|
|
725
|
+
onMessage(callback) {
|
|
726
|
+
this._rawIpc.addEventListener('message', callback);
|
|
727
|
+
}
|
|
728
|
+
onClose(callback) {}
|
|
729
|
+
}
|
|
730
|
+
const wrap$5 = messagePort => {
|
|
731
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
732
|
+
};
|
|
733
|
+
const IpcParentWithMessagePort$1 = {
|
|
734
|
+
__proto__: null,
|
|
735
|
+
create: create$5$1,
|
|
736
|
+
signal: signal$1,
|
|
737
|
+
wrap: wrap$5
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
class CommandNotFoundError extends Error {
|
|
741
|
+
constructor(command) {
|
|
742
|
+
super(`Command not found ${command}`);
|
|
743
|
+
this.name = 'CommandNotFoundError';
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
const commands = Object.create(null);
|
|
747
|
+
const register = commandMap => {
|
|
748
|
+
Object.assign(commands, commandMap);
|
|
749
|
+
};
|
|
750
|
+
const getCommand = key => {
|
|
751
|
+
return commands[key];
|
|
752
|
+
};
|
|
753
|
+
const execute = (command, ...args) => {
|
|
754
|
+
const fn = getCommand(command);
|
|
755
|
+
if (!fn) {
|
|
756
|
+
throw new CommandNotFoundError(command);
|
|
757
|
+
}
|
|
758
|
+
return fn(...args);
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
const Two$1 = '2.0';
|
|
762
|
+
const callbacks = Object.create(null);
|
|
763
|
+
const get$1 = id => {
|
|
764
|
+
return callbacks[id];
|
|
765
|
+
};
|
|
766
|
+
const remove$1 = id => {
|
|
767
|
+
delete callbacks[id];
|
|
768
|
+
};
|
|
769
|
+
class JsonRpcError extends Error {
|
|
770
|
+
constructor(message) {
|
|
771
|
+
super(message);
|
|
772
|
+
this.name = 'JsonRpcError';
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
const NewLine$1 = '\n';
|
|
776
|
+
const DomException = 'DOMException';
|
|
777
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
778
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
779
|
+
const TypeError$1 = 'TypeError';
|
|
780
|
+
const getErrorConstructor = (message, type) => {
|
|
392
781
|
if (type) {
|
|
393
782
|
switch (type) {
|
|
394
783
|
case DomException:
|
|
395
784
|
return DOMException;
|
|
396
|
-
case TypeError$1:
|
|
397
|
-
return TypeError;
|
|
398
|
-
case SyntaxError$1:
|
|
399
|
-
return SyntaxError;
|
|
400
785
|
case ReferenceError$1:
|
|
401
786
|
return ReferenceError;
|
|
787
|
+
case SyntaxError$1:
|
|
788
|
+
return SyntaxError;
|
|
789
|
+
case TypeError$1:
|
|
790
|
+
return TypeError;
|
|
402
791
|
default:
|
|
403
792
|
return Error;
|
|
404
793
|
}
|
|
@@ -520,14 +909,14 @@ const warn = (...args) => {
|
|
|
520
909
|
console.warn(...args);
|
|
521
910
|
};
|
|
522
911
|
const resolve = (id, response) => {
|
|
523
|
-
const fn = get$
|
|
912
|
+
const fn = get$1(id);
|
|
524
913
|
if (!fn) {
|
|
525
914
|
console.log(response);
|
|
526
915
|
warn(`callback ${id} may already be disposed`);
|
|
527
916
|
return;
|
|
528
917
|
}
|
|
529
918
|
fn(response);
|
|
530
|
-
remove(id);
|
|
919
|
+
remove$1(id);
|
|
531
920
|
};
|
|
532
921
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
533
922
|
const getErrorType = prettyError => {
|
|
@@ -554,56 +943,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
554
943
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
555
944
|
return {
|
|
556
945
|
code: MethodNotFound,
|
|
557
|
-
|
|
558
|
-
|
|
946
|
+
data: error.stack,
|
|
947
|
+
message: error.message
|
|
559
948
|
};
|
|
560
949
|
}
|
|
561
950
|
return {
|
|
562
951
|
code: Custom,
|
|
563
|
-
message: prettyError.message,
|
|
564
952
|
data: {
|
|
565
|
-
stack: getStack(prettyError),
|
|
566
|
-
codeFrame: prettyError.codeFrame,
|
|
567
|
-
type: getErrorType(prettyError),
|
|
568
953
|
code: prettyError.code,
|
|
569
|
-
|
|
570
|
-
|
|
954
|
+
codeFrame: prettyError.codeFrame,
|
|
955
|
+
name: prettyError.name,
|
|
956
|
+
stack: getStack(prettyError),
|
|
957
|
+
type: getErrorType(prettyError)
|
|
958
|
+
},
|
|
959
|
+
message: prettyError.message
|
|
571
960
|
};
|
|
572
961
|
};
|
|
573
|
-
const create$1$
|
|
962
|
+
const create$1$1 = (id, error) => {
|
|
574
963
|
return {
|
|
575
|
-
|
|
964
|
+
error,
|
|
576
965
|
id,
|
|
577
|
-
|
|
966
|
+
jsonrpc: Two$1
|
|
578
967
|
};
|
|
579
968
|
};
|
|
580
969
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
581
970
|
const prettyError = preparePrettyError(error);
|
|
582
971
|
logError(error, prettyError);
|
|
583
972
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
584
|
-
return create$1$
|
|
973
|
+
return create$1$1(id, errorProperty);
|
|
585
974
|
};
|
|
586
|
-
const create$
|
|
975
|
+
const create$8 = (message, result) => {
|
|
587
976
|
return {
|
|
588
|
-
jsonrpc: Two$1,
|
|
589
977
|
id: message.id,
|
|
978
|
+
jsonrpc: Two$1,
|
|
590
979
|
result: result ?? null
|
|
591
980
|
};
|
|
592
981
|
};
|
|
593
982
|
const getSuccessResponse = (message, result) => {
|
|
594
983
|
const resultProperty = result ?? null;
|
|
595
|
-
return create$
|
|
984
|
+
return create$8(message, resultProperty);
|
|
596
985
|
};
|
|
597
986
|
const getErrorResponseSimple = (id, error) => {
|
|
598
987
|
return {
|
|
599
|
-
jsonrpc: Two$1,
|
|
600
|
-
id,
|
|
601
988
|
error: {
|
|
602
989
|
code: Custom,
|
|
990
|
+
data: error,
|
|
603
991
|
// @ts-ignore
|
|
604
|
-
message: error.message
|
|
605
|
-
|
|
606
|
-
|
|
992
|
+
message: error.message
|
|
993
|
+
},
|
|
994
|
+
id,
|
|
995
|
+
jsonrpc: Two$1
|
|
607
996
|
};
|
|
608
997
|
};
|
|
609
998
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -633,35 +1022,35 @@ const normalizeParams = args => {
|
|
|
633
1022
|
if (args.length === 1) {
|
|
634
1023
|
const options = args[0];
|
|
635
1024
|
return {
|
|
1025
|
+
execute: options.execute,
|
|
636
1026
|
ipc: options.ipc,
|
|
1027
|
+
logError: options.logError || defaultLogError,
|
|
637
1028
|
message: options.message,
|
|
638
|
-
execute: options.execute,
|
|
639
|
-
resolve: options.resolve || defaultResolve,
|
|
640
1029
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
641
|
-
|
|
642
|
-
|
|
1030
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
1031
|
+
resolve: options.resolve || defaultResolve
|
|
643
1032
|
};
|
|
644
1033
|
}
|
|
645
1034
|
return {
|
|
1035
|
+
execute: args[2],
|
|
646
1036
|
ipc: args[0],
|
|
1037
|
+
logError: args[5],
|
|
647
1038
|
message: args[1],
|
|
648
|
-
execute: args[2],
|
|
649
|
-
resolve: args[3],
|
|
650
1039
|
preparePrettyError: args[4],
|
|
651
|
-
|
|
652
|
-
|
|
1040
|
+
requiresSocket: args[6],
|
|
1041
|
+
resolve: args[3]
|
|
653
1042
|
};
|
|
654
1043
|
};
|
|
655
1044
|
const handleJsonRpcMessage = async (...args) => {
|
|
656
1045
|
const options = normalizeParams(args);
|
|
657
1046
|
const {
|
|
658
|
-
message,
|
|
659
|
-
ipc,
|
|
660
1047
|
execute,
|
|
661
|
-
|
|
662
|
-
preparePrettyError,
|
|
1048
|
+
ipc,
|
|
663
1049
|
logError,
|
|
664
|
-
|
|
1050
|
+
message,
|
|
1051
|
+
preparePrettyError,
|
|
1052
|
+
requiresSocket,
|
|
1053
|
+
resolve
|
|
665
1054
|
} = options;
|
|
666
1055
|
if ('id' in message) {
|
|
667
1056
|
if ('method' in message) {
|
|
@@ -684,36 +1073,17 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
684
1073
|
throw new JsonRpcError('unexpected message');
|
|
685
1074
|
};
|
|
686
1075
|
|
|
687
|
-
class CommandNotFoundError extends Error {
|
|
688
|
-
constructor(command) {
|
|
689
|
-
super(`Command not found ${command}`);
|
|
690
|
-
this.name = 'CommandNotFoundError';
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
const commands = Object.create(null);
|
|
694
|
-
const register = commandMap => {
|
|
695
|
-
Object.assign(commands, commandMap);
|
|
696
|
-
};
|
|
697
|
-
const getCommand = key => {
|
|
698
|
-
return commands[key];
|
|
699
|
-
};
|
|
700
|
-
const execute = (command, ...args) => {
|
|
701
|
-
const fn = getCommand(command);
|
|
702
|
-
if (!fn) {
|
|
703
|
-
throw new CommandNotFoundError(command);
|
|
704
|
-
}
|
|
705
|
-
return fn(...args);
|
|
706
|
-
};
|
|
707
|
-
|
|
708
1076
|
const Two = '2.0';
|
|
709
|
-
|
|
1077
|
+
|
|
1078
|
+
const create$7 = (method, params) => {
|
|
710
1079
|
return {
|
|
711
1080
|
jsonrpc: Two,
|
|
712
1081
|
method,
|
|
713
1082
|
params
|
|
714
1083
|
};
|
|
715
1084
|
};
|
|
716
|
-
|
|
1085
|
+
|
|
1086
|
+
const create$6 = (id, method, params) => {
|
|
717
1087
|
const message = {
|
|
718
1088
|
id,
|
|
719
1089
|
jsonrpc: Two,
|
|
@@ -722,15 +1092,14 @@ const create$n = (id, method, params) => {
|
|
|
722
1092
|
};
|
|
723
1093
|
return message;
|
|
724
1094
|
};
|
|
1095
|
+
|
|
725
1096
|
let id = 0;
|
|
726
|
-
const create$
|
|
1097
|
+
const create$5 = () => {
|
|
727
1098
|
return ++id;
|
|
728
1099
|
};
|
|
729
1100
|
|
|
730
|
-
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
731
|
-
|
|
732
1101
|
const registerPromise = map => {
|
|
733
|
-
const id = create$
|
|
1102
|
+
const id = create$5();
|
|
734
1103
|
const {
|
|
735
1104
|
promise,
|
|
736
1105
|
resolve
|
|
@@ -742,13 +1111,12 @@ const registerPromise = map => {
|
|
|
742
1111
|
};
|
|
743
1112
|
};
|
|
744
1113
|
|
|
745
|
-
// @ts-ignore
|
|
746
1114
|
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
747
1115
|
const {
|
|
748
1116
|
id,
|
|
749
1117
|
promise
|
|
750
1118
|
} = registerPromise(callbacks);
|
|
751
|
-
const message = create$
|
|
1119
|
+
const message = create$6(id, method, params);
|
|
752
1120
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
753
1121
|
ipc.sendAndTransfer(message);
|
|
754
1122
|
} else {
|
|
@@ -784,359 +1152,244 @@ const createRpc = ipc => {
|
|
|
784
1152
|
* @deprecated
|
|
785
1153
|
*/
|
|
786
1154
|
send(method, ...params) {
|
|
787
|
-
const message = create$
|
|
1155
|
+
const message = create$7(method, params);
|
|
788
1156
|
ipc.send(message);
|
|
789
1157
|
}
|
|
790
|
-
};
|
|
791
|
-
return rpc;
|
|
792
|
-
};
|
|
793
|
-
const requiresSocket = () => {
|
|
794
|
-
return false;
|
|
795
|
-
};
|
|
796
|
-
const preparePrettyError = error => {
|
|
797
|
-
return error;
|
|
798
|
-
};
|
|
799
|
-
const logError = () => {
|
|
800
|
-
// handled by renderer worker
|
|
801
|
-
};
|
|
802
|
-
const handleMessage = event => {
|
|
803
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
804
|
-
const actualExecute = event?.target?.execute || execute;
|
|
805
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
806
|
-
};
|
|
807
|
-
const handleIpc = ipc => {
|
|
808
|
-
if ('addEventListener' in ipc) {
|
|
809
|
-
ipc.addEventListener('message', handleMessage);
|
|
810
|
-
} else if ('on' in ipc) {
|
|
811
|
-
// deprecated
|
|
812
|
-
ipc.on('message', handleMessage);
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
const listen$1 = async (module, options) => {
|
|
816
|
-
const rawIpc = await module.listen(options);
|
|
817
|
-
if (module.signal) {
|
|
818
|
-
module.signal(rawIpc);
|
|
819
|
-
}
|
|
820
|
-
const ipc = module.wrap(rawIpc);
|
|
821
|
-
return ipc;
|
|
822
|
-
};
|
|
823
|
-
const create$1$1 = async ({
|
|
824
|
-
commandMap
|
|
825
|
-
}) => {
|
|
826
|
-
// TODO create a commandMap per rpc instance
|
|
827
|
-
register(commandMap);
|
|
828
|
-
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
829
|
-
handleIpc(ipc);
|
|
830
|
-
const rpc = createRpc(ipc);
|
|
831
|
-
return rpc;
|
|
832
|
-
};
|
|
833
|
-
const WebWorkerRpcClient = {
|
|
834
|
-
__proto__: null,
|
|
835
|
-
create: create$1$1
|
|
836
|
-
};
|
|
837
|
-
|
|
838
|
-
const TargetName = 'event.target.name';
|
|
839
|
-
|
|
840
|
-
const RendererWorker = 1;
|
|
841
|
-
|
|
842
|
-
const rpcs = Object.create(null);
|
|
843
|
-
const set$2 = (id, rpc) => {
|
|
844
|
-
rpcs[id] = rpc;
|
|
845
|
-
};
|
|
846
|
-
const get$1 = id => {
|
|
847
|
-
return rpcs[id];
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
const create$2 = rpcId => {
|
|
851
|
-
return {
|
|
852
|
-
async dispose() {
|
|
853
|
-
const rpc = get$1(rpcId);
|
|
854
|
-
await rpc.dispose();
|
|
855
|
-
},
|
|
856
|
-
// @ts-ignore
|
|
857
|
-
invoke(method, ...params) {
|
|
858
|
-
const rpc = get$1(rpcId);
|
|
859
|
-
// @ts-ignore
|
|
860
|
-
return rpc.invoke(method, ...params);
|
|
861
|
-
},
|
|
862
|
-
// @ts-ignore
|
|
863
|
-
invokeAndTransfer(method, ...params) {
|
|
864
|
-
const rpc = get$1(rpcId);
|
|
865
|
-
// @ts-ignore
|
|
866
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
867
|
-
},
|
|
868
|
-
set(rpc) {
|
|
869
|
-
set$2(rpcId, rpc);
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
};
|
|
873
|
-
|
|
874
|
-
const {
|
|
875
|
-
invoke,
|
|
876
|
-
set: set$1
|
|
877
|
-
} = create$2(RendererWorker);
|
|
878
|
-
const getElectronVersion$1 = async () => {
|
|
879
|
-
return invoke('Process.getElectronVersion');
|
|
880
|
-
};
|
|
881
|
-
const getNodeVersion$1 = async () => {
|
|
882
|
-
return invoke('Process.getNodeVersion');
|
|
883
|
-
};
|
|
884
|
-
const getChromeVersion$1 = async () => {
|
|
885
|
-
return invoke('Process.getChromeVersion');
|
|
886
|
-
};
|
|
887
|
-
const getV8Version$1 = async () => {
|
|
888
|
-
return invoke('Process.getV8Version');
|
|
889
|
-
};
|
|
890
|
-
const setFocus = key => {
|
|
891
|
-
return invoke('Focus.setFocus', key);
|
|
892
|
-
};
|
|
893
|
-
const closeWidget$1 = async widgetId => {
|
|
894
|
-
return invoke('Viewlet.closeWidget', widgetId);
|
|
895
|
-
};
|
|
896
|
-
const writeClipBoardText = async text => {
|
|
897
|
-
await invoke('ClipBoard.writeText', /* text */text);
|
|
898
|
-
};
|
|
899
|
-
const showMessageBox$1 = async options => {
|
|
900
|
-
return invoke('ElectronDialog.showMessageBox', options);
|
|
901
|
-
};
|
|
902
|
-
const openWidget = async name => {
|
|
903
|
-
await invoke('Viewlet.openWidget', name);
|
|
904
|
-
};
|
|
905
|
-
const getWindowId$1 = async () => {
|
|
906
|
-
return invoke('GetWindowId.getWindowId');
|
|
907
|
-
};
|
|
908
|
-
|
|
909
|
-
const toCommandId = key => {
|
|
910
|
-
const dotIndex = key.indexOf('.');
|
|
911
|
-
return key.slice(dotIndex + 1);
|
|
912
|
-
};
|
|
913
|
-
const create$1 = () => {
|
|
914
|
-
const states = Object.create(null);
|
|
915
|
-
const commandMapRef = {};
|
|
916
|
-
return {
|
|
917
|
-
get(uid) {
|
|
918
|
-
return states[uid];
|
|
919
|
-
},
|
|
920
|
-
set(uid, oldState, newState) {
|
|
921
|
-
states[uid] = {
|
|
922
|
-
oldState,
|
|
923
|
-
newState
|
|
924
|
-
};
|
|
925
|
-
},
|
|
926
|
-
dispose(uid) {
|
|
927
|
-
delete states[uid];
|
|
928
|
-
},
|
|
929
|
-
getKeys() {
|
|
930
|
-
return Object.keys(states).map(key => {
|
|
931
|
-
return Number.parseInt(key);
|
|
932
|
-
});
|
|
933
|
-
},
|
|
934
|
-
clear() {
|
|
935
|
-
for (const key of Object.keys(states)) {
|
|
936
|
-
delete states[key];
|
|
937
|
-
}
|
|
938
|
-
},
|
|
939
|
-
wrapCommand(fn) {
|
|
940
|
-
const wrapped = async (uid, ...args) => {
|
|
941
|
-
const {
|
|
942
|
-
oldState,
|
|
943
|
-
newState
|
|
944
|
-
} = states[uid];
|
|
945
|
-
const newerState = await fn(newState, ...args);
|
|
946
|
-
if (oldState === newerState || newState === newerState) {
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
const latest = states[uid];
|
|
950
|
-
states[uid] = {
|
|
951
|
-
oldState: latest.oldState,
|
|
952
|
-
newState: newerState
|
|
953
|
-
};
|
|
954
|
-
};
|
|
955
|
-
return wrapped;
|
|
956
|
-
},
|
|
957
|
-
wrapGetter(fn) {
|
|
958
|
-
const wrapped = (uid, ...args) => {
|
|
959
|
-
const {
|
|
960
|
-
newState
|
|
961
|
-
} = states[uid];
|
|
962
|
-
return fn(newState, ...args);
|
|
963
|
-
};
|
|
964
|
-
return wrapped;
|
|
965
|
-
},
|
|
966
|
-
diff(uid, modules, numbers) {
|
|
967
|
-
const {
|
|
968
|
-
oldState,
|
|
969
|
-
newState
|
|
970
|
-
} = states[uid];
|
|
971
|
-
const diffResult = [];
|
|
972
|
-
for (let i = 0; i < modules.length; i++) {
|
|
973
|
-
const fn = modules[i];
|
|
974
|
-
if (!fn(oldState, newState)) {
|
|
975
|
-
diffResult.push(numbers[i]);
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
return diffResult;
|
|
979
|
-
},
|
|
980
|
-
getCommandIds() {
|
|
981
|
-
const keys = Object.keys(commandMapRef);
|
|
982
|
-
const ids = keys.map(toCommandId);
|
|
983
|
-
return ids;
|
|
984
|
-
},
|
|
985
|
-
registerCommands(commandMap) {
|
|
986
|
-
Object.assign(commandMapRef, commandMap);
|
|
987
|
-
}
|
|
988
|
-
};
|
|
989
|
-
};
|
|
990
|
-
|
|
991
|
-
const {
|
|
992
|
-
dispose: dispose$1,
|
|
993
|
-
get,
|
|
994
|
-
getCommandIds,
|
|
995
|
-
registerCommands,
|
|
996
|
-
set,
|
|
997
|
-
wrapCommand
|
|
998
|
-
} = create$1();
|
|
999
|
-
|
|
1000
|
-
const create = uid => {
|
|
1001
|
-
const state = {
|
|
1002
|
-
focusId: 0,
|
|
1003
|
-
lines: [],
|
|
1004
|
-
productName: '',
|
|
1005
|
-
uid
|
|
1006
|
-
};
|
|
1007
|
-
set(uid, state, state);
|
|
1008
|
-
};
|
|
1009
|
-
|
|
1010
|
-
const RenderFocus = 2;
|
|
1011
|
-
const RenderFocusContext = 4;
|
|
1012
|
-
const RenderAbout = 3;
|
|
1013
|
-
|
|
1014
|
-
const diffType$2 = RenderAbout;
|
|
1015
|
-
const isEqual$2 = (oldState, newState) => {
|
|
1016
|
-
return oldState.productName === newState.productName && JSON.stringify(oldState.lines) === JSON.stringify(newState.lines);
|
|
1017
|
-
};
|
|
1018
|
-
|
|
1019
|
-
const diffType$1 = RenderFocus;
|
|
1020
|
-
const isEqual$1 = (oldState, newState) => {
|
|
1021
|
-
return oldState.focusId === newState.focusId;
|
|
1158
|
+
};
|
|
1159
|
+
return rpc;
|
|
1022
1160
|
};
|
|
1023
1161
|
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
return oldState.focusId === newState.focusId;
|
|
1162
|
+
const requiresSocket = () => {
|
|
1163
|
+
return false;
|
|
1027
1164
|
};
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
const numbers = [diffType$2, diffType$1, diffType];
|
|
1031
|
-
|
|
1032
|
-
const diff = (oldState, newState) => {
|
|
1033
|
-
const diffResult = [];
|
|
1034
|
-
for (let i = 0; i < modules.length; i++) {
|
|
1035
|
-
const fn = modules[i];
|
|
1036
|
-
if (!fn(oldState, newState)) {
|
|
1037
|
-
diffResult.push(numbers[i]);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
return diffResult;
|
|
1165
|
+
const preparePrettyError = error => {
|
|
1166
|
+
return error;
|
|
1041
1167
|
};
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
const {
|
|
1045
|
-
newState,
|
|
1046
|
-
oldState
|
|
1047
|
-
} = get(uid);
|
|
1048
|
-
const diffResult = diff(oldState, newState);
|
|
1049
|
-
return diffResult;
|
|
1168
|
+
const logError = () => {
|
|
1169
|
+
// handled by renderer worker
|
|
1050
1170
|
};
|
|
1051
|
-
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1171
|
+
const handleMessage = event => {
|
|
1172
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1173
|
+
const actualExecute = event?.target?.execute || execute;
|
|
1174
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1054
1175
|
};
|
|
1055
1176
|
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
case Copy$2:
|
|
1063
|
-
return Ok$2;
|
|
1064
|
-
case Ok$2:
|
|
1065
|
-
return Copy$2;
|
|
1066
|
-
default:
|
|
1067
|
-
return None;
|
|
1177
|
+
const handleIpc = ipc => {
|
|
1178
|
+
if ('addEventListener' in ipc) {
|
|
1179
|
+
ipc.addEventListener('message', handleMessage);
|
|
1180
|
+
} else if ('on' in ipc) {
|
|
1181
|
+
// deprecated
|
|
1182
|
+
ipc.on('message', handleMessage);
|
|
1068
1183
|
}
|
|
1069
1184
|
};
|
|
1070
1185
|
|
|
1071
|
-
const
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
};
|
|
1186
|
+
const listen$1 = async (module, options) => {
|
|
1187
|
+
const rawIpc = await module.listen(options);
|
|
1188
|
+
if (module.signal) {
|
|
1189
|
+
module.signal(rawIpc);
|
|
1190
|
+
}
|
|
1191
|
+
const ipc = module.wrap(rawIpc);
|
|
1192
|
+
return ipc;
|
|
1079
1193
|
};
|
|
1080
1194
|
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1195
|
+
const create$4 = async ({
|
|
1196
|
+
commandMap,
|
|
1197
|
+
isMessagePortOpen = true,
|
|
1198
|
+
messagePort
|
|
1199
|
+
}) => {
|
|
1200
|
+
// TODO create a commandMap per rpc instance
|
|
1201
|
+
register(commandMap);
|
|
1202
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
1203
|
+
isMessagePortOpen,
|
|
1204
|
+
messagePort
|
|
1205
|
+
});
|
|
1206
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
1207
|
+
handleIpc(ipc);
|
|
1208
|
+
const rpc = createRpc(ipc);
|
|
1209
|
+
messagePort.start();
|
|
1210
|
+
return rpc;
|
|
1090
1211
|
};
|
|
1091
1212
|
|
|
1092
|
-
const
|
|
1213
|
+
const create$3 = async ({
|
|
1214
|
+
commandMap,
|
|
1215
|
+
isMessagePortOpen,
|
|
1216
|
+
send
|
|
1217
|
+
}) => {
|
|
1093
1218
|
const {
|
|
1094
|
-
|
|
1095
|
-
|
|
1219
|
+
port1,
|
|
1220
|
+
port2
|
|
1221
|
+
} = new MessageChannel();
|
|
1222
|
+
await send(port1);
|
|
1223
|
+
return create$4({
|
|
1224
|
+
commandMap,
|
|
1225
|
+
isMessagePortOpen,
|
|
1226
|
+
messagePort: port2
|
|
1227
|
+
});
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
const createSharedLazyRpc = factory => {
|
|
1231
|
+
let rpcPromise;
|
|
1232
|
+
const getOrCreate = () => {
|
|
1233
|
+
if (!rpcPromise) {
|
|
1234
|
+
rpcPromise = factory();
|
|
1235
|
+
}
|
|
1236
|
+
return rpcPromise;
|
|
1237
|
+
};
|
|
1096
1238
|
return {
|
|
1097
|
-
|
|
1098
|
-
|
|
1239
|
+
async dispose() {
|
|
1240
|
+
const rpc = await getOrCreate();
|
|
1241
|
+
await rpc.dispose();
|
|
1242
|
+
},
|
|
1243
|
+
async invoke(method, ...params) {
|
|
1244
|
+
const rpc = await getOrCreate();
|
|
1245
|
+
return rpc.invoke(method, ...params);
|
|
1246
|
+
},
|
|
1247
|
+
async invokeAndTransfer(method, ...params) {
|
|
1248
|
+
const rpc = await getOrCreate();
|
|
1249
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1250
|
+
},
|
|
1251
|
+
async send(method, ...params) {
|
|
1252
|
+
const rpc = await getOrCreate();
|
|
1253
|
+
rpc.send(method, ...params);
|
|
1254
|
+
}
|
|
1099
1255
|
};
|
|
1100
1256
|
};
|
|
1101
1257
|
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1258
|
+
const create$2 = async ({
|
|
1259
|
+
commandMap,
|
|
1260
|
+
isMessagePortOpen,
|
|
1261
|
+
send
|
|
1262
|
+
}) => {
|
|
1263
|
+
return createSharedLazyRpc(() => {
|
|
1264
|
+
return create$3({
|
|
1265
|
+
commandMap,
|
|
1266
|
+
isMessagePortOpen,
|
|
1267
|
+
send
|
|
1268
|
+
});
|
|
1269
|
+
});
|
|
1270
|
+
};
|
|
1106
1271
|
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1272
|
+
const create$1 = async ({
|
|
1273
|
+
commandMap
|
|
1274
|
+
}) => {
|
|
1275
|
+
// TODO create a commandMap per rpc instance
|
|
1276
|
+
register(commandMap);
|
|
1277
|
+
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
1278
|
+
handleIpc(ipc);
|
|
1279
|
+
const rpc = createRpc(ipc);
|
|
1280
|
+
return rpc;
|
|
1281
|
+
};
|
|
1109
1282
|
|
|
1110
|
-
const
|
|
1283
|
+
const createMockRpc = ({
|
|
1284
|
+
commandMap
|
|
1285
|
+
}) => {
|
|
1286
|
+
const invocations = [];
|
|
1287
|
+
const invoke = (method, ...params) => {
|
|
1288
|
+
invocations.push([method, ...params]);
|
|
1289
|
+
const command = commandMap[method];
|
|
1290
|
+
if (!command) {
|
|
1291
|
+
throw new Error(`command ${method} not found`);
|
|
1292
|
+
}
|
|
1293
|
+
return command(...params);
|
|
1294
|
+
};
|
|
1295
|
+
const mockRpc = {
|
|
1296
|
+
invocations,
|
|
1297
|
+
invoke,
|
|
1298
|
+
invokeAndTransfer: invoke
|
|
1299
|
+
};
|
|
1300
|
+
return mockRpc;
|
|
1301
|
+
};
|
|
1111
1302
|
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1303
|
+
const rpcs = Object.create(null);
|
|
1304
|
+
const set$2 = (id, rpc) => {
|
|
1305
|
+
rpcs[id] = rpc;
|
|
1306
|
+
};
|
|
1307
|
+
const get = id => {
|
|
1308
|
+
return rpcs[id];
|
|
1309
|
+
};
|
|
1310
|
+
const remove = id => {
|
|
1311
|
+
delete rpcs[id];
|
|
1114
1312
|
};
|
|
1115
1313
|
|
|
1116
|
-
|
|
1314
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1315
|
+
const create = rpcId => {
|
|
1117
1316
|
return {
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1317
|
+
async dispose() {
|
|
1318
|
+
const rpc = get(rpcId);
|
|
1319
|
+
await rpc.dispose();
|
|
1320
|
+
},
|
|
1321
|
+
// @ts-ignore
|
|
1322
|
+
invoke(method, ...params) {
|
|
1323
|
+
const rpc = get(rpcId);
|
|
1324
|
+
// @ts-ignore
|
|
1325
|
+
return rpc.invoke(method, ...params);
|
|
1326
|
+
},
|
|
1327
|
+
// @ts-ignore
|
|
1328
|
+
invokeAndTransfer(method, ...params) {
|
|
1329
|
+
const rpc = get(rpcId);
|
|
1330
|
+
// @ts-ignore
|
|
1331
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1332
|
+
},
|
|
1333
|
+
registerMockRpc(commandMap) {
|
|
1334
|
+
const mockRpc = createMockRpc({
|
|
1335
|
+
commandMap
|
|
1336
|
+
});
|
|
1337
|
+
set$2(rpcId, mockRpc);
|
|
1338
|
+
// @ts-ignore
|
|
1339
|
+
mockRpc[Symbol.dispose] = () => {
|
|
1340
|
+
remove(rpcId);
|
|
1341
|
+
};
|
|
1342
|
+
// @ts-ignore
|
|
1343
|
+
return mockRpc;
|
|
1344
|
+
},
|
|
1345
|
+
set(rpc) {
|
|
1346
|
+
set$2(rpcId, rpc);
|
|
1347
|
+
}
|
|
1121
1348
|
};
|
|
1122
1349
|
};
|
|
1123
1350
|
|
|
1124
|
-
const
|
|
1351
|
+
const {
|
|
1352
|
+
set: set$1
|
|
1353
|
+
} = create(FileSystemWorker);
|
|
1125
1354
|
|
|
1126
|
-
const
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1355
|
+
const {
|
|
1356
|
+
invoke,
|
|
1357
|
+
invokeAndTransfer,
|
|
1358
|
+
set
|
|
1359
|
+
} = create(RendererWorker);
|
|
1360
|
+
const getElectronVersion$1 = async () => {
|
|
1361
|
+
return invoke('Process.getElectronVersion');
|
|
1362
|
+
};
|
|
1363
|
+
const getNodeVersion$1 = async () => {
|
|
1364
|
+
return invoke('Process.getNodeVersion');
|
|
1365
|
+
};
|
|
1366
|
+
const getChromeVersion$1 = async () => {
|
|
1367
|
+
return invoke('Process.getChromeVersion');
|
|
1368
|
+
};
|
|
1369
|
+
const getV8Version$1 = async () => {
|
|
1370
|
+
return invoke('Process.getV8Version');
|
|
1371
|
+
};
|
|
1372
|
+
const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
|
|
1373
|
+
const command = 'FileSystem.handleMessagePort';
|
|
1374
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
|
|
1375
|
+
};
|
|
1376
|
+
const setFocus = key => {
|
|
1377
|
+
return invoke('Focus.setFocus', key);
|
|
1378
|
+
};
|
|
1379
|
+
const closeWidget$1 = async widgetId => {
|
|
1380
|
+
return invoke('Viewlet.closeWidget', widgetId);
|
|
1381
|
+
};
|
|
1382
|
+
const writeClipBoardText = async text => {
|
|
1383
|
+
await invoke('ClipBoard.writeText', /* text */text);
|
|
1384
|
+
};
|
|
1385
|
+
const showMessageBox$1 = async options => {
|
|
1386
|
+
return invoke('ElectronDialog.showMessageBox', options);
|
|
1387
|
+
};
|
|
1388
|
+
const openWidget = async name => {
|
|
1389
|
+
await invoke('Viewlet.openWidget', name);
|
|
1390
|
+
};
|
|
1391
|
+
const getWindowId$1 = async () => {
|
|
1392
|
+
return invoke('GetWindowId.getWindowId');
|
|
1140
1393
|
};
|
|
1141
1394
|
|
|
1142
1395
|
const closeWidget = closeWidget$1;
|
|
@@ -1369,6 +1622,22 @@ const inSomeYears = years => {
|
|
|
1369
1622
|
});
|
|
1370
1623
|
};
|
|
1371
1624
|
|
|
1625
|
+
const formatRelativeDateRange = (seconds, range) => {
|
|
1626
|
+
const value = Math.floor(seconds / range.divisor);
|
|
1627
|
+
if (value === 1) {
|
|
1628
|
+
return range.one();
|
|
1629
|
+
}
|
|
1630
|
+
return range.some(value);
|
|
1631
|
+
};
|
|
1632
|
+
const formatRelativeDate = (seconds, ranges) => {
|
|
1633
|
+
for (const range of ranges) {
|
|
1634
|
+
if (seconds < range.limit) {
|
|
1635
|
+
return formatRelativeDateRange(seconds, range);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
throw new Error('unreachable');
|
|
1639
|
+
};
|
|
1640
|
+
|
|
1372
1641
|
const minute = 60;
|
|
1373
1642
|
const hour = minute * 60;
|
|
1374
1643
|
const day = hour * 24;
|
|
@@ -1377,103 +1646,85 @@ const month = day * 30;
|
|
|
1377
1646
|
const year = day * 365;
|
|
1378
1647
|
|
|
1379
1648
|
// based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
|
|
1649
|
+
const ranges$1 = [{
|
|
1650
|
+
divisor: 1,
|
|
1651
|
+
limit: minute,
|
|
1652
|
+
one: inOneSecond,
|
|
1653
|
+
some: inSomeSeconds
|
|
1654
|
+
}, {
|
|
1655
|
+
divisor: minute,
|
|
1656
|
+
limit: hour,
|
|
1657
|
+
one: inOneMinute,
|
|
1658
|
+
some: inSomeMinutes
|
|
1659
|
+
}, {
|
|
1660
|
+
divisor: hour,
|
|
1661
|
+
limit: day,
|
|
1662
|
+
one: inOneHour,
|
|
1663
|
+
some: inSomeHours
|
|
1664
|
+
}, {
|
|
1665
|
+
divisor: day,
|
|
1666
|
+
limit: week,
|
|
1667
|
+
one: inOneDay,
|
|
1668
|
+
some: inSomeDays
|
|
1669
|
+
}, {
|
|
1670
|
+
divisor: week,
|
|
1671
|
+
limit: month,
|
|
1672
|
+
one: inOneWeek,
|
|
1673
|
+
some: inSomeWeeks
|
|
1674
|
+
}, {
|
|
1675
|
+
divisor: month,
|
|
1676
|
+
limit: year,
|
|
1677
|
+
one: inOneMonth,
|
|
1678
|
+
some: inSomeMonths
|
|
1679
|
+
}, {
|
|
1680
|
+
divisor: year,
|
|
1681
|
+
limit: Infinity,
|
|
1682
|
+
one: inOneYear,
|
|
1683
|
+
some: inSomeYears
|
|
1684
|
+
}];
|
|
1380
1685
|
const formatDateFuture = seconds => {
|
|
1381
|
-
|
|
1382
|
-
if (seconds === 1) {
|
|
1383
|
-
return inOneSecond();
|
|
1384
|
-
}
|
|
1385
|
-
return inSomeSeconds(seconds);
|
|
1386
|
-
}
|
|
1387
|
-
if (seconds < hour) {
|
|
1388
|
-
const minutes = Math.floor(seconds / minute);
|
|
1389
|
-
if (minutes === 1) {
|
|
1390
|
-
return inOneMinute();
|
|
1391
|
-
}
|
|
1392
|
-
return inSomeMinutes(minutes);
|
|
1393
|
-
}
|
|
1394
|
-
if (seconds < day) {
|
|
1395
|
-
const days = Math.floor(seconds / hour);
|
|
1396
|
-
if (days === 1) {
|
|
1397
|
-
return inOneHour();
|
|
1398
|
-
}
|
|
1399
|
-
return inSomeHours(days);
|
|
1400
|
-
}
|
|
1401
|
-
if (seconds < week) {
|
|
1402
|
-
const days = Math.floor(seconds / day);
|
|
1403
|
-
if (days === 1) {
|
|
1404
|
-
return inOneDay();
|
|
1405
|
-
}
|
|
1406
|
-
return inSomeDays(days);
|
|
1407
|
-
}
|
|
1408
|
-
if (seconds < month) {
|
|
1409
|
-
const weeks = Math.floor(seconds / week);
|
|
1410
|
-
if (weeks === 1) {
|
|
1411
|
-
return inOneWeek();
|
|
1412
|
-
}
|
|
1413
|
-
return inSomeWeeks(weeks);
|
|
1414
|
-
}
|
|
1415
|
-
if (seconds < year) {
|
|
1416
|
-
const months = Math.floor(seconds / month);
|
|
1417
|
-
if (months === 1) {
|
|
1418
|
-
return inOneMonth();
|
|
1419
|
-
}
|
|
1420
|
-
return inSomeMonths(months);
|
|
1421
|
-
}
|
|
1422
|
-
const years = Math.floor(seconds / year);
|
|
1423
|
-
if (years === 1) {
|
|
1424
|
-
return inOneYear();
|
|
1425
|
-
}
|
|
1426
|
-
return inSomeYears(years);
|
|
1686
|
+
return formatRelativeDate(seconds, ranges$1);
|
|
1427
1687
|
};
|
|
1428
1688
|
|
|
1429
1689
|
// based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
|
|
1690
|
+
const ranges = [{
|
|
1691
|
+
divisor: 1,
|
|
1692
|
+
limit: minute,
|
|
1693
|
+
one: oneSecondAgo,
|
|
1694
|
+
some: someSecondsAgo
|
|
1695
|
+
}, {
|
|
1696
|
+
divisor: minute,
|
|
1697
|
+
limit: hour,
|
|
1698
|
+
one: oneMinuteAgo,
|
|
1699
|
+
some: someMinutesAgo
|
|
1700
|
+
}, {
|
|
1701
|
+
divisor: hour,
|
|
1702
|
+
limit: day,
|
|
1703
|
+
one: oneHourAgo,
|
|
1704
|
+
some: someHoursAgo
|
|
1705
|
+
}, {
|
|
1706
|
+
divisor: day,
|
|
1707
|
+
limit: week,
|
|
1708
|
+
one: oneDayAgo,
|
|
1709
|
+
some: someDaysAgo
|
|
1710
|
+
}, {
|
|
1711
|
+
divisor: week,
|
|
1712
|
+
limit: month,
|
|
1713
|
+
one: oneWeekAgo,
|
|
1714
|
+
some: someWeeksAgo
|
|
1715
|
+
}, {
|
|
1716
|
+
divisor: month,
|
|
1717
|
+
limit: year,
|
|
1718
|
+
one: oneMonthAgo,
|
|
1719
|
+
some: someMonthsAgo
|
|
1720
|
+
}, {
|
|
1721
|
+
divisor: year,
|
|
1722
|
+
limit: Infinity,
|
|
1723
|
+
one: oneYearAgo,
|
|
1724
|
+
some: someYearsAgo
|
|
1725
|
+
}];
|
|
1430
1726
|
const formatDatePast = seconds => {
|
|
1431
|
-
|
|
1432
|
-
if (seconds === 1) {
|
|
1433
|
-
return oneSecondAgo();
|
|
1434
|
-
}
|
|
1435
|
-
return someSecondsAgo(seconds);
|
|
1436
|
-
}
|
|
1437
|
-
if (seconds < hour) {
|
|
1438
|
-
const minutes = Math.floor(seconds / minute);
|
|
1439
|
-
if (minutes === 1) {
|
|
1440
|
-
return oneMinuteAgo();
|
|
1441
|
-
}
|
|
1442
|
-
return someMinutesAgo(minutes);
|
|
1443
|
-
}
|
|
1444
|
-
if (seconds < day) {
|
|
1445
|
-
const days = Math.floor(seconds / hour);
|
|
1446
|
-
if (days === 1) {
|
|
1447
|
-
return oneHourAgo();
|
|
1448
|
-
}
|
|
1449
|
-
return someHoursAgo(days);
|
|
1450
|
-
}
|
|
1451
|
-
if (seconds < week) {
|
|
1452
|
-
const days = Math.floor(seconds / day);
|
|
1453
|
-
if (days === 1) {
|
|
1454
|
-
return oneDayAgo();
|
|
1455
|
-
}
|
|
1456
|
-
return someDaysAgo(days);
|
|
1457
|
-
}
|
|
1458
|
-
if (seconds < month) {
|
|
1459
|
-
const weeks = Math.floor(seconds / week);
|
|
1460
|
-
if (weeks === 1) {
|
|
1461
|
-
return oneWeekAgo();
|
|
1462
|
-
}
|
|
1463
|
-
return someWeeksAgo(weeks);
|
|
1464
|
-
}
|
|
1465
|
-
if (seconds < year) {
|
|
1466
|
-
const months = Math.floor(seconds / month);
|
|
1467
|
-
if (months === 1) {
|
|
1468
|
-
return oneMonthAgo();
|
|
1469
|
-
}
|
|
1470
|
-
return someMonthsAgo(months);
|
|
1471
|
-
}
|
|
1472
|
-
const years = Math.floor(seconds / year);
|
|
1473
|
-
if (years === 1) {
|
|
1474
|
-
return oneYearAgo();
|
|
1475
|
-
}
|
|
1476
|
-
return someYearsAgo(years);
|
|
1727
|
+
return formatRelativeDate(seconds, ranges);
|
|
1477
1728
|
};
|
|
1478
1729
|
|
|
1479
1730
|
// based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
|
|
@@ -1500,7 +1751,7 @@ const formatAboutDate = (isoDate, now) => {
|
|
|
1500
1751
|
|
|
1501
1752
|
const getBrowser = () => {
|
|
1502
1753
|
// @ts-ignore
|
|
1503
|
-
return
|
|
1754
|
+
return navigator.userAgent;
|
|
1504
1755
|
};
|
|
1505
1756
|
|
|
1506
1757
|
const version = '0.0.0-dev';
|
|
@@ -1516,10 +1767,10 @@ const getDetailStringWeb = () => {
|
|
|
1516
1767
|
const getElectronVersion = getElectronVersion$1;
|
|
1517
1768
|
const getNodeVersion = getNodeVersion$1;
|
|
1518
1769
|
const getChromeVersion = getChromeVersion$1;
|
|
1519
|
-
const getVersion = () => {
|
|
1770
|
+
const getVersion = async () => {
|
|
1520
1771
|
return version;
|
|
1521
1772
|
};
|
|
1522
|
-
const getCommit = () => {
|
|
1773
|
+
const getCommit = async () => {
|
|
1523
1774
|
return commit;
|
|
1524
1775
|
};
|
|
1525
1776
|
const getV8Version = getV8Version$1;
|
|
@@ -1527,14 +1778,18 @@ const getDate = () => {
|
|
|
1527
1778
|
return commitDate;
|
|
1528
1779
|
};
|
|
1529
1780
|
const productNameLong$1 = 'Lvce Editor - OSS';
|
|
1781
|
+
const getProductNameLong$1 = async () => {
|
|
1782
|
+
return productNameLong$1;
|
|
1783
|
+
};
|
|
1530
1784
|
|
|
1531
|
-
const loadContent2 = state => {
|
|
1785
|
+
const loadContent2 = async state => {
|
|
1532
1786
|
const lines = getDetailStringWeb();
|
|
1787
|
+
const productName = await getProductNameLong$1();
|
|
1533
1788
|
return {
|
|
1534
1789
|
...state,
|
|
1535
1790
|
focusId: Ok$2,
|
|
1536
1791
|
lines,
|
|
1537
|
-
productName
|
|
1792
|
+
productName
|
|
1538
1793
|
};
|
|
1539
1794
|
};
|
|
1540
1795
|
|
|
@@ -1734,7 +1989,7 @@ const getFocusSelector = focusId => {
|
|
|
1734
1989
|
|
|
1735
1990
|
const renderFocus = (oldState, newState) => {
|
|
1736
1991
|
const name = getFocusSelector(newState.focusId);
|
|
1737
|
-
return ['Viewlet.
|
|
1992
|
+
return ['Viewlet.focusSelector', `[name="${name}"]`];
|
|
1738
1993
|
};
|
|
1739
1994
|
|
|
1740
1995
|
const renderFocusContext = (oldState, newState) => {
|
|
@@ -1765,11 +2020,11 @@ const applyRender = (oldState, newState, diffResult) => {
|
|
|
1765
2020
|
|
|
1766
2021
|
const doRender = (uid, diffResult) => {
|
|
1767
2022
|
const {
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
} = get(uid);
|
|
1771
|
-
set(uid,
|
|
1772
|
-
const commands = applyRender(oldState,
|
|
2023
|
+
oldState,
|
|
2024
|
+
scheduledState
|
|
2025
|
+
} = get$2(uid);
|
|
2026
|
+
set$3(uid, scheduledState, scheduledState);
|
|
2027
|
+
const commands = applyRender(oldState, scheduledState, diffResult);
|
|
1773
2028
|
return commands;
|
|
1774
2029
|
};
|
|
1775
2030
|
|
|
@@ -1859,7 +2114,7 @@ const showAbout = async platform => {
|
|
|
1859
2114
|
};
|
|
1860
2115
|
|
|
1861
2116
|
const commandMap = {
|
|
1862
|
-
'About.create': create,
|
|
2117
|
+
'About.create': create$9,
|
|
1863
2118
|
'About.diff2': diff2,
|
|
1864
2119
|
'About.dispose': dispose,
|
|
1865
2120
|
'About.focusNext': wrapCommand(focusNext),
|
|
@@ -1878,14 +2133,30 @@ const commandMap = {
|
|
|
1878
2133
|
'About.showAboutElectron': showAboutElectron
|
|
1879
2134
|
};
|
|
1880
2135
|
|
|
1881
|
-
const
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
2136
|
+
const send = async port => {
|
|
2137
|
+
await sendMessagePortToFileSystemWorker(port, 0);
|
|
2138
|
+
};
|
|
2139
|
+
const initializeFileSystemWorker = async () => {
|
|
2140
|
+
const rpc = await create$2({
|
|
2141
|
+
commandMap: {},
|
|
2142
|
+
send
|
|
1885
2143
|
});
|
|
1886
2144
|
set$1(rpc);
|
|
1887
2145
|
};
|
|
1888
2146
|
|
|
2147
|
+
const initializeRendererWorker = async () => {
|
|
2148
|
+
const rpc = await create$1({
|
|
2149
|
+
commandMap: commandMap
|
|
2150
|
+
});
|
|
2151
|
+
set(rpc);
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2154
|
+
const listen = async () => {
|
|
2155
|
+
registerCommands(commandMap);
|
|
2156
|
+
await initializeRendererWorker();
|
|
2157
|
+
await initializeFileSystemWorker();
|
|
2158
|
+
};
|
|
2159
|
+
|
|
1889
2160
|
const main = async () => {
|
|
1890
2161
|
await listen();
|
|
1891
2162
|
};
|