Skip to content

Commit

Permalink
feat: reconstitution by preload
Browse files Browse the repository at this point in the history
  • Loading branch information
HOUSHENGREN committed May 21, 2023
1 parent 3ca6421 commit 2de4a1b
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 134 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
'plugin:prettier/recommended', // prettier配置
],
rules: {
// 'no-unused-vars': '',
'no-shadow': 'off',
'no-console': 'off', // 允许代码出现console.log
'no-param-reassign': 'off', // 允许修改function的入参
Expand Down
13 changes: 12 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const isDev = require('electron-is-dev');
const { app, BrowserWindow } = require('electron');
const path = require('path');

app.on('ready', () => {
const mainWindow = new BrowserWindow({
Expand All @@ -8,10 +10,19 @@ app.on('ready', () => {
webPreferences: {
// webSecurity: false,
nodeIntegration: true,
contextIsolation: false,
// ontextBridge API can only be used when contextIsolation is enabled
// contextIsolation: false,
contextIsolation: true, // actually, it's a default value,but here i type it clearly
enableRemoteModule: true, // 使用remote模块,这一行实际上貌似可以胜利
preload: path.join(__dirname, 'preload.js'),
},
});

// eslint-disable-next-line global-require
require('@electron/remote/main').initialize();
// eslint-disable-next-line global-require
require('@electron/remote/main').enable(mainWindow.webContents);

mainWindow.webContents.openDevTools();

const url = isDev ? 'http://localhost:3000/' : 'dummy'; // dummy 占位,todo,生产环境先不管
Expand Down
Loading

0 comments on commit 2de4a1b

Please sign in to comment.