Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Modules to control application life and create native browser window
  2. const { app, BrowserWindow, protocol } = 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: 800,
  10. height: 600,
  11. webPreferences: {
  12. // preload: path.join(__dirname, 'preload.js')
  13. }
  14. })
  15. // const startUrl = url.format({
  16. // pathname: path.join(__dirname, './dist/index.html'),
  17. // protocol: 'file:',
  18. // slashes: true
  19. // });
  20. // console.log('startUrl:', startUrl)
  21. // and load the index.html of the app.
  22. mainWindow.loadFile('./dist/index.html')
  23. // Open the DevTools.
  24. mainWindow.webContents.openDevTools()
  25. }
  26. // This method will be called when Electron has finished
  27. // initialization and is ready to create browser windows.
  28. // Some APIs can only be used after this event occurs.
  29. app.whenReady().then(() => {
  30. createWindow()
  31. protocol.interceptFileProtocol('file', (request, callback) => {
  32. const reqUrl = request.url.replace(/file:[/\\]*/, '');
  33. //
  34. let url = reqUrl;
  35. const urls = reqUrl.split(/\/static\//);
  36. if (urls.length > 1) {
  37. url = path.resolve(__dirname, 'dist/static', urls.slice(1).join('/static/'));
  38. }
  39. // console.log('incomming url: ', reqUrl, ' resolved url:', url);
  40. callback({ path: url });
  41. })
  42. app.on('activate', function () {
  43. // On macOS it's common to re-create a window in the app when the
  44. // dock icon is clicked and there are no other windows open.
  45. if (BrowserWindow.getAllWindows().length === 0) createWindow()
  46. })
  47. })
  48. // Quit when all windows are closed, except on macOS. There, it's common
  49. // for applications and their menu bar to stay active until the user quits
  50. // explicitly with Cmd + Q.
  51. app.on('window-all-closed', function () {
  52. if (process.platform !== 'darwin') app.quit()
  53. })
  54. // In this file you can include the rest of your app's specific main process
  55. // code. You can also put them in separate files and require them here.