electron/spec/fixtures/api/mixed-sandbox-app/main.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

const {app, BrowserWindow, ipcMain} = require('electron')
const net = require('net')
2017-06-16 22:34:11 +00:00
const path = require('path')
2017-06-19 15:03:02 +00:00
process.on('uncaughtException', () => {
2017-06-16 22:34:11 +00:00
app.exit(1)
})
2017-06-28 15:33:06 +00:00
if (!process.argv.includes('--enable-mixed-sandbox')) {
app.enableMixedSandbox()
}
let sandboxWindow
let noSandboxWindow
2017-06-19 15:03:02 +00:00
app.once('ready', () => {
sandboxWindow = new BrowserWindow({
show: false,
webPreferences: {
2017-06-28 16:58:23 +00:00
preload: path.join(__dirname, 'electron-app-mixed-sandbox-preload.js'),
sandbox: true
2017-06-16 22:34:11 +00:00
}
})
sandboxWindow.loadURL('about:blank')
noSandboxWindow = new BrowserWindow({
show: false,
webPreferences: {
2017-06-28 16:58:23 +00:00
preload: path.join(__dirname, 'electron-app-mixed-sandbox-preload.js'),
sandbox: false
}
2017-06-16 22:34:11 +00:00
})
noSandboxWindow.loadURL('about:blank')
2017-06-16 22:34:11 +00:00
const argv = {
sandbox: null,
noSandbox: null,
sandboxDevtools: null,
noSandboxDevtools: null
2017-06-16 22:34:11 +00:00
}
2017-06-28 16:58:23 +00:00
let connected = false
function finish () {
2017-07-12 01:29:59 +00:00
if (connected && argv.sandbox != null && argv.noSandbox != null &&
argv.noSandboxDevtools != null && argv.sandboxDevtools != null) {
2017-06-28 16:58:23 +00:00
client.once('end', () => {
app.exit(0)
})
client.end(JSON.stringify(argv))
}
}
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox'
const client = net.connect(socketPath, () => {
connected = true
finish()
})
noSandboxWindow.webContents.once('devtools-opened', () => {
argv.noSandboxDevtools = true
finish()
})
noSandboxWindow.webContents.openDevTools()
sandboxWindow.webContents.once('devtools-opened', () => {
argv.sandboxDevtools = true
finish()
})
sandboxWindow.webContents.openDevTools()
ipcMain.on('argv', (event, value) => {
if (event.sender === sandboxWindow.webContents) {
argv.sandbox = value
} else if (event.sender === noSandboxWindow.webContents) {
argv.noSandbox = value
}
2017-06-28 16:58:23 +00:00
finish()
})
2017-06-16 22:34:11 +00:00
})