Git Product home page Git Product logo

Comments (5)

subatomicglue avatar subatomicglue commented on May 20, 2024 3

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.

catdad avatar catdad commented on May 20, 2024 1

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.

subatomicglue avatar subatomicglue commented on May 20, 2024

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.

subatomicglue avatar subatomicglue commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.