Gracefully shut down database operations before app exit
This commit is contained in:
parent
2822f4ce40
commit
6300256a3e
5 changed files with 161 additions and 11 deletions
24
preload.js
24
preload.js
|
@ -151,6 +151,25 @@ ipc.on('delete-all-data', () => {
|
|||
}
|
||||
});
|
||||
|
||||
ipc.on('get-ready-for-shutdown', async () => {
|
||||
const { shutdown } = window.Events;
|
||||
if (!shutdown) {
|
||||
window.log.error('preload shutdown handler: shutdown method not found');
|
||||
ipc.send('now-ready-for-shutdown');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await shutdown();
|
||||
ipc.send('now-ready-for-shutdown');
|
||||
} catch (error) {
|
||||
ipc.send(
|
||||
'now-ready-for-shutdown',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
function installGetter(name, functionName) {
|
||||
ipc.on(`get-${name}`, async () => {
|
||||
const getFn = window.Events[functionName];
|
||||
|
@ -159,7 +178,10 @@ function installGetter(name, functionName) {
|
|||
try {
|
||||
ipc.send(`get-success-${name}`, null, await getFn());
|
||||
} catch (error) {
|
||||
ipc.send(`get-success-${name}`, error);
|
||||
ipc.send(
|
||||
`get-success-${name}`,
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue