Format
Plain text
Post date
2023-01-06 15:23
Publication Period
Unlimited
  1. // Native
  2. import { join } from 'path'
  3. import { format } from 'url'
  4. // Packages
  5. import { BrowserWindow, app, ipcMain, IpcMainEvent } from 'electron'
  6. import isDev from 'electron-is-dev'
  7. import prepareNext from 'electron-next'
  8. // Prepare the renderer once the app is ready
  9. app.on('ready', async () => {
  10. await prepareNext('./renderer')
  11. const mainWindow = new BrowserWindow({
  12. width: 800,
  13. height: 600,
  14. webPreferences: {
  15. nodeIntegration: false,
  16. contextIsolation: false,
  17. preload: join(__dirname, 'preload.js'),
  18. },
  19. })
  20. const url = isDev
  21. ? 'http://localhost:8000/'
  22. : format({
  23. pathname: join(__dirname, '../renderer/out/index.html'),
  24. protocol: 'file:',
  25. slashes: true,
  26. })
  27. mainWindow.loadURL(url)
  28. })
  29. // Quit the app once all windows are closed
  30. app.on('window-all-closed', app.quit)
  31. // listen the channel `message` and resend the received message to the renderer process
  32. ipcMain.on('message', (event: IpcMainEvent, message: any) => {
  33. console.log(message)
  34. setTimeout(() => event.sender.send('message', 'hi from electron'), 500)
  35. })
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text