2017-06-26 21:12:03 +00:00
|
|
|
const {app, BrowserWindow, ipcMain} = require('electron')
|
2017-06-28 16:27:19 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:12:03 +00:00
|
|
|
let sandboxWindow
|
|
|
|
let noSandboxWindow
|
2017-06-19 15:03:02 +00:00
|
|
|
|
2017-06-26 21:12:03 +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'),
|
2017-06-26 21:12:03 +00:00
|
|
|
sandbox: true
|
2017-06-16 22:34:11 +00:00
|
|
|
}
|
|
|
|
})
|
2017-06-26 21:12:03 +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'),
|
2017-06-26 21:12:03 +00:00
|
|
|
sandbox: false
|
|
|
|
}
|
2017-06-16 22:34:11 +00:00
|
|
|
})
|
2017-06-26 21:12:03 +00:00
|
|
|
noSandboxWindow.loadURL('about:blank')
|
2017-06-16 22:34:11 +00:00
|
|
|
|
2017-06-26 21:12:03 +00:00
|
|
|
const argv = {
|
|
|
|
sandbox: null,
|
2017-07-12 01:18:36 +00:00
|
|
|
noSandbox: null,
|
|
|
|
sandboxDevtools: null,
|
|
|
|
noSandboxDevtools: null
|
2017-06-16 22:34:11 +00:00
|
|
|
}
|
2017-06-26 21:12:03 +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()
|
|
|
|
})
|
|
|
|
|
2017-07-12 01:18:36 +00:00
|
|
|
noSandboxWindow.webContents.once('devtools-opened', () => {
|
|
|
|
argv.noSandboxDevtools = true
|
|
|
|
finish()
|
|
|
|
})
|
|
|
|
noSandboxWindow.webContents.openDevTools()
|
|
|
|
|
|
|
|
sandboxWindow.webContents.once('devtools-opened', () => {
|
|
|
|
argv.sandboxDevtools = true
|
|
|
|
finish()
|
|
|
|
})
|
|
|
|
sandboxWindow.webContents.openDevTools()
|
|
|
|
|
2017-06-26 21:12:03 +00:00
|
|
|
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-26 21:12:03 +00:00
|
|
|
})
|
2017-06-16 22:34:11 +00:00
|
|
|
})
|