@lvce-editor/main-process 2.5.0 → 2.7.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.
@@ -1,5 +1,5 @@
1
1
  import * as Electron from 'electron';
2
- import Electron__default, { dialog, app, clipboard, BrowserWindow, MessageChannelMain, Menu, shell, desktopCapturer, contentTracing, net, netLog, powerSaveBlocker, safeStorage, screen, WebContentsView, webContents } from 'electron';
2
+ import Electron__default, { dialog, app, clipboard, BrowserWindow, MessageChannelMain, Menu, shell, desktopCapturer, contentTracing, net, netLog, powerSaveBlocker, safeStorage, screen, webContents, WebContentsView } from 'electron';
3
3
  import process$1 from 'node:process';
4
4
  import { inspect } from 'node:util';
5
5
  import { spawn } from 'node:child_process';
@@ -5544,7 +5544,7 @@ const createPidMap = () => {
5544
5544
  };
5545
5545
 
5546
5546
  const rpcs = Object.create(null);
5547
- const set$3 = (id, rpc) => {
5547
+ const set$5 = (id, rpc) => {
5548
5548
  rpcs[id] = rpc;
5549
5549
  };
5550
5550
  const get = id => {
@@ -5557,7 +5557,7 @@ const createUtilityProcessRpc = async options => {
5557
5557
  ...options
5558
5558
  });
5559
5559
  const rpcId = options.targetRpcId || options.rpcId || options.ipcId;
5560
- set$3(rpcId, rpc);
5560
+ set$5(rpcId, rpc);
5561
5561
  };
5562
5562
 
5563
5563
  const serializeDeskopCapturerSource = source => {
@@ -5805,6 +5805,53 @@ const getBounds = () => {
5805
5805
  };
5806
5806
  };
5807
5807
 
5808
+ const disposeWebContents = webContents => {
5809
+ if (webContents.close) {
5810
+ // electron v22
5811
+ webContents.close();
5812
+ // @ts-ignore
5813
+ } else if (webContents.destroy) {
5814
+ // older versions of electron
5815
+ // @ts-ignore
5816
+ webContents.destroy();
5817
+ }
5818
+ };
5819
+
5820
+ const getStats$1 = webContentsId => {
5821
+ number(webContentsId);
5822
+ const contents = webContents.fromId(webContentsId);
5823
+ if (!contents) {
5824
+ return undefined;
5825
+ }
5826
+ const canGoBack = contents.navigationHistory.canGoBack();
5827
+ const canGoForward = contents.navigationHistory.canGoForward();
5828
+ const url = contents.getURL();
5829
+ const title = contents.getTitle();
5830
+ return {
5831
+ canGoBack,
5832
+ canGoForward,
5833
+ url,
5834
+ title
5835
+ };
5836
+ };
5837
+ const dispose$1 = webContentsId => {
5838
+ number(webContentsId);
5839
+ const contents = webContents.fromId(webContentsId);
5840
+ if (!contents) {
5841
+ return;
5842
+ }
5843
+ disposeWebContents(contents);
5844
+ };
5845
+ const callFunction = (webContentsId, functionName, ...args) => {
5846
+ number(webContentsId);
5847
+ string(functionName);
5848
+ const contents = webContents.fromId(webContentsId);
5849
+ if (!contents) {
5850
+ return;
5851
+ }
5852
+ contents[functionName](...args);
5853
+ };
5854
+
5808
5855
  const KeyDown = 'keyDown';
5809
5856
 
5810
5857
  const Backspace$1 = 'Backspace';
@@ -6628,15 +6675,6 @@ const wrapBrowserViewCommand = fn => {
6628
6675
  };
6629
6676
  return wrappedCommand;
6630
6677
  };
6631
-
6632
- /**
6633
- *
6634
- * @param {Electron.BrowserView} view
6635
- * @param {number} x
6636
- * @param {number} y
6637
- * @param {number} width
6638
- * @param {number} height
6639
- */
6640
6678
  const resizeBrowserView = (view, x, y, width, height) => {
6641
6679
  object(view);
6642
6680
  number(x);
@@ -6658,12 +6696,6 @@ const setIframeSrcFallback = async (view, code, message) => {
6658
6696
  }
6659
6697
  });
6660
6698
  };
