#The app wont close with my custom button.
30 messages · Page 1 of 1 (latest)
can you share documentation or a link that can help me?
i have this now , a preload file
contextBridge.exposeInMainWorld("api", {
close: () => ipcRenderer.send("close-app"),
getCurrentLoad: () => currentLoad()
});```
in my main.js
const path = require('path');
require("electron-reload")(__dirname)
let win;
const createWindow = () => {
const mainWindow = new BrowserWindow({
width: 569,
height: 240,
maxHeight: 240, minHeight: 240,
minWidth:320, minHeight: 320,
frame: false,
autoHideMenuBar: true,
webPreferences: {
preload:__dirname + "\\preload.js",
nodeIntegration: true
},
transparent: true,
alwaysOnTop: true,
});
ipcMain.on("close-app", () => app.quit());
mainWindow.loadFile(path.join(__dirname, 'index.html'));
};
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});```
in my style.css
padding: 5px;
font-size: .8em;
color: grey;
-webkit-app-region: no-drag;
}
#close:hover {
color: #8ce796;
}```
and i have this in my index.html
<p id="close">✖</p>
still wont work
Okay, it looks better
the path to your preload is wrong
Here is the docs for IPC : https://www.electronjs.org/docs/latest/tutorial/ipc
Use the ipcMain and ipcRenderer modules to communicate between Electron processes
You preload path should be something like this:
preload: path.join(__dirname, 'preload.js')
Thank you ser!
If you care about security, set nodeIntegration to false
https://www.electronjs.org/docs/latest/tutorial/security
and in your preload, I can't see the function currentLoad, so you will get an error on this
checking on the documentation now, thanks a lot ser madam!
@outer palm thanks my issue with close button solved!
Kudo to you for reading the docs. Far too many people don't.