Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

88 строки
2.8 KiB

  1. // Modules to control application life and create native browser window
  2. const { app, BrowserWindow, protocol, ipcMain, dialog } = require('electron')
  3. const { request } = require('http')
  4. const path = require('path')
  5. const url = require('url')
  6. function createWindow() {
  7. // Create the browser window.
  8. const mainWindow = new BrowserWindow({
  9. width: 1080,
  10. height: 600,
  11. webPreferences: {
  12. nodeIntegration: true,
  13. // javascript: true,
  14. // plugins: true,
  15. preload: path.join(__dirname, 'electron-main', 'preload.js'),
  16. },
  17. // frame: false,
  18. })
  19. // const startUrl = url.format({
  20. // pathname: path.join(__dirname, './dist/index.html'),
  21. // protocol: 'file:',
  22. // slashes: true
  23. // });
  24. // console.log('startUrl:', startUrl)
  25. // and load the index.html of the app.
  26. // mainWindow.loadFile('./dist/index.html')
  27. // mainWindow.loadURL('http://47.104.91.134:9000');
  28. // mainWindow.loadURL('http://47.104.91.134:9000', { "extraHeaders": "pragma: no-cache\n" });
  29. mainWindow.loadURL('http://localhost:8081');
  30. // 隐藏菜单栏
  31. mainWindow.setMenuBarVisibility(false);
  32. // Open the DevTools.
  33. mainWindow.webContents.openDevTools()
  34. }
  35. // This method will be called when Electron has finished
  36. // initialization and is ready to create browser windows.
  37. // Some APIs can only be used after this event occurs.
  38. app.whenReady().then(() => {
  39. createWindow()
  40. protocol.interceptFileProtocol('file', (request, callback) => {
  41. const reqUrl = request.url.replace(/file:[/\\]*/, '');
  42. //
  43. let url = reqUrl;
  44. const urls = reqUrl.split(/\/static\//);
  45. if (urls.length > 1) {
  46. url = path.resolve(__dirname, 'dist/static', urls.slice(1).join('/static/'));
  47. }
  48. // console.log('incomming url: ', reqUrl, ' resolved url:', url);
  49. callback({ path: url });
  50. })
  51. app.on('activate', function () {
  52. // On macOS it's common to re-create a window in the app when the
  53. // dock icon is clicked and there are no other windows open.
  54. if (BrowserWindow.getAllWindows().length === 0) createWindow()
  55. })
  56. })
  57. // Quit when all windows are closed, except on macOS. There, it's common
  58. // for applications and their menu bar to stay active until the user quits
  59. // explicitly with Cmd + Q.
  60. app.on('window-all-closed', function () {
  61. if (process.platform !== 'darwin') app.quit()
  62. })
  63. // In this file you can include the rest of your app's specific main process
  64. // code. You can also put them in separate files and require them here.
  65. // 监听必要的自定义事件
  66. /**
  67. * 项目中的文件上传
  68. */
  69. ipcMain.handle('project-upload-file', async (event, args) => {
  70. const res = await dialog.showOpenDialog({
  71. properties: ['openFile'],
  72. });
  73. return res;
  74. // dialog.showOpenDialog({
  75. // properties: ['openFile'],
  76. // }).then((files) => {
  77. // if(files){
  78. // event.sender.send('project-selected-upload-file', files);
  79. // }
  80. // })
  81. });