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

78 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-09-13 16:10:51 +00:00
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)
})
2018-10-10 04:32:09 +00:00
if (process.argv.includes('--app-enable-sandbox')) {
app.enableSandbox()
}
let currentWindowSandboxed = false
2017-06-19 15:03:02 +00:00
app.whenReady().then(() => {
function testWindow (isSandboxed, callback) {
currentWindowSandboxed = isSandboxed
const currentWindow = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(__dirname, 'electron-app-mixed-sandbox-preload.js'),
sandbox: isSandboxed
}
})
currentWindow.loadURL('about:blank')
currentWindow.webContents.once('devtools-opened', () => {
if (isSandboxed) {
argv.sandboxDevtools = true
} else {
argv.noSandboxDevtools = true
}
if (callback) {
callback()
}
finish()
})
currentWindow.webContents.openDevTools()
}
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
testWindow(true, () => {
testWindow()
})
2017-06-28 16:58:23 +00:00
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()
})
ipcMain.on('argv', (event, value) => {
if (currentWindowSandboxed) {
argv.sandbox = value
} else {
argv.noSandbox = value
}
2017-06-28 16:58:23 +00:00
finish()
})
2017-06-16 22:34:11 +00:00
})