Comments (5)
Found it!
if (serve) {
win.webContents.openDevTools();
require('electron-reload')(__dirname, {
electron: require(path.join(__dirname, '/../node_modules/electron' ))
});
win.loadURL('http://localhost:4200');
}
This was in my app/main.ts
from the project I copied this from (angular + electron example I found online).
So, in the end - my app WAS exiting, but then 2 were launching. One from electron-reload
and one from electronmon
.
Commenting out the electron-reload
fixes the issue with the extra app getting launched when saving app/main.ts
.
All is good now.
from electronmon.
I think there are two issues here:
First, when you use a compile-to-javascript language, the source code (in your case the typescript files) is not what is run by Electron. Electron can only run JavaScript files. ng
takes your source typescript and creates output JavaScript, which is then what Electron uses. When electronmon comes into play, it works the same way. It can only analyze code (that is, the JavaScript files output by your build), and makes the assumption that all the other files are "miscellaneous renderer files" that it just doesn't know how to analyze. Again, the only actual code that is run in your case is the output JavaScript files from the build. Typescript files cannot and are not run as code. You can ignore those (as well as sourcemaps) using the patterns
property you mentioned.
Second, multiple apps... since there are no repro steps provided, I can only take guesses here. Electronmon sends standard kill signals to kill the app when restarting it. However, like any other signal, Electron can overload it and choose not to exit. My guess is that is what might be happening, but again, I have no way of knowing if there is no way for me to easily and simply reproduce this problem.
from electronmon.
Well, I figured out that maybe I should add the --watch
to the tsc
command above
This regenerates .js
files when .ts
files change (In the case of app/main.ts
, it's the app/main.js
):
wait-on tcp:4200 && tsc --watch -p tsconfig.serve.json && npx electronmon . --serve
which tsc --watch
blocks, and electronmon
never runs...
so I run in 2 separate terminals as a test:
Terminal 1
wait-on tcp:4200 && tsc --watch -p tsconfig.serve.json
Terminal 2
npx electronmon . --serve
It runs... But when I change & save app/main.ts
I get another electron app running.
Change&Save it 3 times, I get 3 more apps....
Here's the output after I change & save app/main.ts
(must modify the app/main.ts
or the .js
wont generate and wont trigger the electronmon
watcher)
[electronmon] renderer file change: app/main.ts
[electronmon] renderer file change: app/main.js.map
[electronmon] main file change: app/main.js
...partial console.logs (not seeing any global console.log from main.ts)....
will quit
[electronmon] restarting app due to file change
...full console.logs (seeing all console logs from main.ts)....
Ideas how to prevent all the extra apps running?
from electronmon.
Ok, that helps, so the typescript side of things needs extra config. Cool. Thanks for the explanation, that all makes sense.
I've edited the package.json
so that npm start
triggers the right tsc --watch
and electronmon
watchers... cool...
"start": "set NODE_ENV=development && npm-run-all -p ng:serve electron:serve-tscwatch electron:serve-electron",
"ng:serve": "ng serve -c web -o",
"electron:serve-tscwatch": "tsc --watch -p tsconfig.serve.json",
"electron:serve-electron": "wait-on tcp:4200 && npx electronmon . --serve",
This gets the *.js
files in the main
process to regenerate, which gets electronmon
to relaunch, cool.
And added a pattern for electronmon
to ignore the .ts
files in the main
process:
"electronmon": {
"patterns": ["!app/*.ts"]
},
seems to remove the redundant app/main.ts
stuff from getting detected by electronmon
in addition to the .js
detections.
So, the remaining problem:
For the additional app getting launched, it seems to only happen when saving app/main.ts
which generates app/main.js
... If I save package.json
, then no additional apps are added.
from electronmon.
Related Issues (20)
- The only working reloader, thank you very much, you are a holy man! HOT 1
- please, add quiet mode HOT 1
- monitoring crashes if the app has an error while starting app and user clicks "OK" on error prompt HOT 5
- add a JavaScript API so that the module can be used from other script HOT 3
- update to the latest chalk HOT 1
- create splash image for the README
- crashes when npm updated package.json when installing dependencies HOT 2
- Debugging main and renderer documentation HOT 1
- build and publish through github actions
- Watchboy error after change of file HOT 3
- "path" argument must be of type string - `electronmon` fails to load app due to bug in `runtime-required` dependency HOT 1
- expose reload events via API for retaining SPA state HOT 1
- BrowserView doesn't get reloaded HOT 2
- Stop app flashing on Windows taskbar for soft reloads HOT 1
- Expose watchboy API as well HOT 1
- Electronmon not working in Node v18? HOT 5
- Support for custom electron fork
- Cannot find module '@/src/xxx' HOT 1
- Quit electronmon process while I am using electronmon in my start script in package.json
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electronmon.