Skip to content

Commit

Permalink
docs: Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gergof committed Sep 6, 2022
1 parent 672f687 commit 3cd964e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,27 @@ app.whenReady().then(() => {
win.loadFile('index.html');

ElectronShutdownHandler.setWindowHandle(win.getNativeWindowHandle());
ElectronShutdownHandler.blockShutdown('Please wait for some data to be saved');

Electron.ShutdownHandler.on('shutdown', () => {
console.log('Shutting down!')
console.log('Shutting down!');
ElectronShutdownHandler.releaseShutdown();
win.webContents.send('shutdown');
app.quit();
});
});
```

#### Usage

First of all you need to create an electron window, after which you can call the `setWindowHandle` method. Calling this method is required, otherwise the rest of the functions will throw. This function will store the HWND of the window in the addon and will set that the window will be the first process to shut down (otherwise the renderer process might exit first which results in the crash of electron).

To block the shutdown you need to call the `blockShutdown` function before a shutdown event occures, but you also need to set up an event listener, otherwise the hook won't be added to the window message callback.

You should also call app.quit() in the shutdown handler.

Please note that this addon is singleton, you can only use it for one window at the moment, so you should always set the main window's handle.

## API

#### Functions
Expand Down

0 comments on commit 3cd964e

Please sign in to comment.