@lvce-editor/main-area-worker 7.2.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.
@@ -105,6 +105,7 @@ const Tab = 13;
105
105
  const Separator = 1;
106
106
  const None = 0;
107
107
 
108
+ const ClipBoardWorker = 3400;
108
109
  const ExtensionHostWorker = 44;
109
110
  const IconThemeWorker = 7009;
110
111
  const RendererWorker = 1;
@@ -273,6 +274,55 @@ const getTransferrables = value => {
273
274
  walkValue(value, transferrables, isTransferrable);
274
275
  return transferrables;
275
276
  };
277
+ const removeValues = (value, toRemove) => {
278
+ if (!value) {
279
+ return value;
280
+ }
281
+ if (Array.isArray(value)) {
282
+ const newItems = [];
283
+ for (const item of value) {
284
+ if (!toRemove.includes(item)) {
285
+ newItems.push(removeValues(item, toRemove));
286
+ }
287
+ }
288
+ return newItems;
289
+ }
290
+ if (typeof value === 'object') {
291
+ const newObject = Object.create(null);
292
+ for (const [key, property] of Object.entries(value)) {
293
+ if (!toRemove.includes(property)) {
294
+ newObject[key] = removeValues(property, toRemove);
295
+ }
296
+ }
297
+ return newObject;
298
+ }
299
+ return value;
300
+ };
301
+
302
+ // workaround for electron not supporting transferrable objects
303
+ // as parameters. If the transferrable object is a parameter, in electron
304
+ // only an empty objected is received in the main process
305
+ const fixElectronParameters = value => {
306
+ const transfer = getTransferrables(value);
307
+ const newValue = removeValues(value, transfer);
308
+ return {
309
+ newValue,
310
+ transfer
311
+ };
312
+ };
313
+ const getActualDataElectron = event => {
314
+ const {
315
+ data,
316
+ ports
317
+ } = event;
318
+ if (ports.length === 0) {
319
+ return data;
320
+ }
321
+ return {
322
+ ...data,
323
+ params: [...ports, ...data.params]
324
+ };
325
+ };
276
326
  const attachEvents = that => {
277
327
  const handleMessage = (...args) => {
278
328
  const data = that.getData(...args);
@@ -432,6 +482,48 @@ class IpcError extends VError {
432
482
  this.stderr = stderr;
433
483
  }
434
484
  }
485
+ const listen$b = ({
486
+ messagePort
487
+ }) => {
488
+ if (!isMessagePortMain(messagePort)) {
489
+ throw new IpcError('port must be of type MessagePortMain');
490
+ }
491
+ return messagePort;
492
+ };
493
+ const signal$c = messagePort => {
494
+ messagePort.start();
495
+ };
496
+ class IpcChildWithElectronMessagePort extends Ipc {
497
+ getData = getActualDataElectron;
498
+ send(message) {
499
+ this._rawIpc.postMessage(message);
500
+ }
501
+ sendAndTransfer(message) {
502
+ const {
503
+ newValue,
504
+ transfer
505
+ } = fixElectronParameters(message);
506
+ this._rawIpc.postMessage(newValue, transfer);
507
+ }
508
+ dispose() {
509
+ this._rawIpc.close();
510
+ }
511
+ onMessage(callback) {
512
+ this._rawIpc.on('message', callback);
513
+ }
514
+ onClose(callback) {
515
+ this._rawIpc.on('close', callback);
516
+ }
517
+ }
518
+ const wrap$j = messagePort => {
519
+ return new IpcChildWithElectronMessagePort(messagePort);
520
+ };
521
+ const IpcChildWithElectronMessagePort$1 = {
522
+ __proto__: null,
523
+ listen: listen$b,
524
+ signal: signal$c,
525
+ wrap: wrap$j
526
+ };
435
527
  const readyMessage = 'ready';
436
528
  const getData$2 = event => {
437
529
  return event.data;
@@ -1083,6 +1175,23 @@ const listen$1 = async (module, options) => {
1083
1175
  const ipc = module.wrap(rawIpc);
1084
1176
  return ipc;
1085
1177
  };
1178
+ const create$q = async ({
1179
+ commandMap,
1180
+ messagePort,
1181
+ requiresSocket
1182
+ }) => {
1183
+ // TODO create a commandMap per rpc instance
1184
+ register(commandMap);
1185
+ const ipc = await listen$1(IpcChildWithElectronMessagePort$1, {
1186
+ messagePort
1187
+ });
1188
+ if (requiresSocket) {
1189
+ ipc.requiresSocket = requiresSocket;
1190
+ }
1191
+ handleIpc(ipc);
1192
+ const rpc = createRpc(ipc);
1193
+ return rpc;
1194
+ };
1086
1195
 
1087
1196
  /* eslint-disable @typescript-eslint/no-misused-promises */
1088
1197
 
@@ -1113,6 +1222,39 @@ const createSharedLazyRpc = factory => {
1113
1222
  }
1114
1223
  };
1115
1224
  };
1225
+ const create$l = async ({
1226
+ commandMap,
1227
+ getPortTuple,
1228
+ send
1229
+ }) => {
1230
+ const {
1231
+ port1,
1232
+ port2
1233
+ } = await getPortTuple();
1234
+ await send(port1);
1235
+ const rpc = create$q({
1236
+ commandMap,
1237
+ messagePort: port2
1238
+ });
1239
+ return rpc;
1240
+ };
1241
+ const create$k = async ({
1242
+ commandMap,
1243
+ getPortTuple,
1244
+ send
1245
+ }) => {
1246
+ return createSharedLazyRpc(() => {
1247
+ return create$l({
1248
+ commandMap,
1249
+ getPortTuple,
1250
+ send
1251
+ });
1252
+ });
1253
+ };
1254
+ const LazyTransferElectronMessagePortRpc = {
1255
+ __proto__: null,
1256
+ create: create$k
1257
+ };
1116
1258
  const create$j = async ({
1117
1259
  commandMap,
1118
1260
  isMessagePortOpen,
@@ -1202,7 +1344,7 @@ const createMockRpc = ({
1202
1344
  };
1203
1345
 
1204
1346
  const rpcs = Object.create(null);
1205
- const set$4 = (id, rpc) => {
1347
+ const set$5 = (id, rpc) => {
1206
1348
  rpcs[id] = rpc;
1207
1349
  };
1208
1350
  const get$1 = id => {
@@ -1235,7 +1377,7 @@ const create$2 = rpcId => {
1235
1377
  const mockRpc = createMockRpc({
1236
1378
  commandMap
1237
1379
  });
1238
- set$4(rpcId, mockRpc);
1380
+ set$5(rpcId, mockRpc);
1239
1381
  // @ts-ignore
1240
1382
  mockRpc[Symbol.dispose] = () => {
1241
1383
  remove(rpcId);
@@ -1244,11 +1386,15 @@ const create$2 = rpcId => {
1244
1386
  return mockRpc;
1245
1387
  },
1246
1388
  set(rpc) {
1247
- set$4(rpcId, rpc);
1389
+ set$5(rpcId, rpc);
1248
1390
  }
1249
1391
  };
1250
1392
  };
1251
1393
 
1394
+ const {
1395
+ set: set$4
1396
+ } = create$2(ClipBoardWorker);
1397
+
1252
1398
  const {
1253
1399
  set: set$3
1254
1400
  } = create$2(ExtensionHostWorker);
@@ -4139,6 +4285,19 @@ const commandMap = {
4139
4285
  'MainArea.terminate': terminate
4140
4286
  };
4141
4287
 
4288
+ const sendMessagePortToClipBoardWorker = async port => {
4289
+ // @ts-ignore
4290
+ await undefined(port, 0);
4291
+ };
4292
+
4293
+ const initializeClipBoardWorker = async () => {
4294
+ const rpc = await LazyTransferElectronMessagePortRpc.create({
4295
+ commandMap: {},
4296
+ send: sendMessagePortToClipBoardWorker
4297
+ });
4298
+ set$4(rpc);
4299
+ };
4300
+
4142
4301
  const send = port => {
4143
4302
  return sendMessagePortToIconThemeWorker(port, 0);
4144
4303
  };
@@ -4168,7 +4327,7 @@ const initializeRendererWorker = async () => {
4168
4327
 
4169
4328
  const listen = async () => {
4170
4329
  registerCommands(commandMap);
4171
- await Promise.all([initializeRendererWorker(), initializeIconThemeWorker()]);
4330
+ await Promise.all([initializeRendererWorker(), initializeIconThemeWorker(), initializeClipBoardWorker()]);
4172
4331
  };
4173
4332
 
4174
4333
  const main$2 = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "7.2.0",
3
+ "version": "7.3.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",