csepulv / electron-with-create-react-app

Sample Electron application using create-react-app
MIT License
831 stars 217 forks source link

Logging? #4

Closed carbureted closed 7 years ago

carbureted commented 7 years ago

Hey, I'm fairly new with electron, so perhaps I'm missing something basic, but I noticed that console.log isn't working for anything on the electron-starter.js side of things. Is there an easy solution for this? The top stack overflow results weren't helpful, unfortunately.

csepulv commented 7 years ago

Unfortunately I don't know. I've never tried logging from the bootstrap script that loads the window.

What do you need to log that isn't loggable elsewhere?

sebassdc commented 7 years ago

i think its beacause the server is constantly realoading and re-renders everything im triying a simple ipc comunication and i dont know how to manually test it. How can i stop server and hot reloading?

csepulv commented 7 years ago

You probably need to eject your app, as the hot reloading it part of create-react-app.

pikiaboy commented 6 years ago

There is no logging from electron-starter.js because if you take a look at electron-wait-react.js, you can see that electron is actually being called from a child_process via exec. Because of this, the logging goes to a buffer that we have to provide in a callback. However, this gets really inefficient, as you'd have to close the electron app each time to check the logging.

The best way I've found to fix this issue would be to run electron from a child_process.spawn(). This way, we can bind the stdout of the child_process and log it right away.

`onst tryConnection = () => client.connect({port: port}, () => { client.end(); if(!startedElectron) { console.log('starting electron'); startedElectron = true;

        const { spawn } = require('child_process');
        const child = spawn('npm', ['run', 'electron']);
        child.stdout.on('data', (data) => {
            console.log(`child stdout: ${data}`);
          });

          child.stderr.on('data', (data) => {
            console.error(`child stderr: ${data}`);
          });
          child.on('exit', function (code, signal) {
            console.log('child process exited with ' +
                        `code ${code} and signal ${signal}`);
          });

        // const exec = require('child_process').exec;

        // exec('npm run electron',(error,stdout,stderr) => {
        //     console.log(stdout);
        // });
    }
}

);`