diff --git a/epic-games.js b/epic-games.js
index e4f5293..db37414 100644
--- a/epic-games.js
+++ b/epic-games.js
@@ -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:
${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();
diff --git a/gog.js b/gog.js
index fade890..a496130 100644
--- a/gog.js
+++ b/gog.js
@@ -10,6 +10,12 @@ console.log(datetime(), 'started checking gog');
const db = await jsonDb('gog.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://playwright.dev/docs/auth#multi-factor-authentication
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless,
@@ -132,11 +138,11 @@ try {
} catch (error) {
console.error(error); // .toString()?
process.exitCode = 1;
- if (error.message && !error.message.includes('Target closed') && !error.message.includes('Browser closed')) // e.g. when killed by Ctrl-C
+ if (error.message && !exit)
notify(`gog 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(`gog:
${html_game_list(notify_games)}`);
}
}
diff --git a/prime-gaming.js b/prime-gaming.js
index 8988557..6300f41 100644
--- a/prime-gaming.js
+++ b/prime-gaming.js
@@ -12,6 +12,12 @@ console.log(datetime(), 'started checking prime-gaming');
const db = await jsonDb('prime-gaming.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://playwright.dev/docs/auth#multi-factor-authentication
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless,
@@ -165,7 +171,7 @@ 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(`prime-gaming failed: ${error.message.split('\n')[0]}`);
} finally {
await db.write(); // write out json db