LOCKING盒子版
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

70 Zeilen
1.8 KiB

  1. const { app, BrowserWindow, protocol } = require('electron');
  2. const path = require('path');
  3. const url = require('url');
  4. function createWindow() {
  5. //创建窗口
  6. let mainWindow = new BrowserWindow({
  7. height: 900,
  8. webPreferences: {
  9. // preload: path.join(__dirname, 'preload.js'),
  10. webSecurity: false,
  11. nodeIntegration: true,
  12. },
  13. backgroundColor: '#2e2c29',
  14. darkTheme: true,
  15. title: 'My App',
  16. width: 1700,
  17. frame: true,
  18. minWidth: 1300,
  19. minHeight: 900,
  20. });
  21. // 隐藏菜单栏
  22. mainWindow.setMenuBarVisibility(false);
  23. if (process.env.NODE_ENV === 'development') {
  24. // 开发环境
  25. // 加载页面并打开调试工具,根据 NODE_ENV
  26. // umijs 在dev时会给出相应的url,直接加载即可
  27. mainWindow.loadURL('http://localhost:8000/');
  28. mainWindow.webContents.openDevTools();
  29. } else {
  30. //生产环境
  31. // 加载html文件
  32. // 这里的路径是umi输出的html路径,如果没有修改过,路径和下面是一样的
  33. mainWindow.webContents.openDevTools();
  34. // mainWindow.loadFile(path.join(__dirname, '../dist/index.html'));
  35. mainWindow.loadURL(
  36. url.format({
  37. pathname: path.join(__dirname, '../dist/index.html'),
  38. protocol: 'file:',
  39. slashes: true,
  40. }),
  41. );
  42. }
  43. mainWindow.on('closed', () => {
  44. mainWindow = null;
  45. });
  46. }
  47. app.on('ready', () => {
  48. createWindow();
  49. app.on('activate', function () {
  50. // On macOS it's common to re-create a window in the app when the
  51. // dock icon is clicked and there are no other windows open.
  52. if (BrowserWindow.getAllWindows().length === 0) createWindow();
  53. });
  54. // protocol.interceptFileProtocol('file', (req,cb) => {
  55. // cb({
  56. // url: req.url,
  57. // })
  58. // });
  59. });
  60. app.on('window-all-closed', () => {
  61. if (process.platform !== 'darwin') {
  62. app.quit();
  63. }
  64. });