bruno/main/index.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-03-22 13:48:20 +01:00
const path = require('path');
2022-03-05 18:37:48 +01:00
const { format } = require('url');
2022-03-22 13:48:20 +01:00
const { BrowserWindow, app, Menu } = require('electron');
const { setContentSecurityPolicy } = require('electron-util');
2022-03-05 18:37:48 +01:00
2022-03-22 13:48:20 +01:00
const menuTemplate = require('./app/menu-template');
const registerIpc = require('./ipc');
2022-03-05 18:37:48 +01:00
const isDev = require('electron-is-dev');
const prepareNext = require('electron-next');
2022-03-22 13:48:20 +01:00
setContentSecurityPolicy(`
default-src * 'unsafe-inline' 'unsafe-eval';
script-src * 'unsafe-inline' 'unsafe-eval';
connect-src * 'unsafe-inline';
base-uri 'none';
form-action 'none';
frame-ancestors 'none';
`);
const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
let mainWindow;
2022-03-05 18:37:48 +01:00
// Prepare the renderer once the app is ready
app.on('ready', async () => {
await prepareNext('./renderer');
2022-03-22 13:48:20 +01:00
mainWindow = new BrowserWindow({
width: 1280,
height: 768,
2022-03-05 18:37:48 +01:00
webPreferences: {
2022-03-08 20:45:26 +01:00
nodeIntegration: true,
2022-03-22 13:48:20 +01:00
contextIsolation: true,
preload: path.join(__dirname, "preload.js")
2022-03-05 18:37:48 +01:00
},
});
const url = isDev
? 'http://localhost:8000'
: format({
2022-03-22 13:48:20 +01:00
pathname: path.join(__dirname, '../renderer/out/index.html'),
2022-03-05 18:37:48 +01:00
protocol: 'file:',
2022-03-22 13:48:20 +01:00
slashes: true
});
2022-03-05 18:37:48 +01:00
mainWindow.loadURL(url);
2022-03-22 13:48:20 +01:00
// register all ipc handlers
registerIpc(mainWindow);
2022-03-05 18:37:48 +01:00
});
// Quit the app once all windows are closed
app.on('window-all-closed', app.quit);