0

Quero executar um arquivo JS junto com o Electron e retornar seu resultado dentro da parte de renderização do Electron

Codigo que quero mostrar dentro do Electron na parte de HTML:

const si = require('systeminformation');
si.cpu().then(data => console.log(data));

Como eu penso que pode ser:

const { app, BrowserWindow } = require('electron')

function createWindow () {
  // Cria uma janela de navegação.
  let win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

  // e carregar o index.html do aplicativo.
  win.loadFile('index.html')
}

function informationSystem(){
    const si = require('systeminformation');
    si.cpu().then(data => console.log(data));   

}

informationSystem()
app.whenReady().then(createWindow)

1 Resposta 1

0

É isso o que você quer fazer?

Arquivo dentro de main.js

const { app, BrowserWindow } = require('electron')

function createWindow () {
  // Cria uma janela de navegação.
  let win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })
  win.webContents.openDevTools()
  win.loadFile('index.html')
}

app.whenReady().then(createWindow)

Arquivo dentro de index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Hello</h1>
    <ul class="cpus"></ul>
    <script>
        const cpuInfos = require('os').cpus()
        const list = document.querySelector('ul.cpus')
        cpuInfos.map(cpu => {
            const element = document.createElement('li')
            element.innerHTML = `model: ${cpu.model}, speed: ${cpu.speed}`
            list.appendChild(element)
        })
    </script>
</body>
</html>

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .