main.js 718 B

12345678910111213141516171819202122232425262728293031323334
  1. const { BrowserWindow, app, screen, ipcMain, desktopCapturer } = require('electron/main')
  2. let mainWindow = null
  3. ipcMain.handle('get-screen-size', () => {
  4. return screen.getPrimaryDisplay().workAreaSize
  5. })
  6. ipcMain.handle('get-sources', (event, options) => {
  7. return desktopCapturer.getSources(options)
  8. })
  9. function createWindow () {
  10. const windowOptions = {
  11. width: 600,
  12. height: 300,
  13. title: 'Take a Screenshot',
  14. webPreferences: {
  15. contextIsolation: false,
  16. nodeIntegration: true
  17. }
  18. }
  19. mainWindow = new BrowserWindow(windowOptions)
  20. mainWindow.loadFile('index.html')
  21. mainWindow.on('closed', () => {
  22. mainWindow = null
  23. })
  24. }
  25. app.whenReady().then(() => {
  26. createWindow()
  27. })