Amir Zare
Amir Zare

Reputation: 41

How to prevent electron app from closing by task manager

I want to create an application that can't be closed by task manager. I do prevent application closing from taskbar, minimize the window and put it in tray but couldn't handle task manager closing. I'm wondering if anyone could help me.

Here's the snippet:

mainWindow.on('close', (event) => {
    if (!canClose) {
        event.preventDefault();
        mainWindow.minimize();
        mainWindow.setSkipTaskbar(true);
    } else {
        if (appIcon) appIcon.destroy();
        app.quit();
    }
});

canClose => let, appIcon => Tray

Upvotes: 1

Views: 1524

Answers (1)

tpikachu
tpikachu

Reputation: 4854

app.on('before-quit', event => {
  event.preventDefault();
})

before-quit event will be triggered just before quit event.

Prevent this event manually then quit event won't be triggered.

Upvotes: 1

Related Questions