diff --git a/epic-games.js b/epic-games.js index 812af6b..a0a15dd 100644 --- a/epic-games.js +++ b/epic-games.js @@ -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 diff --git a/gog.js b/gog.js index 4128e89..8fff1ce 100644 --- a/gog.js +++ b/gog.js @@ -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(); diff --git a/prime-gaming.js b/prime-gaming.js index c39901f..0ef98c8 100644 --- a/prime-gaming.js +++ b/prime-gaming.js @@ -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 diff --git a/util.js b/util.js index a1d6d40..08b55d1 100644 --- a/util.js +++ b/util.js @@ -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('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');