#The app wont close with my custom button.

30 messages · Page 1 of 1 (latest)

worn spindle
#

I created a timer app that is transparent hiding the menubar, then i created a custom button to close the app.

Right in my main.js i but this ipcMain.on("customCloseButton", () => app.quit()); but i cant make it work :(. Can someone help me get a hint to make it work?

worn spindle
outer palm
#

remote is deprecated

#

use IPC and a preload file

worn spindle
#

can you share documentation or a link that can help me?

worn spindle
#

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">&#10006;</p>

#

still wont work

outer palm
#

Okay, it looks better

#

the path to your preload is wrong

#

You preload path should be something like this:

preload: path.join(__dirname, 'preload.js')
outer palm
#

and in your preload, I can't see the function currentLoad, so you will get an error on this

worn spindle
worn spindle
#

@outer palm thanks my issue with close button solved!

outer palm
#

Kudo to you for reading the docs. Far too many people don't.

vernal carbon
#

how to fix it

#

@worn spindle

worn spindle
#

im a neophytes on this field mate and you sharing screenshot in turkish 😄

#

basically when i converted your screenshot with OCR and a translator, it basically says, you are trying to run a 32 bit in a 64 bit process cant be able to access the modules.