Handle Steam achievement status check failure by logging them

This commit is contained in:
Heikki Aitakangas 2022-01-12 20:57:45 +02:00
parent 521889b027
commit c7c303c551

@ -10,7 +10,7 @@ async function enableAchievementsInterval(window) {
// here. Hey if it works it works. // here. Hey if it works it works.
const steamAchievements = greenworks.getAchievementNames(); const steamAchievements = greenworks.getAchievementNames();
log.info(`All Steam achievements ${JSON.stringify(steamAchievements)}`); log.info(`All Steam achievements ${JSON.stringify(steamAchievements)}`);
const playerAchieved = (await Promise.all(steamAchievements.map(name => new Promise((resolve, reject) => { greenworks.getAchievement(name, (playerHas) => resolve(playerHas ? name : ""), reject); })))).filter(name => !!name); const playerAchieved = (await Promise.all(steamAchievements.map(checkSteamAchievement))).filter(name => !!name);
log.info(`Player has Steam achievements ${JSON.stringify(playerAchieved)}`); log.info(`Player has Steam achievements ${JSON.stringify(playerAchieved)}`);
const intervalID = setInterval(async () => { const intervalID = setInterval(async () => {
try { try {
@ -34,6 +34,15 @@ async function enableAchievementsInterval(window) {
window.achievementsIntervalID = intervalID; window.achievementsIntervalID = intervalID;
} }
function checkSteamAchievement(name) {
return new Promise((resolve) => {
greenworks.getAchievement(name, playerHas => resolve(playerHas ? name : ""), err => {
log.warn(`Failed to get Steam achievement ${name} status: ${err}`);
resolve("");
});
});
}
function disableAchievementsInterval(window) { function disableAchievementsInterval(window) {
if (window.achievementsIntervalID) { if (window.achievementsIntervalID) {
clearInterval(window.achievementsIntervalID); clearInterval(window.achievementsIntervalID);