@lvce-editor/main-process 6.13.0 → 6.14.1

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,7 +5,7 @@ import { fileURLToPath } from 'node:url';
5
5
  import { inspect } from 'node:util';
6
6
  import { spawn } from 'node:child_process';
7
7
  import { Console } from 'node:console';
8
- import { mkdirSync, createWriteStream, readFileSync, openAsBlob, existsSync, openSync, writeSync, closeSync, rmSync } from 'node:fs';
8
+ import { mkdirSync, createWriteStream, readFileSync, openAsBlob, existsSync, writeFileSync, rmSync, openSync, writeSync, closeSync } from 'node:fs';
9
9
  import * as NodePath from 'node:path';
10
10
  import { dirname, join as join$1 } from 'node:path';
11
11
  import { homedir, tmpdir } from 'node:os';
@@ -4066,7 +4066,6 @@ const PageTitleUpdated = 'page-title-updated';
4066
4066
  const Destroyed = 'destroyed';
4067
4067
  const BeforeInputEvent = 'before-input-event';
4068
4068
 
4069
- const Allow = 'allow';
4070
4069
  const Deny = 'deny';
4071
4070
 
4072
4071
  const shouldOpenExternal = url => {
@@ -4888,6 +4887,106 @@ const openContextMenu = async (menuItems, x, y) => {
4888
4887
  }
4889
4888
  };
4890
4889
 
4890
+ const profileDuration = 10_000;
4891
+ const getFileName$1 = targetName => {
4892
+ const safeTargetName = targetName.replaceAll(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-/, '').replace(/-$/, '') || 'extension-host';
4893
+ return `${safeTargetName}-${Date.now()}.cpuprofile`;
4894
+ };
4895
+ const wait = async () => {
4896
+ await new Promise(resolve => {
4897
+ setTimeout(resolve, profileDuration);
4898
+ });
4899
+ };
4900
+ const takeCpuProfile = async (windowId, workerName) => {
4901
+ const browserWindow = Electron.BrowserWindow.fromId(windowId);
4902
+ if (!browserWindow) {
4903
+ throw new Error(`Browser window not found: ${windowId}`);
4904
+ }
4905
+ const electronDebugger = browserWindow.webContents.debugger;
4906
+ const wasAttached = electronDebugger.isAttached();
4907
+ let filePath = '';
4908
+ let profileStarted = false;
4909
+ let profileStopped = false;
4910
+ let sessionId;
4911
+ let success = false;
4912
+ if (!wasAttached) {
4913
+ electronDebugger.attach();
4914
+ }
4915
+ try {
4916
+ if (workerName) {
4917
+ const {
4918
+ frameTree
4919
+ } = await electronDebugger.sendCommand('Page.getFrameTree');
4920
+ const {
4921
+ targetInfos
4922
+ } = await electronDebugger.sendCommand('Target.getTargets');
4923
+ const target = targetInfos.find(targetInfo => targetInfo.type === 'worker' && targetInfo.title === workerName && targetInfo.parentFrameId === frameTree.frame.id);
4924
+ if (!target) {
4925
+ throw new Error(`Worker not found: ${workerName}`);
4926
+ }
4927
+ const attachResult = await electronDebugger.sendCommand('Target.attachToTarget', {
4928
+ flatten: true,
4929
+ targetId: target.targetId
4930
+ });
4931
+ sessionId = attachResult.sessionId;
4932
+ }
4933
+ await electronDebugger.sendCommand('Profiler.enable', undefined, sessionId);
4934
+ await electronDebugger.sendCommand('Profiler.start', undefined, sessionId);
4935
+ profileStarted = true;
4936
+ await wait();
4937
+ const {
4938
+ profile
4939
+ } = await electronDebugger.sendCommand('Profiler.stop', undefined, sessionId);
4940
+ profileStopped = true;
4941
+ const downloadsPath = Electron.app.getPath('downloads');
4942
+ mkdirSync(downloadsPath, {
4943
+ recursive: true
4944
+ });
4945
+ const targetName = workerName || `Extension Host Window ${windowId}`;
4946
+ filePath = join$1(downloadsPath, getFileName$1(targetName));
4947
+ writeFileSync(filePath, JSON.stringify(profile), {
4948
+ flag: 'wx'
4949
+ });
4950
+ success = true;
4951
+ return filePath;
4952
+ } finally {
4953
+ try {
4954
+ if (profileStarted && !profileStopped && electronDebugger.isAttached()) {
4955
+ await electronDebugger.sendCommand('Profiler.stop', undefined, sessionId);
4956
+ }
4957
+ if (electronDebugger.isAttached()) {
4958
+ await electronDebugger.sendCommand('Profiler.disable', undefined, sessionId);
4959
+ }
4960
+ } finally {
4961
+ try {
4962
+ if (!success && filePath) {
4963
+ rmSync(filePath, {
4964
+ force: true
4965
+ });
4966
+ }
4967
+ if (sessionId && electronDebugger.isAttached()) {
4968
+ await electronDebugger.sendCommand('Target.detachFromTarget', {
4969
+ sessionId
4970
+ });
4971
+ }
4972
+ } finally {
4973
+ if (!wasAttached && electronDebugger.isAttached()) {
4974
+ electronDebugger.detach();
4975
+ }
4976
+ }
4977
+ }
4978
+ }
4979
+ };
4980
+ const takeWindowCpuProfile = async windowId => {
4981
+ number(windowId);
4982
+ return takeCpuProfile(windowId, '');
4983
+ };
4984
+ const takeWorkerCpuProfile = async (windowId, workerName) => {
4985
+ number(windowId);
4986
+ string(workerName);
4987
+ return takeCpuProfile(windowId, workerName);
4988
+ };
4989
+
4891
4990
  const getFileName = workerName => {
4892
4991
  const safeWorkerName = workerName.replaceAll(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-/, '').replace(/-$/, '') || 'worker';
4893
4992
  return `${safeWorkerName}-${Date.now()}.heapsnapshot`;
@@ -5800,9 +5899,6 @@ const ElectronBrowserViewEventListenerWillNavigate = {
5800
5899
  key: key$1
5801
5900
  };
5802
5901
 
5803
- const BackgroundTab = 'background-tab';
5804
- const NewWindow = 'new-window';
5805
-
5806
5902
  const key = 'window-open';
5807
5903
  const attach = (webContents, listener) => {
5808
5904
  webContents.setWindowOpenHandler(listener);
@@ -5811,38 +5907,11 @@ const detach = (webContents, listener) => {
5811
5907
  webContents.setWindowOpenHandler(null);
5812
5908
  };
5813
5909
  const handler = ({
5814
- disposition,
5815
- features,
5816
- frameName,
5817
- postBody,
5818
- referrer,
5819
5910
  url
5820
5911
  }) => {
5821
- if (url === 'about:blank') {
5822
- return {
5823
- messages: [],
5824
- result: {
5825
- action: Allow
5826
- }
5827
- };
5828
- }
5829
- if (disposition === BackgroundTab) {
5830
- return {
5831
- messages: [['handleWindowOpen', url]],
5832
- result: {
5833
- action: Deny
5834
- }
5835
- };
5836
- }
5837
- if (disposition === NewWindow) {
5838
- return {
5839
- messages: [],
5840
- result: {
5841
- action: Allow
5842
- }
5843
- };
5912
+ if (shouldOpenExternal(url)) {
5913
+ void openExternal(url);
5844
5914
  }
5845
- info(`[main-process] blocked popup for ${url}`);
5846
5915
  return {
5847
5916
  messages: [],
5848
5917
  result: {
@@ -6601,6 +6670,8 @@ const commandMap = {
6601
6670
  'ElectronContextMenu.openContextMenu': openContextMenu,
6602
6671
  'ElectronDeveloper.crashMainProcess': crashMainProcess,
6603
6672
  'ElectronDeveloper.getPerformanceEntries': getPerformanceEntries,
6673
+ 'ElectronDeveloper.takeWindowCpuProfile': takeWindowCpuProfile,
6674
+ 'ElectronDeveloper.takeWorkerCpuProfile': takeWorkerCpuProfile,
6604
6675
  'ElectronDeveloper.takeWorkerHeapSnapshot': takeWorkerHeapSnapshot,
6605
6676
  'ElectronDialog.showMessageBox': showMessageBox,
6606
6677
  'ElectronDialog.showOpenDialog': showOpenDialog,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "6.13.0",
3
+ "version": "6.14.1",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"
@@ -14,7 +14,7 @@
14
14
  "type": "module",
15
15
  "main": "dist/mainProcessMain.js",
16
16
  "dependencies": {
17
- "electron": "43.1.1"
17
+ "electron": "43.2.0"
18
18
  },
19
19
  "engines": {
20
20
  "node": ">=22"