await notify before process.exit, #69

This commit is contained in:
Ralf Vogler 2023-02-24 00:08:35 +01:00
parent 114631da4d
commit 73a7cffd47
4 changed files with 9 additions and 8 deletions

View file

@ -84,7 +84,7 @@ try {
}).catch(_ => { });
} else {
console.log('Waiting for you to login in the browser.');
notify('epic-games: no longer signed in and not enough options set for automatic login.');
await notify('epic-games: no longer signed in and not enough options set for automatic login.');
if (cfg.headless) {
console.log('Run `SHOW=1 node epic-games` to login in the opened browser.');
await context.close(); // finishes potential recording

2
gog.js
View file

@ -72,7 +72,7 @@ try {
await page.waitForSelector('#menuUsername')
} else {
console.log('Waiting for you to login in the browser.');
notify('gog: no longer signed in and not enough options set for automatic login.');
await notify('gog: no longer signed in and not enough options set for automatic login.');
if (cfg.headless) {
console.log('Run `SHOW=1 node gog` to login in the opened browser.');
await context.close();

View file

@ -54,7 +54,7 @@ try {
const error = await page.locator('.a-alert-content').first().innerText();
if (!error.trim.length) return;
console.error('Login error:', error);
notify(`prime-gaming: login: ${error}`);
await notify(`prime-gaming: login: ${error}`);
await context.close(); // finishes potential recording
process.exit(1);
});
@ -68,7 +68,7 @@ try {
}).catch(_ => { });
} else {
console.log('Waiting for you to login in the browser.');
notify('prime-gaming: no longer signed in and not enough options set for automatic login.');
await notify('prime-gaming: no longer signed in and not enough options set for automatic login.');
if (cfg.headless) {
console.log('Run `SHOW=1 node prime-gaming` to login in the opened browser.');
await context.close(); // finishes potential recording

View file

@ -99,8 +99,8 @@ export const prompt = o => enquirer.prompt({name: 'name', type: 'input', message
import { exec } from 'child_process';
import { cfg } from './config.js';
export const notify = (html) => {
if (!cfg.notify) return;
export const notify = (html) => new Promise((resolve, reject) => {
if (!cfg.notify) return resolve();
const title = cfg.notify_title ? `-t ${cfg.notify_title}` : '';
exec(`apprise ${cfg.notify} -i html ${title} -b '${html}'`, (error, stdout, stderr) => {
if (error) {
@ -108,12 +108,13 @@ export const notify = (html) => {
if (error.message.includes('command not found')) {
console.info('Run `pip install apprise`. See https://github.com/vogler/free-games-claimer#notifications');
}
return;
return resolve();
}
if (stderr) console.error(`stderr: ${stderr}`);
if (stdout) console.log(`stdout: ${stdout}`);
resolve();
});
}
});
export const escapeHtml = (unsafe) => unsafe.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#039;');