You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
1.3 KiB

  1. import {app, BrowserWindow, ipcMain, session} from 'electron';
  2. import {join} from 'path';
  3. function createWindow () {
  4. const mainWindow = new BrowserWindow({
  5. width: 800,
  6. height: 600,
  7. webPreferences: {
  8. preload: join(__dirname, 'preload.js'),
  9. nodeIntegration: false,
  10. contextIsolation: true,
  11. }
  12. });
  13. if (process.env.NODE_ENV === 'development') {
  14. const rendererPort = process.argv[2];
  15. mainWindow.loadURL(`http://localhost:${rendererPort}`);
  16. }
  17. else {
  18. mainWindow.loadFile(join(app.getAppPath(), 'renderer', 'index.html'));
  19. }
  20. }
  21. app.whenReady().then(() => {
  22. createWindow();
  23. session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
  24. callback({
  25. responseHeaders: {
  26. ...details.responseHeaders,
  27. 'Content-Security-Policy': ['script-src \'self\'']
  28. }
  29. })
  30. })
  31. app.on('activate', function () {
  32. // On macOS it's common to re-create a window in the app when the
  33. // dock icon is clicked and there are no other windows open.
  34. if (BrowserWindow.getAllWindows().length === 0) {
  35. createWindow();
  36. }
  37. });
  38. });
  39. app.on('window-all-closed', function () {
  40. if (process.platform !== 'darwin') app.quit()
  41. });
  42. ipcMain.on('message', (event, message) => {
  43. console.log(message);
  44. })