Running the "First Electron App" wont show versions?
If you activate the Developer Tools, you should see error messages in the Console like such:
Uncaught ReferenceError: process is not defined
at index.html:11
You need to activate nodeIntegration
and deactivate contextIsolation
of the BrowserWindow, so that the process running in the BrowserWindow ("renderer process") is allowed to access Node's process
object.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
(Before Electron 12, only the nodeIntegration
key was needed, and the default value of contextIsolation
was false
.)
This is your file with correction
const {app, BrowserWindow} = require('electron')
const path = require('path')
let mainWindow
function createWindow () {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
// I think you don't need this line
// preload: path.join(__dirname, 'preload.js')
nodeIntegration: true
}
})
mainWindow.loadFile('index.html')
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
if (mainWindow === null) createWindow()
})