main.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Modules to control application life and create native browser window
  2. const {
  3. app,
  4. BrowserWindow,
  5. globalShortcut,
  6. } = require("electron");
  7. // const httpServer = require("http-server");
  8. const path = require('path')
  9. let port = 11086;
  10. // const server = httpServer.createServer({
  11. // // root:__dirname
  12. // root: "./",
  13. // });
  14. // server.listen(port);
  15. // Keep a global reference of the window object, if you don't, the window will
  16. // be closed automatically when the JavaScript object is garbage collected.
  17. let mainWindow;
  18. function createWindow() {
  19. // Create the browser window.
  20. mainWindow = new BrowserWindow({
  21. fullscreen: true, // 设置全屏
  22. width: 1920,
  23. height: 1000,
  24. icon: path.join(__dirname, './code/icon.png'),
  25. webPreferences: {
  26. preload: path.join(__dirname, './preload.js'),
  27. nodeIntegration: false,
  28. webSecurity: false,
  29. contextIsolation: false,
  30. },
  31. });
  32. mainWindow.setMenu(null)
  33. // `http://localhost:${port}/code/index.html`
  34. let url = path.join('file://', __dirname, '/code/index.html')
  35. mainWindow.loadURL(url, {
  36. userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36",
  37. });
  38. // Emitted when the window is closed.
  39. mainWindow.on("closed", function () {
  40. // Dereference the window object, usually you would store windows
  41. // in an array if your app supports multi windows, this is the time
  42. // when you should delete the corresponding element.
  43. mainWindow = null;
  44. });
  45. // mainWindow.webContents.openDevTools()
  46. globalShortcut.register("CommandOrControl+Shift+i", () => {
  47. mainWindow.webContents.openDevTools();
  48. });
  49. }
  50. // 保证每次都是无缓存状态
  51. app.commandLine.appendSwitch("--disable-http-cache");
  52. // This method will be called when Electron has finished
  53. // initialization and is ready to create browser windows.
  54. // Some APIs can only be used after this event occurs.
  55. app.on("ready", createWindow);
  56. // Quit when all windows are closed.
  57. app.on("window-all-closed", function () {
  58. // On OS X it is common for applications and their menu bar
  59. // to stay active until the user quits explicitly with Cmd + Q
  60. if (process.platform !== "darwin") {
  61. app.quit();
  62. }
  63. });
  64. app.on("activate", function () {
  65. // On OS X it's common to re-create a window in the app when the
  66. // dock icon is clicked and there are no other windows open.
  67. if (mainWindow === null) {
  68. createWindow();
  69. }
  70. });