6661
-
6662
- /**
6663
- *
6664
- * @param {Electron.BrowserView} view
6665
- * @param {string} iframeSrc
6666
- */
6667
6699
  const setIframeSrc = async (view, iframeSrc) => {
6668
6700
  try {
6669
6701
  object(view);
@@ -6679,21 +6711,12 @@ const setIframeSrc = async (view, iframeSrc) => {
6679
6711
  throw betterError;
6680
6712
  }
6681
6713
  };
6682
- /**
6683
- *
6684
- * @param {Electron.BrowserView} view
6685
- */
6686
6714
  const focus = view => {
6687
6715
  const {
6688
6716
  webContents
6689
6717
  } = view;
6690
6718
  webContents.focus();
6691
6719
  };
6692
-
6693
- /**
6694
- *
6695
- * @param {Electron.BrowserView} view
6696
- */
6697
6720
  const openDevtools = view => {
6698
6721
  const {
6699
6722
  webContents
@@ -6701,43 +6724,40 @@ const openDevtools = view => {
6701
6724
  // TODO return promise that resolves once devtools are actually open
6702
6725
  webContents.openDevTools();
6703
6726
  };
6704
- /**
6705
- *
6706
- * @param {Electron.BrowserView} view
6707
- */
6727
+ const getSlimCode = html => {
6728
+ let result = html;
6729
+ result = result.replaceAll(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script\s*>/gi, '');
6730
+ result = result.replaceAll(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style\s*>/gi, '');
6731
+ return result;
6732
+ };
6733
+ const getDomTree = async view => {
6734
+ const {
6735
+ webContents
6736
+ } = view;
6737
+ const code = `document.body.outerHTML`;
6738
+ const result = await webContents.executeJavaScript(code);
6739
+ const slimCode = getSlimCode(result);
6740
+ return slimCode;
6741
+ };
6708
6742
  const reload = view => {
6709
6743
  const {
6710
6744
  webContents
6711
6745
  } = view;
6712
6746
  webContents.reload();
6713
6747
  };
6714
- /**
6715
- *
6716
- * @param {Electron.BrowserView} view
6717
- */
6718
6748
  const forward = view => {
6719
6749
  const {
6720
6750
  webContents
6721
6751
  } = view;
6722
- webContents.goForward();
6752
+ webContents.navigationHistory.goForward();
6723
6753
  };
6724
-
6725
- /**
6726
- *
6727
- * @param {Electron.BrowserView} view
6728
- */
6729
6754
  const backward = view => {
6730
6755
  // TODO return promise that resolves once devtools are actually open
6731
6756
  const {
6732
6757
  webContents
6733
6758
  } = view;
6734
- webContents.goBack();
6759
+ webContents.navigationHistory.goBack();
6735
6760
  };
6736
-
6737
- /**
6738
- *
6739
- * @param {Electron.BrowserView} view
6740
- */
6741
6761
  const cancelNavigation = view => {
6742
6762
  const {
6743
6763
  webContents
@@ -6745,8 +6765,8 @@ const cancelNavigation = view => {
6745
6765
  setCanceled(webContents.id);
6746
6766
  debug(`[main process] canceled navigation to ${webContents.getURL()}`);
6747
6767
  webContents.stop();
6748
- if (webContents.canGoBack()) {
6749
- webContents.goBack();
6768
+ if (webContents.navigationHistory.canGoBack()) {
6769
+ webContents.navigationHistory.goBack();
6750
6770
  }
6751
6771
  };
6752
6772
  const show = id => {
@@ -6833,7 +6853,7 @@ const setFallThroughKeyBindings = fallthroughKeyBindings => {
6833
6853
  /**
6834
6854
  * @param {Electron.BrowserView} view
6835
6855
  */
6836
- const getStats$1 = view => {
6856
+ const getStats = view => {
6837
6857
  const {
6838
6858
  webContents
6839
6859
  } = view;
@@ -6974,7 +6994,7 @@ const handleElectronMessagePort = async (messagePort, rpcId) => {
6974
6994
  requiresSocket: requiresSocket
6975
6995
  });
6976
6996
  if (rpcId) {
6977
- set$3(rpcId, rpc);
6997
+ set$5(rpcId, rpc);
6978
6998
  }
6979
6999
  };
6980
7000
 
@@ -7133,7 +7153,7 @@ const sendTo2 = async (port, targetRpcId, sourceRpcId) => {
7133
7153
  };
7134
7154
 
7135
7155
  // todo dispose the rpc by rpc id
7136
- const dispose$1 = name => {
7156
+ const dispose = name => {
7137
7157
  string(name);
7138
7158
  const formattedName = formatUtilityProcessName(name);
7139
7159
  const utilityProcess = getByName(formattedName);
@@ -7180,16 +7200,20 @@ const commandMap = {
7180
7200
  'ElectronShell.openExternal': openExternal,
7181
7201
  'ElectronShell.openPath': openPath,
7182
7202
  'ElectronShell.showItemInFolder': showItemInFolder,
7203
+ 'ElectronWebContents.callFunction': callFunction,
7204
+ 'ElectronWebContents.dispose': dispose$1,
7205
+ 'ElectronWebContents.getStats': getStats$1,
7183
7206
  'ElectronWebContentsView.attachEventListeners': attachEventListeners,
7184
7207
  'ElectronWebContentsView.createWebContentsView': createWebContentsView,
7185
7208
  'ElectronWebContentsView.disposeWebContentsView': disposeWebContentsView,
7186
7209
  'ElectronWebContentsViewFunctions.addToWindow': addToWindow,
7210
+ 'ElectronWebContentsViewFunctions.getDomTree': wrapBrowserViewCommand(getDomTree),
7187
7211
  'ElectronWebContentsViewFunctions.backward': wrapBrowserViewCommand(backward),
7188
7212
  'ElectronWebContentsViewFunctions.cancelNavigation': wrapBrowserViewCommand(cancelNavigation),
7189
7213
  'ElectronWebContentsViewFunctions.copyImageAt': wrapBrowserViewCommand(copyImageAt),
7190
7214
  'ElectronWebContentsViewFunctions.focus': wrapBrowserViewCommand(focus),
7191
7215
  'ElectronWebContentsViewFunctions.forward': wrapBrowserViewCommand(forward),
7192
- 'ElectronWebContentsViewFunctions.getStats': wrapBrowserViewCommand(getStats$1),
7216
+ 'ElectronWebContentsViewFunctions.getStats': wrapBrowserViewCommand(getStats),
7193
7217
  'ElectronWebContentsViewFunctions.hide': hide,
7194
7218
  'ElectronWebContentsViewFunctions.inspectElement': wrapBrowserViewCommand(inspectElement),
7195
7219
  'ElectronWebContentsViewFunctions.openDevtools': wrapBrowserViewCommand(openDevtools),
@@ -7217,7 +7241,7 @@ const commandMap = {
7217
7241
  'Process.getPid': getPid,
7218
7242
  'Process.getV8Version': getV8Version,
7219
7243
  'TemporaryMessagePort.createPortTuple': createPortTuple,
7220
- 'TemporaryMessagePort.dispose': dispose$1,
7244
+ 'TemporaryMessagePort.dispose': dispose,
7221
7245
  'TemporaryMessagePort.sendTo': sendTo,
7222
7246
  'TemporaryMessagePort.sendTo2': sendTo2,
7223
7247
  'Trash.trash': trash
@@ -7739,7 +7763,7 @@ const ElectronScreen_ipc = {
7739
7763
  const name$7 = 'TemporaryMessagePort';
7740
7764
  const Commands$7 = {
7741
7765
  createPortTuple: createPortTuple,
7742
- dispose: dispose$1,
7766
+ dispose: dispose,
7743
7767
  sendTo: sendTo
7744
7768
  };
7745
7769
 
@@ -7749,61 +7773,10 @@ const TemporaryMessagePort_ipc = {
7749
7773
  name: name$7
7750
7774
  };
7751
7775
 
7752
- /**
7753
- *
7754
- * @param {Electron.WebContents} webContents
7755
- */
7756
- const disposeWebContents = webContents => {
7757
- if (webContents.close) {
7758
- // electron v22
7759
- webContents.close();
7760
- // @ts-ignore
7761
- } else if (webContents.destroy) {
7762
- // older versions of electron
7763
- // @ts-ignore
7764
- webContents.destroy();
7765
- }
7766
- };
7767
-
7768
- const getStats = webContentsId => {
7769
- number(webContentsId);
7770
- const contents = webContents.fromId(webContentsId);
7771
- if (!contents) {
7772
- return undefined;
7773
- }
7774
- const canGoBack = contents.navigationHistory.canGoBack();
7775
- const canGoForward = contents.navigationHistory.canGoForward();
7776
- const url = contents.getURL();
7777
- const title = contents.getTitle();
7778
- return {
7779
- canGoBack,
7780
- canGoForward,
7781
- url,
7782
- title
7783
- };
7784
- };
7785
- const dispose = webContentsId => {
7786
- number(webContentsId);
7787
- const contents = webContents.fromId(webContentsId);
7788
- if (!contents) {
7789
- return;
7790
- }
7791
- disposeWebContents(contents);
7792
- };
7793
- const callFunction = (webContentsId, functionName, ...args) => {
7794
- number(webContentsId);
7795
- string(functionName);
7796
- const contents = webContents.fromId(webContentsId);
7797
- if (!contents) {
7798
- return;
7799
- }
7800
- contents[functionName](...args);
7801
- };
7802
-
7803
7776
  const name$6 = 'ElectronWebContents';
7804
7777
  const Commands$6 = {
7805
- dispose: dispose,
7806
- getStats: getStats,
7778
+ dispose: dispose$1,
7779
+ getStats: getStats$1,
7807
7780
  callFunction: callFunction
7808
7781
  };
7809
7782
 
@@ -7834,7 +7807,7 @@ const Commands$4 = {
7834
7807
  copyImageAt: wrapBrowserViewCommand(copyImageAt),
7835
7808
  focus: wrapBrowserViewCommand(focus),
7836
7809
  forward: wrapBrowserViewCommand(forward),
7837
- getStats: wrapBrowserViewCommand(getStats$1),
7810
+ getStats: wrapBrowserViewCommand(getStats),
7838
7811
  hide: hide,
7839
7812
  inspectElement: wrapBrowserViewCommand(inspectElement),
7840
7813
  openDevtools: wrapBrowserViewCommand(openDevtools),
@@ -7844,7 +7817,8 @@ const Commands$4 = {
7844
7817
  setFallthroughKeyBindings: setFallThroughKeyBindings,
7845
7818
  setIframeSrc: wrapBrowserViewCommand(setIframeSrc),
7846
7819
  setIframeSrcFallback: wrapBrowserViewCommand(setIframeSrcFallback),
7847
- show: show
7820
+ show: show,
7821
+ getDomTree: getDomTree
7848
7822
  };
7849
7823
 
7850
7824
  const ElectronWebContentsViewFunctions_ipc = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "lvce-editor",