2018-09-13 16:10:51 +00:00
|
|
|
const { app, BrowserWindow, ipcMain } = require('electron');
|
2023-06-15 14:42:27 +00:00
|
|
|
const net = require('node:net');
|
|
|
|
const path = require('node:path');
|
2017-06-16 22:34:11 +00:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-08-13 16:30:20 +00:00
|
|
|
let currentWindowSandboxed = false;
|
2017-06-19 15:03:02 +00:00
|
|
|
|
2020-02-03 22:43:22 +00:00
|
|
|
app.whenReady().then(() => {
|
2018-08-13 16:30:20 +00:00
|
|
|
function testWindow (isSandboxed, callback) {
|
|
|
|
currentWindowSandboxed = isSandboxed;
|
2018-10-02 01:56:31 +00:00
|
|
|
const currentWindow = new BrowserWindow({
|
2018-08-13 16:30:20 +00:00
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
2018-08-13 16:30:20 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2017-06-26 21:12:03 +00:00
|
|
|
ipcMain.on('argv', (event, value) => {
|
2018-08-13 16:30:20 +00:00
|
|
|
if (currentWindowSandboxed) {
|
2017-06-26 21:12:03 +00:00
|
|
|
argv.sandbox = value;
|
2018-08-13 16:30:20 +00:00
|
|
|
} else {
|
2017-06-26 21:12:03 +00:00
|
|
|
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
|
|
|
});
|