ngx-rocket / generator-ngx-rocket

:rocket: Extensible Angular 14+ enterprise-grade project generator
https://ngx-rocket.github.io/
MIT License
1.53k stars 217 forks source link

Electron app run shows raw index.html file not running app #517

Closed timoplus closed 4 years ago

timoplus commented 4 years ago

I'm submitting Bug report

Current behavior

Using npm start runs the app in the browser.

npm run electron:build  Build desktop app
npm run electron:run    Run app on electron

The app loads in the Electron shell but displays the contents of the index.html file instead of the running app.

Expected behavior

App runs in the Electron window instead of showing the source.

Minimal reproduction of the problem with instructions

https://github.com/timoplus/web-electron-rocket

(This repo includes the answers to the creation questions in the readme.)

Environment

Windows 10.

timoplus commented 4 years ago

I've noticed that if you choose View/Reload then the app runs correctly. Once running 'npm run electron:run' actually served the app in it's functional state, but all other times it displays the index.html file instead of running the app.

An observant dev might notice this in the electron.main.ts:

const liveReload = process.argv.slice(2).some(arg => arg === '--serve');
...
if (liveReload) {
    require('electron-reload')(__dirname, { electron: require(`${__dirname}/node_modules/electron`) });
    mainWindow.loadURL('http://localhost:4200');
    mainWindow.webContents.openDevTools();
  } else {
    // Load the index.html of the app.
    mainWindow.loadFile('dist.electron/index.html');
  }

So this behavior is by design. If you run the app with two flags like this then the app is run.

npm run electron:run -- --serve
timoplus commented 4 years ago

This might still be an issue. Running the app with the -- --serve flags causes a blank screen. Running without the flags, as noted above, prints out the index.html, but refreshing the view runs the app. However, I want to have a full screen app with no menu bar. When I have the solution to this issue I will report back here.

timoplus commented 4 years ago

This is partially a duplicate of #507. In that issue, it is noted that after doing an npm run build and npm run electron:run typing cmd-r refreshes the page and runs the app.