javascriptnode.jsmacosoperating-systemelectron

How to prevent Electron app from interrupting macOS system shutdown?


I have an Electron based app that runs in the macOS menu bar/the Windows tray area.

On Windows a system shutdown exits the app, but on macOS a system shutdown is interrupted due to the app not closing. How can I detect a shutdown event and close the app when the user has not explicitly requested the app to close?


Solution

  • Simple solution:

    import { app, powerMonitor } from 'electron';
    
    powerMonitor.on('shutdown', () => {
      app.quit();
    });