@lvce-editor/main-process 6.38.0 → 6.40.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.
@@ -2230,7 +2230,7 @@ const IpcChildWithNodeForkedProcess$1 = {
2230
2230
  signal: signal$7,
2231
2231
  wrap: wrap$d
2232
2232
  };
2233
- const listen$3 = async () => {
2233
+ const listen$3$1 = async () => {
2234
2234
  const {
2235
2235
  parentPort
2236
2236
  } = await import('node:worker_threads');
@@ -2268,7 +2268,7 @@ const wrap$b = parentPort => {
2268
2268
  };
2269
2269
  const IpcChildWithNodeWorker$1 = {
2270
2270
  __proto__: null,
2271
- listen: listen$3,
2271
+ listen: listen$3$1,
2272
2272
  signal: signal$5,
2273
2273
  wrap: wrap$b
2274
2274
  };
@@ -3115,7 +3115,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
3115
3115
  const errorProperty = getErrorProperty(error, prettyError);
3116
3116
  return create$1$1(id, errorProperty);
3117
3117
  };
3118
- const create$9 = (message, result) => {
3118
+ const create$a = (message, result) => {
3119
3119
  return {
3120
3120
  id: message.id,
3121
3121
  jsonrpc: Two$2,
@@ -3124,7 +3124,7 @@ const create$9 = (message, result) => {
3124
3124
  };
3125
3125
  const getSuccessResponse = (message, result) => {
3126
3126
  const resultProperty = result ?? null;
3127
- return create$9(message, resultProperty);
3127
+ return create$a(message, resultProperty);
3128
3128
  };
3129
3129
  const getErrorResponseSimple = (id, error) => {
3130
3130
  return {
@@ -3234,7 +3234,7 @@ const invokeAndTransfer$1 = (ipc, method, ...params) => {
3234
3234
 
3235
3235
  const Two$1 = '2.0';
3236
3236
 
3237
- const create$8 = (method, params) => {
3237
+ const create$9 = (method, params) => {
3238
3238
  return {
3239
3239
  jsonrpc: Two$1,
3240
3240
  method,
@@ -3242,7 +3242,7 @@ const create$8 = (method, params) => {
3242
3242
  };
3243
3243
  };
3244
3244
 
3245
- const create$7 = (id, method, params) => {
3245
+ const create$8 = (id, method, params) => {
3246
3246
  const message = {
3247
3247
  id,
3248
3248
  jsonrpc: Two$1,
@@ -3253,12 +3253,12 @@ const create$7 = (id, method, params) => {
3253
3253
  };
3254
3254
 
3255
3255
  let id = 0;
3256
- const create$6 = () => {
3256
+ const create$7 = () => {
3257
3257
  return ++id;
3258
3258
  };
3259
3259
 
3260
3260
  const registerPromise = map => {
3261
- const id = create$6();
3261
+ const id = create$7();
3262
3262
  const {
3263
3263
  promise,
3264
3264
  resolve
@@ -3275,7 +3275,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
3275
3275
  id,
3276
3276
  promise
3277
3277
  } = registerPromise(callbacks);
3278
- const message = create$7(id, method, params);
3278
+ const message = create$8(id, method, params);
3279
3279
  if (useSendAndTransfer && ipc.sendAndTransfer) {
3280
3280
  ipc.sendAndTransfer(message);
3281
3281
  } else {
@@ -3311,7 +3311,7 @@ const createRpc = ipc => {
3311
3311
  * @deprecated
3312
3312
  */
3313
3313
  send(method, ...params) {
3314
- const message = create$8(method, params);
3314
+ const message = create$9(method, params);
3315
3315
  ipc.send(message);
3316
3316
  }
3317
3317
  };
@@ -3342,7 +3342,7 @@ const handleIpc$1 = ipc => {
3342
3342
  }
3343
3343
  };
3344
3344
 
3345
- const listen$2 = async (module, options) => {
3345
+ const listen$3 = async (module, options) => {
3346
3346
  const rawIpc = await module.listen(options);
3347
3347
  if (module.signal) {
3348
3348
  module.signal(rawIpc);
@@ -3351,14 +3351,14 @@ const listen$2 = async (module, options) => {
3351
3351
  return ipc;
3352
3352
  };
3353
3353
 
3354
- const create$5 = async ({
3354
+ const create$6 = async ({
3355
3355
  commandMap,
3356
3356
  messagePort,
3357
3357
  requiresSocket
3358
3358
  }) => {
3359
3359
  // TODO create a commandMap per rpc instance
3360
3360
  register(commandMap);
3361
- const ipc = await listen$2(IpcChildWithElectronMessagePort$1, {
3361
+ const ipc = await listen$3(IpcChildWithElectronMessagePort$1, {
3362
3362
  messagePort
3363
3363
  });
3364
3364
  if (requiresSocket) {
@@ -3369,7 +3369,7 @@ const create$5 = async ({
3369
3369
  return rpc;
3370
3370
  };
3371
3371
 
3372
- const create$4 = async ({
3372
+ const create$5 = async ({
3373
3373
  argv,
3374
3374
  commandMap,
3375
3375
  env,
@@ -3397,7 +3397,7 @@ const create$4 = async ({
3397
3397
  return rpc;
3398
3398
  };
3399
3399
 
3400
- const create$3 = async ({
3400
+ const create$4 = async ({
3401
3401
  commandMap,
3402
3402
  requiresSocket,
3403
3403
  webContents
@@ -3482,7 +3482,7 @@ const trackUtilityProcess = (rawIpc, name) => {
3482
3482
  };
3483
3483
 
3484
3484
  const createElectronUtilityProcessRpc = async options => {
3485
- const rpc = await create$4(options);
3485
+ const rpc = await create$5(options);
3486
3486
  const rpcWithRawIpc = rpc;
3487
3487
  trackUtilityProcess(rpcWithRawIpc.ipc?._rawIpc, options.name);
3488
3488
  return rpc;
@@ -3602,7 +3602,7 @@ const launchSharedProcess = async ({
3602
3602
  port2
3603
3603
  } = getPortTuple();
3604
3604
  await sharedProcessRpc.invokeAndTransfer('HandleElectronMessagePort.handleElectronMessagePort', port2, MainProcess);
3605
- await create$5({
3605
+ await create$6({
3606
3606
  commandMap: commandMapRef,
3607
3607
  messagePort: port1,
3608
3608
  requiresSocket: requiresSocket
@@ -4744,6 +4744,126 @@ const load = async (path, env = process.env) => {
4744
4744
  }
4745
4745
  };
4746
4746
 
4747
+ const create$3 = () => {
4748
+ let pressedAt = -1;
4749
+ let releasedAt = -1;
4750
+ let controlCode = '';
4751
+ const reset = () => {
4752
+ pressedAt = -1;
4753
+ releasedAt = -1;
4754
+ controlCode = '';
4755
+ };
4756
+ const accept = (input, now) => {
4757
+ if (!['ControlLeft', 'ControlRight'].includes(input.code) || input.alt || input.meta || input.shift || input.isComposing) {
4758
+ reset();
4759
+ return false;
4760
+ }
4761
+ if (input.isAutoRepeat) {
4762
+ return false;
4763
+ }
4764
+ if (input.type === 'keyDown') {
4765
+ if (pressedAt !== -1 || controlCode !== input.code || now - releasedAt > 400) {
4766
+ reset();
4767
+ }
4768
+ controlCode = input.code;
4769
+ pressedAt = now;
4770
+ return false;
4771
+ }
4772
+ if (input.type !== 'keyUp' || controlCode !== input.code || pressedAt === -1 || now - pressedAt > 250) {
4773
+ reset();
4774
+ return false;
4775
+ }
4776
+ pressedAt = -1;
4777
+ if (releasedAt !== -1 && now - releasedAt <= 400) {
4778
+ reset();
4779
+ return true;
4780
+ }
4781
+ releasedAt = now;
4782
+ return false;
4783
+ };
4784
+ return {
4785
+ accept,
4786
+ reset
4787
+ };
4788
+ };
4789
+
4790
+ const windows = new Map();
4791
+ const setEnabled = (windowId, enabled) => {
4792
+ windows.get(windowId)?.setEnabled(enabled);
4793
+ };
4794
+ const attach$d = (window, contents) => {
4795
+ windows.get(window.id)?.attach(contents);
4796
+ };
4797
+ const listen$2 = (window, rpc) => {
4798
+ const gesture = create$3();
4799
+ const disposers = new Map();
4800
+ let enabled = false;
4801
+ let pending;
4802
+ const reset = () => {
4803
+ gesture.reset();
4804
+ if (pending) {
4805
+ clearImmediate(pending);
4806
+ pending = undefined;
4807
+ }
4808
+ };
4809
+ const attachContents = contents => {
4810
+ if (disposers.has(contents)) {
4811
+ return;
4812
+ }
4813
+ const handleInput = (_event, input) => {
4814
+ if (!enabled || !window.isFocused()) {
4815
+ reset();
4816
+ return;
4817
+ }
4818
+ if (gesture.accept(input, performance.now())) {
4819
+ // Deliver the key release before moving focus to another WebContents.
4820
+ pending = setImmediate(() => {
4821
+ pending = undefined;
4822
+ if (enabled && !contents.isDestroyed() && contents.isFocused() && window.isFocused()) {
4823
+ rpc.send('Window.handleBrowserFullWidthGesture');
4824
+ }
4825
+ });
4826
+ }
4827
+ };
4828
+ const dispose = () => {
4829
+ reset();
4830
+ contents.off('before-input-event', handleInput);
4831
+ contents.off('before-mouse-event', reset);
4832
+ contents.off('blur', reset);
4833
+ contents.off('focus', reset);
4834
+ contents.off('destroyed', dispose);
4835
+ disposers.delete(contents);
4836
+ };
4837
+ contents.on('before-input-event', handleInput);
4838
+ contents.on('before-mouse-event', reset);
4839
+ contents.on('blur', reset);
4840
+ contents.on('focus', reset);
4841
+ contents.once('destroyed', dispose);
4842
+ disposers.set(contents, dispose);
4843
+ };
4844
+ windows.set(window.id, {
4845
+ attach: attachContents,
4846
+ setEnabled(value) {
4847
+ reset();
4848
+ enabled = value;
4849
+ }
4850
+ });
4851
+ attachContents(window.webContents);
4852
+ window.on('blur', reset);
4853
+ const dispose = () => {
4854
+ enabled = false;
4855
+ reset();
4856
+ for (const disposeContents of disposers.values()) {
4857
+ disposeContents();
4858
+ }
4859
+ window.off('blur', reset);
4860
+ window.off('closed', dispose);
4861
+ windows.delete(window.id);
4862
+ };
4863
+ window.once('closed', dispose);
4864
+ return dispose;
4865
+ };
4866
+
4747
4867
  const closePreparationTimeout = 1000;
4748
4868
  const prepareClose = async rpc => {
4749
4869
  let timeout;
@@ -4997,7 +5117,7 @@ const get$2 = () => {
4997
5117
  };
4998
5118
  const registerWebviewProtocol = async port => {
4999
5119
  object(port);
5000
- const rpc = await create$5({
5120
+ const rpc = await create$6({
5001
5121
  commandMap: {},
5002
5122
  messagePort: port,
5003
5123
  requiresSocket: requiresSocket
@@ -5118,12 +5238,16 @@ const createAppWindow = async (windowOptions, parsedArgs, workingDirectory, titl
5118
5238
  // window.setMenu(menu)
5119
5239
  window.setMenuBarVisibility(true);
5120
5240
  window.setAutoHideMenuBar(false);
5121
- const rpc = await create$3({
5241
+ const rpc = await create$4({
5122
5242
  commandMap: commandMapRef,
5123
5243
  webContents: window.webContents
5124
5244
  });
5125
5245
  const disposeFullScreenListener = listen$1(window, rpc);
5126
- const handleWindowClose = createWindowCloseHandler(window, rpc, error => handleError(new VError(error, `Failed to prepare window close`)), disposeFullScreenListener);
5246
+ const disposeBrowserGesture = listen$2(window, rpc);
5247
+ const handleWindowClose = createWindowCloseHandler(window, rpc, error => handleError(new VError(error, `Failed to prepare window close`)), () => {
5248
+ disposeBrowserGesture();
5249
+ disposeFullScreenListener();
5250
+ });
5127
5251
  window.on('close', handleWindowClose);
5128
5252
  await loadUrl(window, url);
5129
5253
  };
@@ -5373,32 +5497,47 @@ const getElectronCallbacks = () => {
5373
5497
  };
5374
5498
  };
5375
5499
 
5376
- const getElectronMenuItems = (menuItems, click) => {
5377
- const template = [];
5378
- for (const menuItem of menuItems) {
5379
- // @ts-ignore
5380
- template.push({
5500
+ const editingActions = new Set(['undo', 'redo', 'cut', 'copy', 'paste', 'selectAll']);
5501
+ const getElectronMenuItems = (menuItems, click, contents) => {
5502
+ return menuItems.map(menuItem => {
5503
+ const {
5504
+ role,
5505
+ ...options
5506
+ } = menuItem;
5507
+ if (contents && editingActions.has(role)) {
5508
+ return {
5509
+ ...options,
5510
+ click(item) {
5511
+ if (!contents.isDestroyed()) contents[role]();
5512
+ click(item);
5513
+ }
5514
+ };
5515
+ }
5516
+ return {
5381
5517
  ...menuItem,
5382
5518
  click
5383
- });
5384
- }
5385
- return template;
5519
+ };
5520
+ });
5386
5521
  };
5387
5522
 
5388
- const openContextMenu = async (menuItems, x, y) => {
5523
+ const openContextMenu = async (menuItems, x, y, browserViewId) => {
5389
5524
  array(menuItems);
5390
5525
  number(x);
5391
5526
  number(y);
5527
+ const origin = browserViewId === undefined ? undefined : get$4(browserViewId);
5528
+ if (browserViewId !== undefined && (!origin || origin.view.webContents.isDestroyed())) return {
5529
+ data: undefined,
5530
+ type: 'close'
5531
+ };
5392
5532
  const {
5393
5533
  handleClick,
5394
5534
  handleClose,
5395
5535
  promise
5396
5536
  } = getElectronCallbacks();
5397
- const template = getElectronMenuItems(menuItems, handleClick);
5537
+ const template = getElectronMenuItems(menuItems, handleClick, origin?.view.webContents);
5398
5538
  const menu = Menu.buildFromTemplate(template);
5399
- // TODO pass window id
5400
- const window = BrowserWindow.getFocusedWindow();
5401
- if (!window) {
5539
+ const window = origin?.browserWindow || BrowserWindow.getFocusedWindow();
5540
+ if (!window || window.isDestroyed()) {
5402
5541
  return {
5403
5542
  data: undefined,
5404
5543
  type: 'close'
@@ -5721,6 +5860,10 @@ const executeWindowFunction = (browserWindowId, key) => {
5721
5860
  if (!browserWindow) {
5722
5861
  return;
5723
5862
  }
5863
+ if (key === 'enableBrowserFullWidthGesture' || key === 'disableBrowserFullWidthGesture') {
5864
+ setEnabled(browserWindowId, key === 'enableBrowserFullWidthGesture');
5865
+ return;
5866
+ }
5724
5867
  if (key === 'toggleDevtools') {
5725
5868
  toggleDevtools(browserWindow);
5726
5869
  return;
@@ -6911,6 +7054,11 @@ const getSession = () => {
6911
7054
 
6912
7055
  const attach$1 = (webContents, parentWebContents) => {
6913
7056
  let shouldRestoreParentFocus = false;
7057
+ const cancel = () => {
7058
+ shouldRestoreParentFocus = false;
7059
+ };
7060
+ parentWebContents.on('blur', cancel);
7061
+ webContents.once('destroyed', () => parentWebContents.off('blur', cancel));
6914
7062
  webContents.on(DidStartNavigation, (_event, _url, _isInPlace, isMainFrame) => {
6915
7063
  if (!isMainFrame) {
6916
7064
  return;
@@ -6918,7 +7066,7 @@ const attach$1 = (webContents, parentWebContents) => {
6918
7066
  shouldRestoreParentFocus = parentWebContents.isFocused();
6919
7067
  });
6920
7068
  webContents.on(DidNavigate, () => {
6921
- if (!shouldRestoreParentFocus) {
7069
+ if (!shouldRestoreParentFocus || parentWebContents.isDestroyed()) {
6922
7070
  return;
6923
7071
  }
6924
7072
  shouldRestoreParentFocus = false;
@@ -6980,6 +7128,7 @@ const attachEventListenersToWebContents = (webContentsId, webContents, browserWi
6980
7128
  if (webContentsWithEventListeners.has(webContents)) {
6981
7129
  return;
6982
7130
  }
7131
+ attach$d(browserWindow, webContents);
6983
7132
  attach$1(webContents, browserWindow.webContents);
6984
7133
  attach(webContents);
6985
7134
  const values = Object.values(ElectronBrowserViewEventListeners);
@@ -7543,7 +7692,7 @@ const getWindowId = webContentsId => {
7543
7692
 
7544
7693
  const handleElectronMessagePort = async (messagePort, rpcId) => {
7545
7694
  object(messagePort);
7546
- const rpc = await create$5({
7695
+ const rpc = await create$6({
7547
7696
  commandMap: commandMapRef,
7548
7697
  messagePort: messagePort,
7549
7698
  requiresSocket: requiresSocket
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "6.38.0",
3
+ "version": "6.40.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"