@lvce-editor/main-process 6.39.0 → 6.41.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.
@@ -4791,7 +4791,7 @@ const windows = new Map();
4791
4791
  const setEnabled = (windowId, enabled) => {
4792
4792
  windows.get(windowId)?.setEnabled(enabled);
4793
4793
  };
4794
- const attach$d = (window, contents) => {
4794
+ const attach$e = (window, contents) => {
4795
4795
  windows.get(window.id)?.attach(contents);
4796
4796
  };
4797
4797
  const listen$2 = (window, rpc) => {
@@ -5497,32 +5497,47 @@ const getElectronCallbacks = () => {
5497
5497
  };
5498
5498
  };
5499
5499
 
5500
- const getElectronMenuItems = (menuItems, click) => {
5501
- const template = [];
5502
- for (const menuItem of menuItems) {
5503
- // @ts-ignore
5504
- 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 {
5505
5517
  ...menuItem,
5506
5518
  click
5507
- });
5508
- }
5509
- return template;
5519
+ };
5520
+ });
5510
5521
  };
5511
5522
 
5512
- const openContextMenu = async (menuItems, x, y) => {
5523
+ const openContextMenu = async (menuItems, x, y, browserViewId) => {
5513
5524
  array(menuItems);
5514
5525
  number(x);
5515
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
+ };
5516
5532
  const {
5517
5533
  handleClick,
5518
5534
  handleClose,
5519
5535
  promise
5520
5536
  } = getElectronCallbacks();
5521
- const template = getElectronMenuItems(menuItems, handleClick);
5537
+ const template = getElectronMenuItems(menuItems, handleClick, origin?.view.webContents);
5522
5538
  const menu = Menu.buildFromTemplate(template);
5523
- // TODO pass window id
5524
- const window = BrowserWindow.getFocusedWindow();
5525
- if (!window) {
5539
+ const window = origin?.browserWindow || BrowserWindow.getFocusedWindow();
5540
+ if (!window || window.isDestroyed()) {
5526
5541
  return {
5527
5542
  data: undefined,
5528
5543
  type: 'close'
@@ -6427,7 +6442,7 @@ const handleWebContentsViewZoomKeyBinding = (webContentsId, input) => {
6427
6442
  };
6428
6443
 
6429
6444
  const key$a = 'before-input';
6430
- const attach$c = (webContents, listener) => {
6445
+ const attach$d = (webContents, listener) => {
6431
6446
  webContents.on(BeforeInputEvent, listener);
6432
6447
  };
6433
6448
  const detach$a = (webContents, listener) => {
@@ -6467,14 +6482,14 @@ const handler$a = (event, input, webContentsId) => {
6467
6482
 
6468
6483
  const ElectronBrowserViewEventListenerBeforeInput = {
6469
6484
  __proto__: null,
6470
- attach: attach$c,
6485
+ attach: attach$d,
6471
6486
  detach: detach$a,
6472
6487
  handler: handler$a,
6473
6488
  key: key$a
6474
6489
  };
6475
6490
 
6476
6491
  const key$9 = AudioStateChanged;
6477
- const attach$b = (webContents, listener) => {
6492
+ const attach$c = (webContents, listener) => {
6478
6493
  webContents.on(AudioStateChanged, listener);
6479
6494
  };
6480
6495
  const detach$9 = (webContents, listener) => {
@@ -6489,29 +6504,32 @@ const handler$9 = event => {
6489
6504
 
6490
6505
  const ElectronBrowserViewEventListenerAudioStateChanged = {
6491
6506
  __proto__: null,
6492
- attach: attach$b,
6507
+ attach: attach$c,
6493
6508
  detach: detach$9,
6494
6509
  handler: handler$9,
6495
6510
  key: key$9
6496
6511
  };
6497
6512
 
6498
6513
  const key$8 = 'context-menu';
6499
- const attach$a = (webContents, listener) => {
6514
+ const attach$b = (webContents, listener) => {
6500
6515
  webContents.on(ContextMenu, listener);
6501
6516
  };
6502
6517
  const detach$8 = (webContents, listener) => {
6503
6518
  webContents.off(ContextMenu, listener);
6504
6519
  };
6505
- const handler$8 = (event, params) => {
6520
+ const handler$8 = (event, params, browserViewId) => {
6506
6521
  return {
6507
- messages: [['handleContextMenu', params]],
6522
+ messages: [['handleContextMenu', {
6523
+ ...params,
6524
+ browserViewId
6525
+ }]],
6508
6526
  result: undefined
6509
6527
  };
6510
6528
  };
6511
6529
 
6512
6530
  const ElectronBrowserViewEventListenerContextMenu = {
6513
6531
  __proto__: null,
6514
- attach: attach$a,
6532
+ attach: attach$b,
6515
6533
  detach: detach$8,
6516
6534
  handler: handler$8,
6517
6535
  key: key$8
@@ -6551,7 +6569,7 @@ const cancelForWebContents = webContentsId => {
6551
6569
  };
6552
6570
 
6553
6571
  const key$7 = 'destroyed';
6554
- const attach$9 = (webContents, listener) => {
6572
+ const attach$a = (webContents, listener) => {
6555
6573
  webContents.on(Destroyed, listener);
6556
6574
  };
6557
6575
  const detach$7 = (webContents, listener) => {
@@ -6579,7 +6597,7 @@ const handler$7 = (_event, webContentsId) => {
6579
6597
 
6580
6598
  const ElectronBrowserViewEventListenerDestroyed = {
6581
6599
  __proto__: null,
6582
- attach: attach$9,
6600
+ attach: attach$a,
6583
6601
  detach: detach$7,
6584
6602
  handler: handler$7,
6585
6603
  key: key$7
@@ -6596,7 +6614,7 @@ const has = (webContents, url) => {
6596
6614
  const maxFaviconBytes = 1024 * 1024;
6597
6615
  const faviconFetchTimeout = 2000;
6598
6616
  const key$6 = PageFaviconUpdated;
6599
- const attach$8 = (webContents, listener) => {
6617
+ const attach$9 = (webContents, listener) => {
6600
6618
  webContents.on(PageFaviconUpdated, listener);
6601
6619
  };
6602
6620
  const detach$6 = (webContents, listener) => {
@@ -6686,7 +6704,7 @@ const handler$6 = async (_event, favicons, _webContentsId, webContents) => {
6686
6704
 
6687
6705
  const ElectronBrowserViewEventListenerPageFaviconUpdated = {
6688
6706
  __proto__: null,
6689
- attach: attach$8,
6707
+ attach: attach$9,
6690
6708
  detach: detach$6,
6691
6709
  handler: handler$6,
6692
6710
  key: key$6,
@@ -6694,7 +6712,7 @@ const ElectronBrowserViewEventListenerPageFaviconUpdated = {
6694
6712
  };
6695
6713
 
6696
6714
  const key$5 = 'did-navigate';
6697
- const attach$7 = (webContents, listener) => {
6715
+ const attach$8 = (webContents, listener) => {
6698
6716
  webContents.on(DidNavigate, listener);
6699
6717
  };
6700
6718
  const detach$5 = (webContents, listener) => {
@@ -6731,14 +6749,14 @@ const handler$5 = async (_event, url, _httpResponseCode, _httpStatusText, _webCo
6731
6749
 
6732
6750
  const ElectronBrowserViewEventListenerDidNavigate = {
6733
6751
  __proto__: null,
6734
- attach: attach$7,
6752
+ attach: attach$8,
6735
6753
  detach: detach$5,
6736
6754
  handler: handler$5,
6737
6755
  key: key$5
6738
6756
  };
6739
6757
 
6740
6758
  const key$4 = DidNavigateInPage;
6741
- const attach$6 = (webContents, listener) => {
6759
+ const attach$7 = (webContents, listener) => {
6742
6760
  webContents.on(DidNavigateInPage, listener);
6743
6761
  };
6744
6762
  const detach$4 = (webContents, listener) => {
@@ -6754,14 +6772,14 @@ const handler$4 = (_event, url, isMainFrame) => {
6754
6772
 
6755
6773
  const ElectronBrowserViewEventListenerDidNavigateInPage = {
6756
6774
  __proto__: null,
6757
- attach: attach$6,
6775
+ attach: attach$7,
6758
6776
  detach: detach$4,
6759
6777
  handler: handler$4,
6760
6778
  key: key$4
6761
6779
  };
6762
6780
 
6763
6781
  const key$3 = Login;
6764
- const attach$5 = (webContents, listener) => {
6782
+ const attach$6 = (webContents, listener) => {
6765
6783
  webContents.on(Login, listener);
6766
6784
  };
6767
6785
  const detach$3 = (webContents, listener) => {
@@ -6786,14 +6804,14 @@ const handler$3 = (event, authenticationResponseDetails, authInfo, callback, web
6786
6804
 
6787
6805
  const ElectronBrowserViewEventListenerLogin = {
6788
6806
  __proto__: null,
6789
- attach: attach$5,
6807
+ attach: attach$6,
6790
6808
  detach: detach$3,
6791
6809
  handler: handler$3,
6792
6810
  key: key$3
6793
6811
  };
6794
6812
 
6795
6813
  const key$2 = 'page-title-updated';
6796
- const attach$4 = (webContents, listener) => {
6814
+ const attach$5 = (webContents, listener) => {
6797
6815
  webContents.on(PageTitleUpdated, listener);
6798
6816
  };
6799
6817
  const detach$2 = (webContents, listener) => {
@@ -6808,14 +6826,14 @@ const handler$2 = (event, title) => {
6808
6826
 
6809
6827
  const ElectronBrowserViewEventListenerPageTitleUpdated = {
6810
6828
  __proto__: null,
6811
- attach: attach$4,
6829
+ attach: attach$5,
6812
6830
  detach: detach$2,
6813
6831
  handler: handler$2,
6814
6832
  key: key$2
6815
6833
  };
6816
6834
 
6817
6835
  const key$1 = 'will-navigate';
6818
- const attach$3 = (webContents, listener) => {
6836
+ const attach$4 = (webContents, listener) => {
6819
6837
  webContents.on(WillNavigate, listener);
6820
6838
  };
6821
6839
  const detach$1 = (webContents, listener) => {
@@ -6830,14 +6848,14 @@ const handler$1 = (event, url) => {
6830
6848
 
6831
6849
  const ElectronBrowserViewEventListenerWillNavigate = {
6832
6850
  __proto__: null,
6833
- attach: attach$3,
6851
+ attach: attach$4,
6834
6852
  detach: detach$1,
6835
6853
  handler: handler$1,
6836
6854
  key: key$1
6837
6855
  };
6838
6856
 
6839
6857
  const key = 'window-open';
6840
- const attach$2 = (webContents, listener) => {
6858
+ const attach$3 = (webContents, listener) => {
6841
6859
  webContents.setWindowOpenHandler(listener);
6842
6860
  };
6843
6861
  const detach = (webContents, listener) => {
@@ -6867,7 +6885,7 @@ const handler = ({
6867
6885
 
6868
6886
  const ElectronBrowserViewEventListenerWindowOpen = {
6869
6887
  __proto__: null,
6870
- attach: attach$2,
6888
+ attach: attach$3,
6871
6889
  detach,
6872
6890
  handler,
6873
6891
  key
@@ -7037,8 +7055,13 @@ const getSession = () => {
7037
7055
  return state.session;
7038
7056
  };
7039
7057
 
7040
- const attach$1 = (webContents, parentWebContents) => {
7058
+ const attach$2 = (webContents, parentWebContents) => {
7041
7059
  let shouldRestoreParentFocus = false;
7060
+ const cancel = () => {
7061
+ shouldRestoreParentFocus = false;
7062
+ };
7063
+ parentWebContents.on('blur', cancel);
7064
+ webContents.once('destroyed', () => parentWebContents.off('blur', cancel));
7042
7065
  webContents.on(DidStartNavigation, (_event, _url, _isInPlace, isMainFrame) => {
7043
7066
  if (!isMainFrame) {
7044
7067
  return;
@@ -7046,7 +7069,7 @@ const attach$1 = (webContents, parentWebContents) => {
7046
7069
  shouldRestoreParentFocus = parentWebContents.isFocused();
7047
7070
  });
7048
7071
  webContents.on(DidNavigate, () => {
7049
- if (!shouldRestoreParentFocus) {
7072
+ if (!shouldRestoreParentFocus || parentWebContents.isDestroyed()) {
7050
7073
  return;
7051
7074
  }
7052
7075
  shouldRestoreParentFocus = false;
@@ -7086,7 +7109,7 @@ const isSoundCloudUrl = url => {
7086
7109
  return false;
7087
7110
  }
7088
7111
  };
7089
- const attach = webContents => {
7112
+ const attach$1 = webContents => {
7090
7113
  webContents.on(DidNavigate, (_event, url) => {
7091
7114
  if (!isSoundCloudUrl(url)) {
7092
7115
  return;
@@ -7103,14 +7126,23 @@ const send = (method, ...params) => {
7103
7126
  return rpc.send(method, ...params);
7104
7127
  };
7105
7128
 
7129
+ const focusTimes = new WeakMap();
7130
+ const attach = contents => {
7131
+ if (focusTimes.has(contents)) return;
7132
+ focusTimes.set(contents, 0);
7133
+ contents.on('focus', () => focusTimes.set(contents, Date.now()));
7134
+ };
7135
+ const getLastFocusedAt = contents => focusTimes.get(contents) || 0;
7136
+
7106
7137
  const webContentsWithEventListeners = new WeakSet();
7107
7138
  const attachEventListenersToWebContents = (webContentsId, webContents, browserWindow) => {
7108
7139
  if (webContentsWithEventListeners.has(webContents)) {
7109
7140
  return;
7110
7141
  }
7111
- attach$d(browserWindow, webContents);
7112
- attach$1(webContents, browserWindow.webContents);
7113
7142
  attach(webContents);
7143
+ attach$e(browserWindow, webContents);
7144
+ attach$2(webContents, browserWindow.webContents);
7145
+ attach$1(webContents);
7114
7146
  const values = Object.values(ElectronBrowserViewEventListeners);
7115
7147
  for (const value of values) {
7116
7148
  const handleResult = ({
@@ -7506,6 +7538,8 @@ const getStats = (view, includeMemory = false) => {
7506
7538
  canGoBack,
7507
7539
  canGoForward,
7508
7540
  isAudioMuted,
7541
+ isFocused: webContents.isFocused(),
7542
+ lastFocusedAt: getLastFocusedAt(webContents),
7509
7543
  title,
7510
7544
  url
7511
7545
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "6.39.0",
3
+ "version": "6.41.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"