main.js 704 B

123456789101112131415161718192021222324252627282930
  1. const { app, BrowserWindow, ipcMain } = require('electron')
  2. const path = require('path')
  3. function createWindow () {
  4. const mainWindow = new BrowserWindow({
  5. webPreferences: {
  6. preload: path.join(__dirname, 'preload.js')
  7. }
  8. })
  9. ipcMain.on('set-title', (event, title) => {
  10. const webContents = event.sender
  11. const win = BrowserWindow.fromWebContents(webContents)
  12. win.setTitle(title)
  13. })
  14. mainWindow.loadFile('index.html')
  15. }
  16. app.whenReady().then(() => {
  17. createWindow()
  18. app.on('activate', function () {
  19. if (BrowserWindow.getAllWindows().length === 0) createWindow()
  20. })
  21. })
  22. app.on('window-all-closed', function () {
  23. if (process.platform !== 'darwin') app.quit()
  24. })