@lvce-editor/main-process 2.3.0 → 2.5.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.
@@ -5,6 +5,7 @@ import { inspect } from 'node:util';
5
5
  import { spawn } from 'node:child_process';
6
6
  import { MessageChannel } from 'node:worker_threads';
7
7
  import { createWriteStream, readFileSync } from 'node:fs';
8
+ import { fileURLToPath } from 'node:url';
8
9
  import * as NodePath from 'node:path';
9
10
  import { dirname } from 'node:path';
10
11
  import require$$1 from 'tty';
@@ -12,7 +13,6 @@ import require$$1$1 from 'util';
12
13
  import require$$0 from 'os';
13
14
  import { Console } from 'node:console';
14
15
  import { tmpdir, homedir } from 'node:os';
15
- import { fileURLToPath } from 'node:url';
16
16
 
17
17
  function escapeStringRegexp(string) {
18
18
  if (typeof string !== 'string') {
@@ -757,7 +757,7 @@ const getNewLineIndex$2 = (string, startIndex = undefined) => {
757
757
 
758
758
  // TODO disable logging via environment variable, don't enable logging during tests
759
759
 
760
- const state$8 = {
760
+ const state$7 = {
761
761
  console: undefined
762
762
  };
763
763
  const createConsole = () => {
@@ -767,8 +767,8 @@ const createConsole = () => {
767
767
  return logger;
768
768
  };
769
769
  const getOrCreateLogger = () => {
770
- state$8.console ||= createConsole();
771
- return state$8.console;
770
+ state$7.console ||= createConsole();
771
+ return state$7.console;
772
772
  };
773
773
  const info = (...args) => {
774
774
  const logger = getOrCreateLogger();
@@ -2707,10 +2707,10 @@ const create$4 = (method, params) => {
2707
2707
  };
2708
2708
  };
2709
2709
  const callbacks = Object.create(null);
2710
- const set$2 = (id, fn) => {
2710
+ const set$1 = (id, fn) => {
2711
2711
  callbacks[id] = fn;
2712
2712
  };
2713
- const get$3 = id => {
2713
+ const get$4 = id => {
2714
2714
  return callbacks[id];
2715
2715
  };
2716
2716
  const remove$2 = id => {
@@ -2726,7 +2726,7 @@ const registerPromise = () => {
2726
2726
  resolve,
2727
2727
  promise
2728
2728
  } = Promise.withResolvers();
2729
- set$2(id, resolve);
2729
+ set$1(id, resolve);
2730
2730
  return {
2731
2731
  id,
2732
2732
  promise
@@ -2883,7 +2883,7 @@ const warn = (...args) => {
2883
2883
  console.warn(...args);
2884
2884
  };
2885
2885
  const resolve = (id, response) => {
2886
- const fn = get$3(id);
2886
+ const fn = get$4(id);
2887
2887
  if (!fn) {
2888
2888
  console.log(response);
2889
2889
  warn(`callback ${id} may already be disposed`);
@@ -3337,7 +3337,7 @@ const launchSharedProcess = async ({
3337
3337
  return sharedProcessRpc;
3338
3338
  };
3339
3339
 
3340
- const state$7 = {
3340
+ const state$6 = {
3341
3341
  /**
3342
3342
  * @type {any}
3343
3343
  */
@@ -3348,14 +3348,14 @@ const getOrCreate = async ({
3348
3348
  method,
3349
3349
  env = {}
3350
3350
  }) => {
3351
- if (!state$7.promise) {
3351
+ if (!state$6.promise) {
3352
3352
  // @ts-ignore
3353
- state$7.promise = launchSharedProcess({
3353
+ state$6.promise = launchSharedProcess({
3354
3354
  method,
3355
3355
  env
3356
3356
  });
3357
3357
  }
3358
- return state$7.promise;
3358
+ return state$6.promise;
3359
3359
  };
3360
3360
  const send$1 = async (method, ...params) => {
3361
3361
  const rpc = await getOrCreate({
@@ -4478,14 +4478,14 @@ const createTitleBar = items => {
4478
4478
 
4479
4479
  const PHASE_DEFAULT = 0;
4480
4480
  const PHASE_SHUTDOWN = -1;
4481
- const state$6 = {
4481
+ const state$5 = {
4482
4482
  phase: PHASE_DEFAULT
4483
4483
  };
4484
4484
  const isShutDown = () => {
4485
- return state$6.phase === PHASE_SHUTDOWN;
4485
+ return state$5.phase === PHASE_SHUTDOWN;
4486
4486
  };
4487
4487
  const setShutDown = () => {
4488
- state$6.phase = PHASE_SHUTDOWN;
4488
+ state$5.phase = PHASE_SHUTDOWN;
4489
4489
  };
4490
4490
 
4491
4491
  // TODO move this function to shared process
@@ -4782,41 +4782,41 @@ const BeforeInputEvent = 'before-input-event';
4782
4782
  const Allow = 'allow';
4783
4783
  const Deny = 'deny';
4784
4784
 
4785
- const state$5 = {
4785
+ const state$4 = {
4786
4786
  views: Object.create(null),
4787
4787
  fallThroughKeyBindings: [],
4788
4788
  canceled: Object.create(null)
4789
4789
  };
4790
4790
  const add$1 = (id, browserWindow, view) => {
4791
4791
  // state
4792
- state$5.views[id] = {
4792
+ state$4.views[id] = {
4793
4793
  browserWindow,
4794
4794
  view
4795
4795
  };
4796
4796
  };
4797
4797
  const hasWebContents = id => {
4798
4798
  number(id);
4799
- return id in state$5.views;
4799
+ return id in state$4.views;
4800
4800
  };
4801
4801
  /**
4802
4802
  *
4803
4803
  * @param {number} id
4804
4804
  * @returns {{browserWindow: Electron.BrowserWindow, view: Electron.WebContentsView}}
4805
4805
  */
4806
- const get$2 = id => {
4807
- return state$5.views[id];
4806
+ const get$3 = id => {
4807
+ return state$4.views[id];
4808
4808
  };
4809
4809
  const remove$1 = id => {
4810
- delete state$5.views[id];
4810
+ delete state$4.views[id];
4811
4811
  };
4812
4812
  const setFallthroughKeyBindings = fallthroughKeyBindings => {
4813
- state$5.fallThroughKeyBindings = fallthroughKeyBindings;
4813
+ state$4.fallThroughKeyBindings = fallthroughKeyBindings;
4814
4814
  };
4815
4815
  const getFallthroughKeyBindings = () => {
4816
- return state$5.fallThroughKeyBindings;
4816
+ return state$4.fallThroughKeyBindings;
4817
4817
  };
4818
4818
  const setCanceled = id => {
4819
- state$5.canceled[id] = true;
4819
+ state$4.canceled[id] = true;
4820
4820
  };
4821
4821
 
4822
4822
  const shouldAllowNavigation = webContentsId => {
@@ -4829,6 +4829,7 @@ const shouldAllowNavigation = webContentsId => {
4829
4829
  const handleWebContentsWindowOpen = ({
4830
4830
  url
4831
4831
  }) => {
4832
+ // @ts-ignore
4832
4833
  void undefined(url);
4833
4834
  return {
4834
4835
  action: Deny
@@ -4891,13 +4892,6 @@ const privilegedSchems = [{
4891
4892
  }
4892
4893
  }];
4893
4894
 
4894
- /**
4895
- *
4896
- * @param {Electron.Protocol} protocol
4897
- * @param {string} name
4898
- * @param {(request: GlobalRequest) => Promise<GlobalResponse>} handleRequest
4899
- * @returns
4900
- */
4901
4895
  const handle = (protocol, name, handleRequest) => {
4902
4896
  if (isProtocolHandleApiSupported(protocol)) {
4903
4897
  protocol.handle(name, handleRequest);
@@ -4905,12 +4899,6 @@ const handle = (protocol, name, handleRequest) => {
4905
4899
  }
4906
4900
  throw new Error('protocol.handle api is not supported');
4907
4901
  };
4908
-
4909
- /**
4910
- *
4911
- * @param {Electron.Protocol} protocol
4912
- * @returns
4913
- */
4914
4902
  const enable = protocol => {
4915
4903
  protocol.registerSchemesAsPrivileged(privilegedSchems);
4916
4904
  };
@@ -5123,7 +5111,7 @@ const getModuleId = commandId => {
5123
5111
  }
5124
5112
  };
5125
5113
 
5126
- const state$4 = {
5114
+ const state$3 = {
5127
5115
  commands: Object.create(null),
5128
5116
  pendingModules: Object.create(null),
5129
5117
  async load(moduleId) {}
@@ -5143,21 +5131,21 @@ const initializeModule = module => {
5143
5131
  throw new Error(`module ${module.name || '<unnamed module>'} is missing commands`);
5144
5132
  };
5145
5133
  const getOrLoadModule = moduleId => {
5146
- if (!state$4.pendingModules[moduleId]) {
5147
- const importPromise = state$4.load(moduleId);
5148
- state$4.pendingModules[moduleId] = importPromise.then(initializeModule);
5134
+ if (!state$3.pendingModules[moduleId]) {
5135
+ const importPromise = state$3.load(moduleId);
5136
+ state$3.pendingModules[moduleId] = importPromise.then(initializeModule);
5149
5137
  }
5150
- return state$4.pendingModules[moduleId];
5138
+ return state$3.pendingModules[moduleId];
5151
5139
  };
5152
5140
  const loadCommand = command => getOrLoadModule(getModuleId(command));
5153
5141
  const register = (commandId, listener) => {
5154
- state$4.commands[commandId] = listener;
5142
+ state$3.commands[commandId] = listener;
5155
5143
  };
5156
5144
  const hasThrown = new Set();
5157
5145
  const loadThenExecute = async (command, ...args) => {
5158
5146
  await loadCommand(command);
5159
5147
  // TODO can skip then block in prod (only to prevent endless loop in dev)
5160
- if (!(command in state$4.commands)) {
5148
+ if (!(command in state$3.commands)) {
5161
5149
  if (hasThrown.has(command)) {
5162
5150
  return;
5163
5151
  }
@@ -5167,13 +5155,13 @@ const loadThenExecute = async (command, ...args) => {
5167
5155
  return execute(command, ...args);
5168
5156
  };
5169
5157
  const execute = (command, ...args) => {
5170
- if (command in state$4.commands) {
5171
- return state$4.commands[command](...args);
5158
+ if (command in state$3.commands) {
5159
+ return state$3.commands[command](...args);
5172
5160
  }
5173
5161
  return loadThenExecute(command, ...args);
5174
5162
  };
5175
5163
  const setLoad = load => {
5176
- state$4.load = load;
5164
+ state$3.load = load;
5177
5165
  };
5178
5166
 
5179
5167
  const ClipBoardRead = 'clipboard-read';
@@ -5265,134 +5253,52 @@ const createElectronSession = () => {
5265
5253
  return session;
5266
5254
  };
5267
5255
 
5268
- const state$3 = {
5256
+ const state$2 = {
5269
5257
  session: undefined
5270
5258
  };
5271
5259
  const has = () => {
5272
- return Boolean(state$3.session);
5260
+ return Boolean(state$2.session);
5273
5261
  };
5274
- const get$1 = () => {
5275
- if (!state$3.session) {
5262
+ const get$2 = () => {
5263
+ if (!state$2.session) {
5276
5264
  throw new Error('session is not defined');
5277
5265
  }
5278
- return state$3.session;
5279
- };
5280
- const set$1 = value => {
5281
- state$3.session = value;
5282
- };
5283
-
5284
- const printPrettyError = (prettyError, prefix = '') => {
5285
- error(`${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`);
5286
- };
5287
-
5288
- const logError = (error, prettyError) => {
5289
- printPrettyError(prettyError, '[main-process] ');
5290
- };
5291
- const handleMessage = event => {
5292
- return handleJsonRpcMessage(event.target, event.data, execute, resolve, prepare,
5293
- // @ts-ignore
5294
- logError, requiresSocket);
5295
- };
5296
-
5297
- const handleIpc = ipc => {
5298
- if ('addEventListener' in ipc) {
5299
- ipc.addEventListener('message', handleMessage);
5300
- } else if ('on' in ipc) {
5301
- // deprecated
5302
- ipc.on('message', handleMessage);
5303
- }
5304
- };
5305
- const unhandleIpc = ipc => {
5306
- if ('removeEventListener' in ipc) {
5307
- ipc.removeEventListener('message', handleMessage);
5308
- } else if ('off' in ipc) {
5309
- ipc.off('message', handleMessage);
5310
- }
5311
- };
5312
-
5313
- const NodeWorker = 1;
5314
- const NodeForkedProcess = 2;
5315
- const ElectronUtilityProcess = 3;
5316
- const ElectronMessagePort = 4;
5317
-
5318
- const getModule$2 = method => {
5319
- switch (method) {
5320
- case NodeWorker:
5321
- return IpcParentWithNodeWorker$1;
5322
- case NodeForkedProcess:
5323
- return IpcParentWithNodeForkedProcess$1;
5324
- case ElectronUtilityProcess:
5325
- return Promise.resolve().then(function () { return IpcParentWithElectronUtilityProcess; });
5326
- case ElectronMessagePort:
5327
- return IpcParentWithElectronMessagePort$1;
5328
- default:
5329
- throw new Error(`unexpected ipc type ${method}`);
5330
- }
5266
+ return state$2.session;
5331
5267
  };
5332
-
5333
- /**
5334
- *
5335
- * @param {*} param0
5336
- * @returns {Promise<any>}
5337
- */
5338
- const create$2 = async ({
5339
- method,
5340
- ...options
5341
- }) => {
5342
- const module = await getModule$2(method);
5343
- // @ts-ignore
5344
- const rawIpc = await module.create(options);
5345
- // @ts-ignore
5346
- if (module.effects) {
5347
- // @ts-ignore
5348
- module.effects({
5349
- rawIpc,
5350
- ...options
5351
- });
5352
- }
5353
- if (options.noReturn) {
5354
- return undefined;
5355
- }
5356
- // @ts-ignore
5357
- const ipc = module.wrap(rawIpc);
5358
- return ipc;
5268
+ const set = value => {
5269
+ state$2.session = value;
5359
5270
  };
5360
5271
 
5361
- const create$1 = ipc => {
5272
+ const create$2 = rpc => {
5362
5273
  const handleRequest = async request => {
5363
5274
  const {
5364
5275
  method,
5365
5276
  url
5366
5277
  } = request;
5367
- console.log('got request', method, url);
5368
5278
  const {
5369
5279
  body,
5370
5280
  init
5371
- } = await invoke$1(ipc, 'WebViewProtocol.getResponse', method, url);
5281
+ } = await rpc.invoke('WebViewProtocol.getResponse', method, url);
5372
5282
  return new Response(body, init);
5373
5283
  };
5374
5284
  return handleRequest;
5375
5285
  };
5376
5286
 
5377
- const get = () => {
5287
+ const get$1 = () => {
5378
5288
  if (!has()) {
5379
- set$1(createElectronSession());
5289
+ set(createElectronSession());
5380
5290
  }
5381
- return get$1();
5291
+ return get$2();
5382
5292
  };
5383
5293
  const registerWebviewProtocol = async port => {
5384
5294
  object(port);
5385
- console.log('will register ptorocol');
5386
- const ipc = await create$2({
5387
- method: ElectronMessagePort,
5388
- messagePort: port
5295
+ const rpc = await ElectronMessagePortRpcClient.create({
5296
+ commandMap: {},
5297
+ messagePort: port,
5298
+ requiresSocket: requiresSocket
5389
5299
  });
5390
- console.log('do register protocol');
5391
- handleIpc(ipc);
5392
- port.start();
5393
- const session = get();
5394
- const handleRequest = create$1(ipc);
5395
- // @ts-ignore
5300
+ const session = get$1();
5301
+ const handleRequest = create$2(rpc);
5396
5302
  handle(session.protocol, WebView, handleRequest);
5397
5303
  };
5398
5304
 
@@ -5422,7 +5328,7 @@ const loadUrl = async (browserWindow, url) => {
5422
5328
 
5423
5329
  // TODO avoid mixing BrowserWindow, childprocess and various lifecycle methods in one file -> separate concerns
5424
5330
  const createAppWindow = async (windowOptions, parsedArgs, workingDirectory, titleBarItems, url) => {
5425
- const session = get();
5331
+ const session = get$1();
5426
5332
  mark(WillCreateCodeWindow);
5427
5333
  const window = new BrowserWindow({
5428
5334
  ...windowOptions,
@@ -5511,7 +5417,12 @@ const connectIpc$1 = async (rpc, browserWindowPort, ...params) => {
5511
5417
  browserWindowPort.start();
5512
5418
  };
5513
5419
 
5514
- const getModule$1 = method => {
5420
+ const NodeWorker = 1;
5421
+ const NodeForkedProcess = 2;
5422
+ const ElectronUtilityProcess = 3;
5423
+ const ElectronMessagePort = 4;
5424
+
5425
+ const getModule$2 = method => {
5515
5426
  switch (method) {
5516
5427
  case NodeWorker:
5517
5428
  return connectIpc$1;
@@ -5522,7 +5433,7 @@ const getModule$1 = method => {
5522
5433
  }
5523
5434
  };
5524
5435
  const connectIpc = async (method, rpc, browserWindowPort, ipcId) => {
5525
- const connectIpc = getModule$1(method);
5436
+ const connectIpc = getModule$2(method);
5526
5437
  return connectIpc(rpc, browserWindowPort, ipcId);
5527
5438
  };
5528
5439
 
@@ -5558,27 +5469,27 @@ const createMessagePort = async (ipcId, port, webContentsId) => {
5558
5469
  return webContentsId;
5559
5470
  };
5560
5471
 
5561
- const state$2 = {
5472
+ const state$1 = {
5562
5473
  all: Object.create(null)
5563
5474
  };
5564
5475
  const add = (pid, process, name) => {
5565
5476
  number(pid);
5566
5477
  object(process);
5567
5478
  string(name);
5568
- state$2.all[pid] = {
5479
+ state$1.all[pid] = {
5569
5480
  process,
5570
5481
  name
5571
5482
  };
5572
5483
  };
5573
5484
  const remove = pid => {
5574
5485
  number(pid);
5575
- delete state$2.all[pid];
5486
+ delete state$1.all[pid];
5576
5487
  };
5577
5488
  const getAll = () => {
5578
- return Object.entries(state$2.all);
5489
+ return Object.entries(state$1.all);
5579
5490
  };
5580
5491
  const getByName = name => {
5581
- for (const value of Object.values(state$2.all)) {
5492
+ for (const value of Object.values(state$1.all)) {
5582
5493
  // @ts-ignore
5583
5494
  if (value.name === name) {
5584
5495
  // @ts-ignore
@@ -5636,13 +5547,17 @@ const rpcs = Object.create(null);
5636
5547
  const set$3 = (id, rpc) => {
5637
5548
  rpcs[id] = rpc;
5638
5549
  };
5550
+ const get = id => {
5551
+ return rpcs[id];
5552
+ };
5639
5553
 
5640
5554
  const createUtilityProcessRpc = async options => {
5641
5555
  const rpc = await ElectronUtilityProcessRpcParent.create({
5642
5556
  commandMap: commandMapRef,
5643
5557
  ...options
5644
5558
  });
5645
- set$3(options.rpcId, rpc);
5559
+ const rpcId = options.targetRpcId || options.rpcId || options.ipcId;
5560
+ set$3(rpcId, rpc);
5646
5561
  };
5647
5562
 
5648
5563
  const serializeDeskopCapturerSource = source => {
@@ -6593,7 +6508,7 @@ const filter = {
6593
6508
  urls: ['<all_urls>']
6594
6509
  };
6595
6510
 
6596
- const state$1 = {
6511
+ const state = {
6597
6512
  session: undefined
6598
6513
  };
6599
6514
  const isAllowedPermission = permission => {
@@ -6626,24 +6541,16 @@ const createSession = () => {
6626
6541
  return session;
6627
6542
  };
6628
6543
  const getSession = () => {
6629
- state$1.session ||= createSession();
6630
- return state$1.session;
6544
+ state.session ||= createSession();
6545
+ return state.session;
6631
6546
  };
6632
6547
 
6633
- const state = {
6634
- ipc: undefined
6635
- };
6636
- const set = ipc => {
6637
- state.ipc = ipc;
6638
- };
6639
6548
  const send = (method, ...params) => {
6640
- const {
6641
- ipc
6642
- } = state;
6643
- if (!ipc) {
6549
+ const rpc = get(EmbedsProcess);
6550
+ if (!rpc) {
6644
6551
  return;
6645
6552
  }
6646
- send$2(ipc, method, ...params);
6553
+ return rpc.send(method, ...params);
6647
6554
  };
6648
6555
 
6649
6556
  // TODO use electron 30 webcontentsview api
@@ -6691,7 +6598,7 @@ const attachEventListeners = webContentsId => {
6691
6598
  };
6692
6599
  const disposeWebContentsView = browserViewId => {
6693
6600
  console.log('[main process] dispose browser view', browserViewId);
6694
- const instance = get$2(browserViewId);
6601
+ const instance = get$3(browserViewId);
6695
6602
  if (!instance) {
6696
6603
  return;
6697
6604
  }
@@ -6709,7 +6616,7 @@ const webContentsViewErrorPath = join(root, 'packages', 'main-process', 'pages',
6709
6616
 
6710
6617
  const wrapBrowserViewCommand = fn => {
6711
6618
  const wrappedCommand = (id, ...args) => {
6712
- const state = get$2(id);
6619
+ const state = get$3(id);
6713
6620
  if (!state) {
6714
6621
  console.log(`[main process] no browser view with id ${id}`);
6715
6622
  return;
@@ -6844,7 +6751,7 @@ const cancelNavigation = view => {
6844
6751
  };
6845
6752
  const show = id => {
6846
6753
  // console.log('[main-process] show browser view', id)
6847
- const state = get$2(id);
6754
+ const state = get$3(id);
6848
6755
  if (!state) {
6849
6756
  debug('[main-process] failed to show browser view', id);
6850
6757
  return;
@@ -6856,7 +6763,7 @@ const show = id => {
6856
6763
  browserWindow.contentView.addChildView(view);
6857
6764
  };
6858
6765
  const addToWindow = (browserWindowId, browserViewId) => {
6859
- const state = get$2(browserViewId);
6766
+ const state = get$3(browserViewId);
6860
6767
  const {
6861
6768
  view
6862
6769
  } = state;
@@ -6867,7 +6774,7 @@ const addToWindow = (browserWindowId, browserViewId) => {
6867
6774
  browserWindow.contentView.addChildView(view);
6868
6775
  };
6869
6776
  const hide = id => {
6870
- const state = get$2(id);
6777
+ const state = get$3(id);
6871
6778
  if (!state) {
6872
6779
  debug('[main-process] failed to hide browser view', id);
6873
6780
  return;
@@ -6942,7 +6849,36 @@ const getStats$1 = view => {
6942
6849
  };
6943
6850
  };
6944
6851
 
6945
- const getModule = method => {
6852
+ const printPrettyError = (prettyError, prefix = '') => {
6853
+ error(`${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`);
6854
+ };
6855
+
6856
+ const logError = (error, prettyError) => {
6857
+ printPrettyError(prettyError, '[main-process] ');
6858
+ };
6859
+ const handleMessage = event => {
6860
+ return handleJsonRpcMessage(event.target, event.data, execute, resolve, prepare,
6861
+ // @ts-ignore
6862
+ logError, requiresSocket);
6863
+ };
6864
+
6865
+ const handleIpc = ipc => {
6866
+ if ('addEventListener' in ipc) {
6867
+ ipc.addEventListener('message', handleMessage);
6868
+ } else if ('on' in ipc) {
6869
+ // deprecated
6870
+ ipc.on('message', handleMessage);
6871
+ }
6872
+ };
6873
+ const unhandleIpc = ipc => {
6874
+ if ('removeEventListener' in ipc) {
6875
+ ipc.removeEventListener('message', handleMessage);
6876
+ } else if ('off' in ipc) {
6877
+ ipc.off('message', handleMessage);
6878
+ }
6879
+ };
6880
+
6881
+ const getModule$1 = method => {
6946
6882
  switch (method) {
6947
6883
  case NodeForkedProcess$1:
6948
6884
  return IpcChildWithNodeForkedProcess$1;
@@ -6963,7 +6899,7 @@ const listen = async ({
6963
6899
  method,
6964
6900
  ...params
6965
6901
  }) => {
6966
- const module = getModule(method);
6902
+ const module = getModule$1(method);
6967
6903
  // @ts-ignore
6968
6904
  const rawIpc = await module.listen(params);
6969
6905
  // @ts-ignore
@@ -6981,7 +6917,7 @@ const open2 = async (options, url) => {
6981
6917
  ...options,
6982
6918
  webPreferences: {
6983
6919
  ...options.webPreferences,
6984
- session: get()
6920
+ session: get$1()
6985
6921
  }
6986
6922
  };
6987
6923
  const processExplorerWindow = new BrowserWindow(allOptions);
@@ -7030,18 +6966,62 @@ const getWindowId = webContentsId => {
7030
6966
  return browserWindow.id;
7031
6967
  };
7032
6968
 
7033
- const handleElectronMessagePort = async (messagePort, ipcId) => {
6969
+ const handleElectronMessagePort = async (messagePort, rpcId) => {
7034
6970
  object(messagePort);
7035
- const ipc = await listen({
7036
- method: ElectronMessagePort$1,
7037
- messagePort
6971
+ const rpc = await ElectronMessagePortRpcClient.create({
6972
+ messagePort: messagePort,
6973
+ commandMap: commandMapRef,
6974
+ requiresSocket: requiresSocket
7038
6975
  });
7039
- handleIpc(ipc);
7040
- if (ipcId === EmbedsProcess) {
7041
- set(ipc);
6976
+ if (rpcId) {
6977
+ set$3(rpcId, rpc);
6978
+ }
6979
+ };
6980
+
6981
+ const getModule = method => {
6982
+ switch (method) {
6983
+ case NodeWorker:
6984
+ return IpcParentWithNodeWorker$1;
6985
+ case NodeForkedProcess:
6986
+ return IpcParentWithNodeForkedProcess$1;
6987
+ case ElectronUtilityProcess:
6988
+ return Promise.resolve().then(function () { return IpcParentWithElectronUtilityProcess; });
6989
+ case ElectronMessagePort:
6990
+ return IpcParentWithElectronMessagePort$1;
6991
+ default:
6992
+ throw new Error(`unexpected ipc type ${method}`);
7042
6993
  }
7043
6994
  };
7044
6995
 
6996
+ /**
6997
+ *
6998
+ * @param {*} param0
6999
+ * @returns {Promise<any>}
7000
+ * @deprecated
7001
+ */
7002
+ const create$1 = async ({
7003
+ method,
7004
+ ...options
7005
+ }) => {
7006
+ const module = await getModule(method);
7007
+ // @ts-ignore
7008
+ const rawIpc = await module.create(options);
7009
+ // @ts-ignore
7010
+ if (module.effects) {
7011
+ // @ts-ignore
7012
+ module.effects({
7013
+ rawIpc,
7014
+ ...options
7015
+ });
7016
+ }
7017
+ if (options.noReturn) {
7018
+ return undefined;
7019
+ }
7020
+ // @ts-ignore
7021
+ const ipc = module.wrap(rawIpc);
7022
+ return ipc;
7023
+ };
7024
+
7045
7025
  const shouldOpenExternal = url => {
7046
7026
  if (url.startsWith('http:') || url.startsWith('https:')) {
7047
7027
  return true;
@@ -7127,6 +7107,10 @@ const createPortTuple = async (id1, id2) => {
7127
7107
  } = getPortTuple();
7128
7108
  await invokeAndTransfer('TemporaryMessagePort.handlePorts', port1, port2, id1, id2);
7129
7109
  };
7110
+
7111
+ /**
7112
+ * @deprecated
7113
+ */
7130
7114
  const sendTo = async (port, name, ipcId) => {
7131
7115
  string(name);
7132
7116
  object(port);
@@ -7137,6 +7121,18 @@ const sendTo = async (port, name, ipcId) => {
7137
7121
  await invokeAndTransfer$1(utilityProcessIpc, 'HandleElectronMessagePort.handleElectronMessagePort', port, ipcId);
7138
7122
  unhandleIpc(utilityProcessIpc);
7139
7123
  };
7124
+
7125
+ // TODO use rpc id, and then use rpc.invokeAndtransfer
7126
+ const sendTo2 = async (port, targetRpcId, sourceRpcId) => {
7127
+ object(port);
7128
+ const rpc = get(targetRpcId);
7129
+ if (!rpc) {
7130
+ throw new Error(`rpc ${targetRpcId} not found`);
7131
+ }
7132
+ await rpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', port, sourceRpcId);
7133
+ };
7134
+
7135
+ // todo dispose the rpc by rpc id
7140
7136
  const dispose$1 = name => {
7141
7137
  string(name);
7142
7138
  const formattedName = formatUtilityProcessName(name);
@@ -7188,21 +7184,21 @@ const commandMap = {
7188
7184
  'ElectronWebContentsView.createWebContentsView': createWebContentsView,
7189
7185
  'ElectronWebContentsView.disposeWebContentsView': disposeWebContentsView,
7190
7186
  'ElectronWebContentsViewFunctions.addToWindow': addToWindow,
7191
- 'ElectronWebContentsViewFunctions.backward': backward,
7192
- 'ElectronWebContentsViewFunctions.cancelNavigation': cancelNavigation,
7193
- 'ElectronWebContentsViewFunctions.copyImageAt': copyImageAt,
7194
- 'ElectronWebContentsViewFunctions.focus': focus,
7195
- 'ElectronWebContentsViewFunctions.forward': forward,
7196
- 'ElectronWebContentsViewFunctions.getStats': getStats$1,
7187
+ 'ElectronWebContentsViewFunctions.backward': wrapBrowserViewCommand(backward),
7188
+ 'ElectronWebContentsViewFunctions.cancelNavigation': wrapBrowserViewCommand(cancelNavigation),
7189
+ 'ElectronWebContentsViewFunctions.copyImageAt': wrapBrowserViewCommand(copyImageAt),
7190
+ 'ElectronWebContentsViewFunctions.focus': wrapBrowserViewCommand(focus),
7191
+ 'ElectronWebContentsViewFunctions.forward': wrapBrowserViewCommand(forward),
7192
+ 'ElectronWebContentsViewFunctions.getStats': wrapBrowserViewCommand(getStats$1),
7197
7193
  'ElectronWebContentsViewFunctions.hide': hide,
7198
- 'ElectronWebContentsViewFunctions.inspectElement': inspectElement,
7199
- 'ElectronWebContentsViewFunctions.openDevtools': openDevtools,
7200
- 'ElectronWebContentsViewFunctions.reload': reload,
7201
- 'ElectronWebContentsViewFunctions.resizeBrowserView': resizeBrowserView,
7202
- 'ElectronWebContentsViewFunctions.setBackgroundColor': setBackgroundColor,
7203
- 'ElectronWebContentsViewFunctions.setFallthroughKeyBindings': undefined,
7204
- 'ElectronWebContentsViewFunctions.setIframeSrc': setIframeSrc,
7205
- 'ElectronWebContentsViewFunctions.setIframeSrcFallback': setIframeSrcFallback,
7194
+ 'ElectronWebContentsViewFunctions.inspectElement': wrapBrowserViewCommand(inspectElement),
7195
+ 'ElectronWebContentsViewFunctions.openDevtools': wrapBrowserViewCommand(openDevtools),
7196
+ 'ElectronWebContentsViewFunctions.reload': wrapBrowserViewCommand(wrapBrowserViewCommand(reload)),
7197
+ 'ElectronWebContentsViewFunctions.resizeBrowserView': wrapBrowserViewCommand(resizeBrowserView),
7198
+ 'ElectronWebContentsViewFunctions.setBackgroundColor': wrapBrowserViewCommand(setBackgroundColor),
7199
+ 'ElectronWebContentsViewFunctions.setFallthroughKeyBindings': wrapBrowserViewCommand(setFallThroughKeyBindings),
7200
+ 'ElectronWebContentsViewFunctions.setIframeSrc': wrapBrowserViewCommand(setIframeSrc),
7201
+ 'ElectronWebContentsViewFunctions.setIframeSrcFallback': wrapBrowserViewCommand(setIframeSrcFallback),
7206
7202
  'ElectronWebContentsViewFunctions.show': show,
7207
7203
  'ElectronWindow.executeWebContentsFunction': executeWebContentsFunction,
7208
7204
  'ElectronWindow.executeWindowFunction': executeWindowFunction,
@@ -7212,7 +7208,7 @@ const commandMap = {
7212
7208
  'Exit.exit': exit,
7213
7209
  'GetWindowId.getWindowId': getWindowId,
7214
7210
  'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
7215
- 'IpcParent.create': create$2,
7211
+ 'IpcParent.create': create$1,
7216
7212
  'OpenExternal.openExternal': openExternal,
7217
7213
  'Process.getArgv': getArgv,
7218
7214
  'Process.getChromeVersion': getChromeVersion,
@@ -7223,6 +7219,7 @@ const commandMap = {
7223
7219
  'TemporaryMessagePort.createPortTuple': createPortTuple,
7224
7220
  'TemporaryMessagePort.dispose': dispose$1,
7225
7221
  'TemporaryMessagePort.sendTo': sendTo,
7222
+ 'TemporaryMessagePort.sendTo2': sendTo2,
7226
7223
  'Trash.trash': trash
7227
7224
  };
7228
7225
 
@@ -7679,7 +7676,7 @@ const ElectronWindowProcessExplorer_ipc = {
7679
7676
 
7680
7677
  const name$c = 'IpcParent';
7681
7678
  const Commands$c = {
7682
- create: create$2
7679
+ create: create$1
7683
7680
  };
7684
7681
 
7685
7682
  const IpcParent_ipc = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "lvce-editor",
@@ -15,7 +15,7 @@
15
15
  "type": "module",
16
16
  "main": "dist/mainProcessMain.js",
17
17
  "dependencies": {
18
- "electron": "36.1.0"
18
+ "electron": "36.2.0"
19
19
  },
20
20
  "engines": {
21
21
  "node": ">=22"