25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

87 lines
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://localhost:8081');
  29. // 隐藏菜单栏
  30. mainWindow.setMenuBarVisibility(false);
  31. // Open the DevTools.
  32. mainWindow.webContents.openDevTools()
  33. }
  34. // This method will be called when Electron has finished
  35. // initialization and is ready to create browser windows.
  36. // Some APIs can only be used after this event occurs.
  37. app.whenReady().then(() => {
  38. createWindow()
  39. protocol.interceptFileProtocol('file', (request, callback) => {
  40. const reqUrl = request.url.replace(/file:[/\\]*/, '');
  41. //
  42. let url = reqUrl;
  43. const urls = reqUrl.split(/\/static\//);
  44. if (urls.length > 1) {
  45. url = path.resolve(__dirname, 'dist/static', urls.slice(1).join('/static/'));
  46. }
  47. // console.log('incomming url: ', reqUrl, ' resolved url:', url);
  48. callback({ path: url });
  49. })
  50. app.on('activate', function () {
  51. // On macOS it's common to re-create a window in the app when the
  52. // dock icon is clicked and there are no other windows open.
  53. if (BrowserWindow.getAllWindows().length === 0) createWindow()
  54. })
  55. })
  56. // Quit when all windows are closed, except on macOS. There, it's common
  57. // for applications and their menu bar to stay active until the user quits
  58. // explicitly with Cmd + Q.
  59. app.on('window-all-closed', function () {
  60. if (process.platform !== 'darwin') app.quit()
  61. })
  62. // In this file you can include the rest of your app's specific main process
  63. // code. You can also put them in separate files and require them here.
  64. // 监听必要的自定义事件
  65. /**
  66. * 项目中的文件上传
  67. */
  68. ipcMain.handle('project-upload-file', async (event, args) => {
  69. const res = await dialog.showOpenDialog({
  70. properties: ['openFile'],
  71. });
  72. return res;
  73. // dialog.showOpenDialog({
  74. // properties: ['openFile'],
  75. // }).then((files) => {
  76. // if(files){
  77. // event.sender.send('project-selected-upload-file', files);
  78. // }
  79. // })
  80. });