main.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Modules to control application life and create native browser window
  2. const {
  3. app,
  4. BrowserWindow
  5. } = require('electron')
  6. const httpServer = require('http-server/lib/http-server')
  7. const fs = require("fs");
  8. const server = httpServer.createServer({
  9. // root:__dirname
  10. root: '../'
  11. })
  12. server.listen(9000)
  13. const path = require('path')
  14. // Keep a global reference of the window object, if you don't, the window will
  15. // be closed automatically when the JavaScript object is garbage collected.
  16. let mainWindow
  17. function createWindow() {
  18. // Create the browser window.
  19. mainWindow = new BrowserWindow({
  20. width: 800,
  21. height: 600,
  22. webPreferences: {
  23. preload: path.join(__dirname, 'preload.js'),
  24. nodeIntegration: false,
  25. webSecurity: true
  26. }
  27. })
  28. // and load the index.html of the app.
  29. //mainWindow.loadFile('index.html')
  30. fs.readFile('../code.txt', 'utf-8', function (err, data) {
  31. let sceneArr = []
  32. if (err) {
  33. console.error(err);
  34. }
  35. else {
  36. console.log(data);
  37. sceneArr = data.split(',')
  38. }
  39. mainWindow.loadURL(`http://localhost:9000/showProPC.html?m=${sceneArr[0]}`, {
  40. userAgent: '5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3497.100 Safari/537.36'
  41. })
  42. })
  43. // Emitted when the window is closed.
  44. mainWindow.on('closed', function () {
  45. // Dereference the window object, usually you would store windows
  46. // in an array if your app supports multi windows, this is the time
  47. // when you should delete the corresponding element.
  48. mainWindow = null
  49. })
  50. }
  51. // This method will be called when Electron has finished
  52. // initialization and is ready to create browser windows.
  53. // Some APIs can only be used after this event occurs.
  54. app.on('ready', createWindow)
  55. // Quit when all windows are closed.
  56. app.on('window-all-closed', function () {
  57. // On OS X it is common for applications and their menu bar
  58. // to stay active until the user quits explicitly with Cmd + Q
  59. if (process.platform !== 'darwin') {
  60. app.quit()
  61. }
  62. })
  63. app.on('activate', function () {
  64. // On OS X it's common to re-create a window in the app when the
  65. // dock icon is clicked and there are no other windows open.
  66. if (mainWindow === null) {
  67. createWindow()
  68. }
  69. })
  70. // In this file you can include the rest of your app's specific main process
  71. // code. You can also put them in separate files and require them here.