main: add context bridge communication example via preload script, set nodeIntegration to false by default, improve security
This commit is contained in:
1 parent
a540caf9d3
commit
8057a3521a
9 files changed
+64
-12
No files matched your search
@@ -0,0 +1,14 @@
|
||||
import { BrowserWindow, ipcMain } from 'electron'
|
||||
import Constants from './utils/Constants'
|
||||
|
||||
/*
|
||||
* IPC Communications
|
||||
* */
|
||||
export default class IPCs {
|
||||
static initialize(window: BrowserWindow) {
|
||||
// Get application version
|
||||
ipcMain.on('msgRequestGetVersion', () => {
|
||||
window.webContents.send('msgReceivedVersion', Constants.APP_VERSION)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { app, BrowserWindow, RenderProcessGoneDetails } from 'electron'
|
||||
import Constants from './utils/Constants'
|
||||
import * as electronRemote from '@electron/remote/main'
|
||||
import IPCs from './IPCs'
|
||||
|
||||
const exitApp = (mainWindow: BrowserWindow): void => {
|
||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||
@@ -48,6 +49,9 @@ export const createMainWindow = async (mainWindow: BrowserWindow): Promise<Brows
|
||||
await mainWindow.loadFile(Constants.APP_INDEX_URL_PROD)
|
||||
}
|
||||
|
||||
// Initialize IPC Communication
|
||||
IPCs.initialize(mainWindow)
|
||||
|
||||
return mainWindow
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import { join } from 'path'
|
||||
import { name, version } from '../../../package.json'
|
||||
|
||||
export default class Constants {
|
||||
static APP_NAME = 'Vutron'
|
||||
// Display app name (uppercase first letter)
|
||||
static APP_NAME = name.charAt(0).toUpperCase() + name.slice(1)
|
||||
|
||||
static APP_VERSION = version
|
||||
|
||||
static IS_DEV_ENV = process.env.NODE_ENV === 'development'
|
||||
|
||||
static IS_MAC = process.platform === 'darwin'
|
||||
|
||||
static DEFAULT_WEB_PREFERENCES = {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
nodeIntegrationInWorker: true,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
enableRemoteModule: false,
|
||||
preload: join(__dirname, '../preload/index.js')
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user