main.js 934 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { app, BrowserWindow, Menu, ipcMain } from 'electron';
  2. import { fileURLToPath } from 'node:url';
  3. import path, { dirname } from 'node:path';
  4. const __filename = fileURLToPath(import.meta.url);
  5. const __dirname = dirname(__filename);
  6. function createWindow() {
  7. Menu.setApplicationMenu(null);
  8. const win = new BrowserWindow({
  9. width: 1200,
  10. height: 800,
  11. fullscreen: true,
  12. webPreferences: {
  13. preload: path.resolve(__dirname, './preload.js')
  14. },
  15. });
  16. win.loadURL(process.env.VITE_DEV_SERVER_URL || path.resolve(__dirname, '../dist/index.html'));
  17. if (process.env.NODE_ENV === 'development')
  18. win.webContents.openDevTools();
  19. ipcMain.on('close-window', () => {
  20. win.close();
  21. });
  22. ipcMain.on('toggle-fullscreen', () => {
  23. win.setFullScreen(!win.isFullScreen());
  24. });
  25. ipcMain.on('toggle-devtools', () => {
  26. win.webContents.toggleDevTools();
  27. });
  28. }
  29. app.whenReady().then(createWindow);