mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-14 11:52:07 +08:00
增加上下文隔离
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const dayjs = require('dayjs');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* 默认配置
|
||||
@@ -52,8 +53,9 @@ module.exports = (appInfo) => {
|
||||
minHeight: 650,
|
||||
webPreferences: {
|
||||
//webSecurity: false,
|
||||
contextIsolation: false, // 设置此项为false后,才可在渲染进程中使用electron api
|
||||
contextIsolation: false, // false->可在渲染进程中使用electronApi,true->需要bridge.js(contextBridge)
|
||||
nodeIntegration: true,
|
||||
preload: path.join(appInfo.baseDir, 'preload', 'bridge.js'),
|
||||
},
|
||||
frame: true,
|
||||
show: true,
|
||||
|
||||
5
electron/preload/bridge.js
Normal file
5
electron/preload/bridge.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { contextBridge, ipcRenderer } = require('electron')
|
||||
|
||||
contextBridge.exposeInMainWorld('electron', {
|
||||
ipcRenderer: ipcRenderer,
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
const { ipcRenderer: ipc } = window.require && window.require('electron') || {}
|
||||
const { ipcRenderer: ipc } = (window.require && window.require('electron')) || window.electron || {}
|
||||
|
||||
/**
|
||||
* (将废弃,请使用 $ipcInvoke 代替)异步调用主函数
|
||||
|
||||
Reference in New Issue
Block a user