SIGINT handler to not notify about error on Ctrl-C
This commit is contained in:
parent
c1cd2db721
commit
66694d65e5
3 changed files with 24 additions and 6 deletions
|
|
@ -13,6 +13,12 @@ console.log(datetime(), 'started checking epic-games');
|
|||
const db = await jsonDb('epic-games.json');
|
||||
db.data ||= {};
|
||||
|
||||
let exit = false;
|
||||
process.on('SIGINT', () => { // e.g. when killed by Ctrl-C
|
||||
console.log('\nInterrupted by SIGINT. Exit! Exception shows where the script was:\n');
|
||||
exit = true;
|
||||
});
|
||||
|
||||
// https://www.nopecha.com extension source from https://github.com/NopeCHA/NopeCHA/releases/tag/0.1.16
|
||||
// const ext = path.resolve('nopecha'); // used in Chromium, currently not needed in Firefox
|
||||
|
||||
|
|
@ -183,13 +189,13 @@ try {
|
|||
} catch (error) {
|
||||
console.error(error); // .toString()?
|
||||
process.exitCode = 1;
|
||||
if (error.message && !error.message.includes('Target closed')) // e.g. when killed by Ctrl-C
|
||||
if (error.message && !exit)
|
||||
notify(`epic-games failed: ${error.message.split('\n')[0]}`);
|
||||
} finally {
|
||||
await db.write(); // write out json db
|
||||
if (notify_games.filter(g => g.status != 'existed').length) { // don't notify if all were already claimed; TODO don't notify if killed?
|
||||
if (notify_games.filter(g => g.status != 'existed').length) { // don't notify if all were already claimed
|
||||
notify(`epic-games:<br>${html_game_list(notify_games)}`);
|
||||
}
|
||||
}
|
||||
writeFileSync(path.resolve(cfg.dir.browser, 'cookies.json'), JSON.stringify(await context.cookies()));
|
||||
if (cfg.debug) writeFileSync(path.resolve(cfg.dir.browser, 'cookies.json'), JSON.stringify(await context.cookies()));
|
||||
await context.close();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue