@lvce-editor/main-process 6.37.10 → 6.37.12

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.
@@ -4090,6 +4090,7 @@ const BeforeInputEvent = 'before-input-event';
4090
4090
  const Login = 'login';
4091
4091
  const AudioStateChanged = 'audio-state-changed';
4092
4092
 
4093
+ const Allow = 'allow';
4093
4094
  const Deny = 'deny';
4094
4095
 
4095
4096
  const shouldOpenExternal = url => {
@@ -6352,6 +6353,39 @@ const ElectronBrowserViewEventListenerContextMenu = {
6352
6353
  key: key$8
6353
6354
  };
6354
6355
 
6356
+ const pendingLogins = new Map();
6357
+ let nextRequestId = 1;
6358
+ const add = (webContentsId, callback) => {
6359
+ const requestId = `${webContentsId}:${nextRequestId++}`;
6360
+ pendingLogins.set(requestId, {
6361
+ callback,
6362
+ webContentsId
6363
+ });
6364
+ return requestId;
6365
+ };
6366
+ const take = requestId => {
6367
+ const pendingLogin = pendingLogins.get(requestId);
6368
+ pendingLogins.delete(requestId);
6369
+ return pendingLogin;
6370
+ };
6371
+ const accept = (requestId, username, password) => {
6372
+ const pendingLogin = take(requestId);
6373
+ pendingLogin?.callback(username, password);
6374
+ };
6375
+ const cancel = requestId => {
6376
+ const pendingLogin = take(requestId);
6377
+ pendingLogin?.callback();
6378
+ };
6379
+ const cancelForWebContents = webContentsId => {
6380
+ for (const [requestId, pendingLogin] of pendingLogins) {
6381
+ if (pendingLogin.webContentsId !== webContentsId) {
6382
+ continue;
6383
+ }
6384
+ pendingLogins.delete(requestId);
6385
+ pendingLogin.callback();
6386
+ }
6387
+ };
6388
+
6355
6389
  const key$7 = 'destroyed';
6356
6390
  const attach$9 = (webContents, listener) => {
6357
6391
  webContents.on(Destroyed, listener);
@@ -6359,9 +6393,22 @@ const attach$9 = (webContents, listener) => {
6359
6393
  const detach$7 = (webContents, listener) => {
6360
6394
  webContents.off(Destroyed, listener);
6361
6395
  };
6362
- const handler$7 = () => {
6396
+ const handler$7 = (_event, webContentsId) => {
6397
+ cancelForWebContents(webContentsId);
6398
+ const instance = get$4(webContentsId);
6399
+ const messages = instance ? [['handleBrowserViewDestroyed']] : [];
6400
+ if (instance) {
6401
+ const {
6402
+ browserWindow,
6403
+ view
6404
+ } = instance;
6405
+ remove(webContentsId);
6406
+ if (!browserWindow.isDestroyed()) {
6407
+ browserWindow.contentView.removeChildView(view);
6408
+ }
6409
+ }
6363
6410
  return {
6364
- messages: [['handleBrowserViewDestroyed']],
6411
+ messages,
6365
6412
  result: undefined
6366
6413
  };
6367
6414
  };
@@ -6549,39 +6596,6 @@ const ElectronBrowserViewEventListenerDidNavigateInPage = {
6549
6596
  key: key$4
6550
6597
  };
6551
6598
 
6552
- const pendingLogins = new Map();
6553
- let nextRequestId = 1;
6554
- const add = (webContentsId, callback) => {
6555
- const requestId = `${webContentsId}:${nextRequestId++}`;
6556
- pendingLogins.set(requestId, {
6557
- callback,
6558
- webContentsId
6559
- });
6560
- return requestId;
6561
- };
6562
- const take = requestId => {
6563
- const pendingLogin = pendingLogins.get(requestId);
6564
- pendingLogins.delete(requestId);
6565
- return pendingLogin;
6566
- };
6567
- const accept = (requestId, username, password) => {
6568
- const pendingLogin = take(requestId);
6569
- pendingLogin?.callback(username, password);
6570
- };
6571
- const cancel = requestId => {
6572
- const pendingLogin = take(requestId);
6573
- pendingLogin?.callback();
6574
- };
6575
- const cancelForWebContents = webContentsId => {
6576
- for (const [requestId, pendingLogin] of pendingLogins) {
6577
- if (pendingLogin.webContentsId !== webContentsId) {
6578
- continue;
6579
- }
6580
- pendingLogins.delete(requestId);
6581
- pendingLogin.callback();
6582
- }
6583
- };
6584
-
6585
6599
  const key$3 = Login;
6586
6600
  const attach$5 = (webContents, listener) => {
6587
6601
  webContents.on(Login, listener);
@@ -6668,12 +6682,21 @@ const detach = (webContents, listener) => {
6668
6682
  const handler = ({
6669
6683
  disposition,
6670
6684
  url
6671
- }) => {
6672
- const messages = shouldOpenExternal(url) ? [['handleWindowOpen', url, disposition]] : [];
6685
+ }, _webContentsId, _webContents, createWindow) => {
6686
+ const shouldCreateWindow = url === 'about:blank' || shouldOpenExternal(url);
6687
+ if (!shouldCreateWindow) {
6688
+ return {
6689
+ messages: [],
6690
+ result: {
6691
+ action: Deny
6692
+ }
6693
+ };
6694
+ }
6673
6695
  return {
6674
- messages,
6696
+ messages: [],
6675
6697
  result: {
6676
- action: Deny
6698
+ action: Allow,
6699
+ createWindow: options => createWindow(options, url, disposition)
6677
6700
  }
6678
6701
  };
6679
6702
  };
@@ -6944,7 +6967,13 @@ const attachEventListenersToWebContents = (webContentsId, webContents, browserWi
6944
6967
  };
6945
6968
  const wrappedListener = (...args) => {
6946
6969
  // @ts-ignore
6947
- const handlerResult = value.handler(...args, webContentsId, webContents);
6970
+ const createWindow = (options, url, disposition) => {
6971
+ const view = createWebContentsViewForWindow(browserWindow, options.webPreferences);
6972
+ send('ElectronWebContents.handleWindowOpen', webContentsId, view.webContents.id, url, disposition);
6973
+ return view.webContents;
6974
+ };
6975
+ // @ts-ignore Electron event handlers have different argument tuples
6976
+ const handlerResult = value.handler(...args, webContentsId, webContents, createWindow);
6948
6977
  if (handlerResult instanceof Promise) {
6949
6978
  return handleAsyncResult(handlerResult);
6950
6979
  }
@@ -6954,16 +6983,13 @@ const attachEventListenersToWebContents = (webContentsId, webContents, browserWi
6954
6983
  }
6955
6984
  webContentsWithEventListeners.add(webContents);
6956
6985
  };
6957
-
6958
- // TODO use electron 30 webcontentsview api
6959
- const createWebContentsView = async () => {
6986
+ const createWebContentsViewForWindow = (browserWindow, webPreferences = {}) => {
6960
6987
  const view = new WebContentsView({
6961
6988
  webPreferences: {
6989
+ ...webPreferences,
6962
6990
  session: getSession()
6963
6991
  }
6964
6992
  });
6965
- // TODO get browser window id from renderer worker
6966
- const browserWindow = BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0];
6967
6993
  view.setBounds({
6968
6994
  height: 720,
6969
6995
  width: 1280,
@@ -6974,12 +7000,17 @@ const createWebContentsView = async () => {
6974
7000
  const {
6975
7001
  webContents
6976
7002
  } = view;
6977
- const {
6978
- id
6979
- } = webContents;
6980
- add$1(id, browserWindow, view);
6981
- attachEventListenersToWebContents(id, webContents, browserWindow);
6982
- return id;
7003
+ add$1(webContents.id, browserWindow, view);
7004
+ attachEventListenersToWebContents(webContents.id, webContents, browserWindow);
7005
+ return view;
7006
+ };
7007
+
7008
+ // TODO use electron 30 webcontentsview api
7009
+ const createWebContentsView = async () => {
7010
+ // TODO get browser window id from renderer worker
7011
+ const browserWindow = BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0];
7012
+ const view = createWebContentsViewForWindow(browserWindow);
7013
+ return view.webContents.id;
6983
7014
  };
6984
7015
  const attachEventListeners = webContentsId => {
6985
7016
  number(webContentsId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-process",
3
- "version": "6.37.10",
3
+ "version": "6.37.12",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "electron"