@lvce-editor/process-explorer-worker 3.16.0 → 3.18.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.
Files changed (2) hide show
  1. package/index.js +100 -51
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -240,7 +240,7 @@ const {
240
240
  getCommandIds,
241
241
  getKeys: getKeys$1,
242
242
  registerCommands,
243
- set: set$7,
243
+ set: set$9,
244
244
  wrapCommand,
245
245
  wrapGetter,
246
246
  wrapLoadContent
@@ -289,7 +289,7 @@ const create$d = (id, _uri, x, y, width, height, args, parentUid, platform = 0,
289
289
  x,
290
290
  y
291
291
  };
292
- set$7(state.uid, state, state);
292
+ set$9(state.uid, state, state);
293
293
  return state;
294
294
  };
295
295
 
@@ -1268,7 +1268,7 @@ const createMockRpc = ({
1268
1268
  };
1269
1269
 
1270
1270
  const rpcs = Object.create(null);
1271
- const set$6 = (id, rpc) => {
1271
+ const set$8 = (id, rpc) => {
1272
1272
  rpcs[id] = rpc;
1273
1273
  };
1274
1274
  const get = id => {
@@ -1301,7 +1301,7 @@ const create$a = rpcId => {
1301
1301
  const mockRpc = createMockRpc({
1302
1302
  commandMap
1303
1303
  });
1304
- set$6(rpcId, mockRpc);
1304
+ set$8(rpcId, mockRpc);
1305
1305
  // @ts-ignore
1306
1306
  mockRpc[Symbol.dispose] = () => {
1307
1307
  remove(rpcId);
@@ -1310,7 +1310,7 @@ const create$a = rpcId => {
1310
1310
  return mockRpc;
1311
1311
  },
1312
1312
  set(rpc) {
1313
- set$6(rpcId, rpc);
1313
+ set$8(rpcId, rpc);
1314
1314
  }
1315
1315
  };
1316
1316
  };
@@ -1509,6 +1509,7 @@ const ErrorWorker = 3308;
1509
1509
  const FileSystemWorker$1 = 209;
1510
1510
  const MainProcess = -5;
1511
1511
  const ProcessExplorerRenderer = 33;
1512
+ const RendererProcess = 1670;
1512
1513
  const RendererWorker = 1;
1513
1514
 
1514
1515
  const FocusSelector = 'Viewlet.focusSelector';
@@ -1520,39 +1521,44 @@ const Empty = 0;
1520
1521
  const FocusExplorer = 13;
1521
1522
 
1522
1523
  const {
1523
- invoke: invoke$3,
1524
- set: set$5
1524
+ invoke: invoke$5,
1525
+ set: set$7
1525
1526
  } = create$a(ErrorWorker);
1526
1527
  const prepare = async error => {
1527
- return invoke$3('Errors.prepare', error);
1528
+ return invoke$5('Errors.prepare', error);
1528
1529
  };
1529
1530
 
1530
1531
  const {
1531
- set: set$4
1532
+ set: set$6
1532
1533
  } = create$a(FileSystemWorker$1);
1533
1534
 
1534
1535
  const FileSystemWorker = {
1535
1536
  __proto__: null,
1536
- set: set$4
1537
+ set: set$6
1537
1538
  };
1538
1539
 
1539
1540
  const {
1540
1541
  dispose: dispose$4,
1541
- invoke: invoke$2,
1542
- set: set$3
1542
+ invoke: invoke$4,
1543
+ set: set$5
1543
1544
  } = create$a(MainProcess);
1544
1545
 
1545
1546
  const {
1546
- invoke: invoke$1,
1547
+ invoke: invoke$3,
1548
+ set: set$4
1549
+ } = create$a(RendererProcess);
1550
+
1551
+ const {
1552
+ invoke: invoke$2,
1547
1553
  invokeAndTransfer,
1548
- set: set$2
1554
+ set: set$3
1549
1555
  } = create$a(RendererWorker);
1550
1556
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
1551
1557
  number(uid);
1552
1558
  number(menuId);
1553
1559
  number(x);
1554
1560
  number(y);
1555
- await invoke$1('ContextMenu.show2', uid, menuId, x, y, args);
1561
+ await invoke$2('ContextMenu.show2', uid, menuId, x, y, args);
1556
1562
  };
1557
1563
  const sendMessagePortToErrorWorker$1 = async (port, rpcId) => {
1558
1564
  const command = 'Errors.handleMessagePort';
@@ -1572,7 +1578,7 @@ const debugProcess = async (state, index = state.focusedIndex) => {
1572
1578
  if (!process) {
1573
1579
  return state;
1574
1580
  }
1575
- await invoke$1('AttachDebugger.attachDebugger', process.pid);
1581
+ await invoke$2('AttachDebugger.attachDebugger', process.pid);
1576
1582
  return state;
1577
1583
  };
1578
1584
 
@@ -1631,7 +1637,7 @@ const update = async uid => {
1631
1637
  }
1632
1638
  pending.add(uid);
1633
1639
  try {
1634
- await invoke$1('ProcessExplorer.update');
1640
+ await invoke$2('ProcessExplorer.update');
1635
1641
  } catch (error) {
1636
1642
  console.error(error);
1637
1643
  } finally {
@@ -1675,11 +1681,11 @@ const handleProcessExplorerRpcClose = async () => {
1675
1681
  scheduledState
1676
1682
  } = viewletState;
1677
1683
  const newState = toProcessExplorerRpcClosedState(scheduledState);
1678
- set$7(uid, oldState, newState);
1684
+ set$9(uid, oldState, newState);
1679
1685
  didUpdate = true;
1680
1686
  }
1681
1687
  if (didUpdate) {
1682
- await invoke$1('ProcessExplorer.rerender');
1688
+ await invoke$2('ProcessExplorer.rerender');
1683
1689
  }
1684
1690
  };
1685
1691
 
@@ -2001,7 +2007,7 @@ const launchProcessExplorerNode = async onClose => {
2001
2007
  const {
2002
2008
  protocols,
2003
2009
  url
2004
- } = await invoke$1('WebSocketCapability.create', 'process-explorer');
2010
+ } = await invoke$2('WebSocketCapability.create', 'process-explorer');
2005
2011
  const webSocket = new WebSocket(url, protocols);
2006
2012
  webSocket.addEventListener('close', onClose);
2007
2013
  return await create$3({
@@ -2024,39 +2030,39 @@ const launchProcessExplorerNode = async onClose => {
2024
2030
  }
2025
2031
  };
2026
2032
 
2027
- const state$1 = {
2033
+ const state$2 = {
2028
2034
  rpc: undefined
2029
2035
  };
2030
- const invoke = async (method, ...params) => {
2031
- if (!state$1.rpc) {
2036
+ const invoke$1 = async (method, ...params) => {
2037
+ if (!state$2.rpc) {
2032
2038
  throw new Error('ProcessExplorerModule is not initialized');
2033
2039
  }
2034
- return state$1.rpc.invoke(method, ...params);
2040
+ return state$2.rpc.invoke(method, ...params);
2035
2041
  };
2036
- const set$1 = newRpc => {
2037
- state$1.rpc = newRpc;
2042
+ const set$2 = newRpc => {
2043
+ state$2.rpc = newRpc;
2038
2044
  };
2039
2045
  const clear = () => {
2040
- state$1.rpc = undefined;
2046
+ state$2.rpc = undefined;
2041
2047
  };
2042
2048
  const dispose$2 = async () => {
2043
2049
  const {
2044
2050
  rpc
2045
- } = state$1;
2046
- state$1.rpc = undefined;
2051
+ } = state$2;
2052
+ state$2.rpc = undefined;
2047
2053
  await rpc?.dispose();
2048
2054
  };
2049
2055
 
2050
- const state = {
2056
+ const state$1 = {
2051
2057
  initializedPlatform: 0
2052
2058
  };
2053
2059
  const handleClose = async () => {
2054
- state.initializedPlatform = 0;
2060
+ state$1.initializedPlatform = 0;
2055
2061
  clear();
2056
2062
  await handleProcessExplorerRpcClose();
2057
2063
  };
2058
2064
  const initializeProcessExplorer = async platform => {
2059
- if (state.initializedPlatform === platform) {
2065
+ if (state$1.initializedPlatform === platform) {
2060
2066
  return;
2061
2067
  }
2062
2068
  if (platform === Electron) {
@@ -2064,24 +2070,24 @@ const initializeProcessExplorer = async platform => {
2064
2070
  mainProcessRpc,
2065
2071
  processExplorerRpc
2066
2072
  } = await launchProcessExplorerElectron();
2067
- set$3(mainProcessRpc);
2068
- set$1(processExplorerRpc);
2069
- state.initializedPlatform = platform;
2073
+ set$5(mainProcessRpc);
2074
+ set$2(processExplorerRpc);
2075
+ state$1.initializedPlatform = platform;
2070
2076
  return;
2071
2077
  }
2072
2078
  if (platform === Remote) {
2073
2079
  const rpc = await launchProcessExplorerNode(() => {
2074
2080
  void handleClose();
2075
2081
  });
2076
- set$1(rpc);
2077
- state.initializedPlatform = platform;
2082
+ set$2(rpc);
2083
+ state$1.initializedPlatform = platform;
2078
2084
  }
2079
2085
  };
2080
2086
  const dispose$1 = async () => {
2081
2087
  const {
2082
2088
  initializedPlatform
2083
- } = state;
2084
- state.initializedPlatform = 0;
2089
+ } = state$1;
2090
+ state$1.initializedPlatform = 0;
2085
2091
  if (initializedPlatform === Electron) {
2086
2092
  await Promise.all([dispose$4(), dispose$2()]);
2087
2093
  return;
@@ -2098,14 +2104,14 @@ const dispose = async uid => {
2098
2104
  };
2099
2105
 
2100
2106
  const createE2eFixtureProcess = async (state, marker) => {
2101
- const pid = await invoke('Process.createE2eFixtureProcess', marker);
2107
+ const pid = await invoke$1('Process.createE2eFixtureProcess', marker);
2102
2108
  return {
2103
2109
  ...state,
2104
2110
  rootPid: pid
2105
2111
  };
2106
2112
  };
2107
2113
  const disposeE2eFixtureProcess = async (_uid, pidOrMarker) => {
2108
- await invoke('Process.disposeE2eFixtureProcess', pidOrMarker);
2114
+ await invoke$1('Process.disposeE2eFixtureProcess', pidOrMarker);
2109
2115
  };
2110
2116
 
2111
2117
  const expandAll = state => {
@@ -2336,7 +2342,7 @@ const handleContextMenu = async (state, index = state.focusedIndex, x = 0, y = 0
2336
2342
  focused: false,
2337
2343
  focusedIndex: numericIndex
2338
2344
  };
2339
- set$7(state.uid, state, newState);
2345
+ set$9(state.uid, state, newState);
2340
2346
  await show2(state.uid, ProcessExplorer$1, x, y, {
2341
2347
  index: numericIndex,
2342
2348
  menuId: ProcessExplorer$1
@@ -2355,12 +2361,45 @@ const handleFocus = state => {
2355
2361
  };
2356
2362
  };
2357
2363
 
2364
+ const state = {
2365
+ connected: false
2366
+ };
2367
+ const isConnected = () => {
2368
+ const {
2369
+ connected
2370
+ } = state;
2371
+ return connected;
2372
+ };
2373
+ const invoke = (method, ...params) => invoke$3(method, ...params);
2374
+ const set$1 = rpc => {
2375
+ set$4(rpc);
2376
+ state.connected = true;
2377
+ };
2378
+
2379
+ const handleMessagePort = async (port, viewletCommandMap) => {
2380
+ const executeViewletCommand = async (uid, command, ...args) => {
2381
+ const fn = viewletCommandMap[`ProcessExplorer.${command}`];
2382
+ if (typeof fn !== 'function') {
2383
+ throw new TypeError(`Viewlet command not found: ${command}`);
2384
+ }
2385
+ await fn(uid, ...args);
2386
+ await invoke$2('Viewlet.requestRender', uid);
2387
+ };
2388
+ const rpc = await create$6({
2389
+ commandMap: {
2390
+ 'Viewlet.executeViewletCommand': executeViewletCommand
2391
+ },
2392
+ messagePort: port
2393
+ });
2394
+ set$1(rpc);
2395
+ };
2396
+
2358
2397
  const killProcess = async (state, index = state.focusedIndex) => {
2359
2398
  const process = state.visibleProcesses[index];
2360
2399
  if (!process) {
2361
2400
  return state;
2362
2401
  }
2363
- const killPromise = invoke('Process.kill', process.pid);
2402
+ const killPromise = invoke$1('Process.kill', process.pid);
2364
2403
  if (process.name === 'process-explorer') {
2365
2404
  dispose$3(state.uid);
2366
2405
  void killPromise.catch(() => {});
@@ -2487,16 +2526,16 @@ const getFocusedIndex = (oldFocusedIndex, visibleProcesses) => {
2487
2526
  };
2488
2527
  const listProcesses = async (rootPid, platform) => {
2489
2528
  if (platform === Electron) {
2490
- const pidMap = await invoke$2('CreatePidMap.createPidMap');
2491
- return invoke('ListProcessesWithMemoryUsage.listProcessesWithMemoryUsage', rootPid, false, pidMap);
2529
+ const pidMap = await invoke$4('CreatePidMap.createPidMap');
2530
+ return invoke$1('ListProcessesWithMemoryUsage.listProcessesWithMemoryUsage', rootPid, false, pidMap);
2492
2531
  }
2493
- return invoke('ListProcessesWithMemoryUsage.listProcessesWithMemoryUsage', rootPid, false);
2532
+ return invoke$1('ListProcessesWithMemoryUsage.listProcessesWithMemoryUsage', rootPid, false);
2494
2533
  };
2495
2534
  const refresh = async state => {
2496
2535
  try {
2497
2536
  await initializeProcessExplorer(state.platform);
2498
2537
  const includeElectronData = state.platform === Electron;
2499
- const rootPid = state.rootPid === -1 ? await invoke('ProcessId.getMainProcessId', {
2538
+ const rootPid = state.rootPid === -1 ? await invoke$1('ProcessId.getMainProcessId', {
2500
2539
  includeElectronData
2501
2540
  }) : state.rootPid;
2502
2541
  const processes = await listProcesses(rootPid, state.platform);
@@ -3070,8 +3109,16 @@ const render2 = (uid, diffResult) => {
3070
3109
  oldState,
3071
3110
  scheduledState
3072
3111
  } = get$2(uid);
3073
- set$7(uid, scheduledState, scheduledState);
3074
- return applyRender(oldState, scheduledState, diffResult);
3112
+ set$9(uid, scheduledState, scheduledState);
3113
+ const commands = applyRender(oldState, scheduledState, diffResult);
3114
+ if (!isConnected()) return commands;
3115
+ return renderDirect(uid, commands);
3116
+ };
3117
+ const renderDirect = async (uid, commands) => {
3118
+ const rendererWorkerCommands = commands.filter(command => command[0] === 'Viewlet.setFocusContext');
3119
+ const rendererProcessCommands = commands.filter(command => command[0] !== 'Viewlet.setFocusContext');
3120
+ const transactionId = await invoke('Viewlet.queueCommands', uid, rendererProcessCommands);
3121
+ return [...rendererWorkerCommands, ['Viewlet.commitPending', uid, transactionId]];
3075
3122
  };
3076
3123
 
3077
3124
  const renderEventListeners = () => {
@@ -3161,6 +3208,7 @@ const setUpdateInterval = (state, updateInterval) => {
3161
3208
  };
3162
3209
  };
3163
3210
 
3211
+ const handleDirectMessagePort = port => handleMessagePort(port, commandMap);
3164
3212
  const commandMap = {
3165
3213
  'ProcessExplorer.collapseAll': wrapCommand(collapseAll),
3166
3214
  'ProcessExplorer.create': create$d,
@@ -3185,6 +3233,7 @@ const commandMap = {
3185
3233
  'ProcessExplorer.handleContextMenu': wrapCommand(handleContextMenu),
3186
3234
  'ProcessExplorer.handleDoubleClick': wrapCommand(handleDoubleClick),
3187
3235
  'ProcessExplorer.handleFocus': wrapCommand(handleFocus),
3236
+ 'ProcessExplorer.handleMessagePort': handleDirectMessagePort,
3188
3237
  'ProcessExplorer.killProcess': wrapCommand(killProcess),
3189
3238
  'ProcessExplorer.loadContent': wrapLoadContent(loadContent),
3190
3239
  'ProcessExplorer.refresh': wrapCommand(refresh),
@@ -3216,7 +3265,7 @@ const createErrorWorkerRpc = async () => {
3216
3265
 
3217
3266
  const initializeErrorWorker = async () => {
3218
3267
  const rpc = await createErrorWorkerRpc();
3219
- set$5(rpc);
3268
+ set$7(rpc);
3220
3269
  };
3221
3270
 
3222
3271
  const sendMessagePortToFileSystemWorker = async port => {
@@ -3248,7 +3297,7 @@ const initializeRendererWorker = async () => {
3248
3297
  const rpc = await create({
3249
3298
  commandMap: commandMap
3250
3299
  });
3251
- set$2(rpc);
3300
+ set$3(rpc);
3252
3301
  };
3253
3302
 
3254
3303
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/process-explorer-worker",
3
- "version": "3.16.0",
3
+ "version": "3.18.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",