0

In my main.js app.on("ready"), I call a function called runTimer() which contains the following:

const runTimer = function(){
    const { net } = require('electron')
    setInterval(async function () {
        if (seconds == 0) {
            const request = await net.request("https://localhost:6001/api/traintimes");
            request.on("response", (response) => {
                if (response.statusCode === 200) {
                    response.on("data", (data) => {
                        mainWindow.webContents.send("render-update", data);
                        console.log(`Body: ${data}`);
                    });
                    response.on("end", () => {
                        console.log("No more data in response.");
                    });
                }
            });
            request.end()
            seconds = 5;
        }
        seconds--
        mainWindow.webContents.send("counting", seconds);

    },1000)
}

I am able to see the data in the console that I wish to send to the UI when I console log it in the following line:

console.log(`Body: data`);

so I expect the following line to send the same JSON data to the UI.

mainWindow.webContents.send("render-update", data);

However, I get a unit8Array result in the UI, and I am not sure why it just doesn't display the JSON result which is logged in the console in the line right after it.

IPC Renderer

ipcRenderer.on("fetched-train-update", (evt, data) => {
  console.log(data);
})

Basically, instead of getting JSON data logged in the UI console, I get unit8Array as shown below:

enter image description here

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
floormind
  • 1,868
  • 5
  • 31
  • 85

0 Answers0