Código:
índice.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"> <link rel="stylesheet" type="text/css" href="index.css"> <title>Youtify</title> </head> <body> <div id = "leftBar"></div> <div id = "rightBar"></div> <div id = "bottomBar"><hr></div> <div id = "toolButtons"> <div id ="closeBtn"><a data-text="✖"></a></div> <div id="maxBtn"><a data-text="❐" ></a></div> <div id="minBtn"><a data-text="─" ></a></div> </div> <script src="./renderer.js"></script> </body> </html>principal.js
const {app, BrowserWindow, ipcMain} = require('electron') const path = require('path') function createWindow () { const mainWindow = new BrowserWindow({ width: 800, height: 600, frame: false, }) mainWindow.loadFile('index.html') } app.whenReady().then(() => { createWindow() app.on('activate', function () { if (BrowserWindow.getAllWindows().length === 0) createWindow() }) })renderizador.js
// close app function closeApp(e) { e.preventDefault(); app.quit(); } document.getElementById("closeBtn").addEventListener("click", closeApp);Lo que quiero es hacer clic en el botón con la identificación "closeBtn" para cerrar la aplicación, la estaba buscando, pero simplemente no puedo hacer que funcione. Alguien puede ayudarme porfavor?
Intente usar ipcRenderer para enviar el comando de cierre a main.js
En su main.js:
ipcMain.on('close', () => { app.quit() })Luego, en tu renderer.js:
const ipc = require('electron').ipcRenderer // close app function closeApp(e) { e.preventDefault() ipc.send('close') } document.getElementById("closeBtn").addEventListener("click", closeApp);