start.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const electron = require('electron');
  2. const path = require('path');
  3. const url = require('url');
  4. const ipc = electron.ipcMain;
  5. const app = electron.app;
  6. const BrowserWindow = electron.BrowserWindow;
  7. let mainWindow;
  8. ipc.on('window-min',function(){
  9. mainWindow.minimize();
  10. });
  11. //登录窗口最大化
  12. ipc.on('window-max',function(){
  13. if (mainWindow.isMaximized()) {
  14. mainWindow.restore();
  15. } else {
  16. mainWindow.maximize();
  17. }
  18. });
  19. ipc.on('window-close',function(){
  20. mainWindow.close();
  21. });
  22. ipc.on('loadurl-message',function(arg){
  23. shell.openExternal(arg);
  24. });
  25. function createWindow() {
  26. mainWindow = new BrowserWindow({
  27. width: 1920,
  28. height: 900,
  29. transparent: true,
  30. frame: false
  31. });
  32. mainWindow.loadURL(url.format({
  33. pathname: path.join(__dirname, 'browser.html'),
  34. protocol: 'file:',
  35. slashes: true
  36. }));
  37. mainWindow.webContents.openDevTools();
  38. mainWindow.on('closed', function () {
  39. mainWindow = null
  40. });
  41. }
  42. app.on('ready', createWindow);
  43. app.on('window-all-closed', function () {
  44. if (process.platform !== 'darwin') {
  45. app.quit()
  46. }
  47. });
  48. app.on('activate', function () {
  49. if (mainWindow === null) {
  50. createWindow()
  51. }
  52. });