From a69b475244acf9ad8f78d9f6a54b1650daa86465 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 25 Jan 2017 09:09:30 -0800 Subject: [PATCH] Gracefully handle case where no box art can be fetched --- static/js/index.js | 13 +++++++++++++ static/js/utils.js | 17 ++++++++++++++--- static/res/no_app_image.png | Bin 0 -> 1622 bytes 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100755 static/res/no_app_image.png diff --git a/static/js/index.js b/static/js/index.js index d478925..642b837 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -425,6 +425,19 @@ function showApps(host) { console.log('Error! Failed to retrieve box art for app ID: ' + app.id + '. Returned value was: ' + failedPromise) console.log('failed host object: '); console.log(host.toString()); + + if ($('#game-' + app.id).length === 0) { + // double clicking the button will cause multiple box arts to appear. + // to mitigate this we ensure we don't add a duplicate. + // This isn't perfect: there's lots of RTTs before the logic prevents anything + $("#game-grid").append($("
", {html:$("", {src: "static/res/no_app_image.png", id: 'game-'+app.id, name: app.title }), class: 'box-art mdl-cell mdl-cell--3-col'}).append($("", {html: app.title, class:"game-title"}))); + $('#game-'+app.id).on('click', function () { + startGame(host, app.id); + }); + + // apply CSS stylization to indicate whether the app is active + stylizeBoxArt(host, app.id); + } }); }); }, function (failedAppList) { diff --git a/static/js/utils.js b/static/js/utils.js index 1fa07fa..f5c9f9d 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -338,7 +338,14 @@ NvHTTP.prototype = { // TODO: unfortunately we do N lookups from storage cache, each of them filling up the memory cache. // once the first round of calls are all made, each subsequent request hits this and returns from memory cache - if (this._memCachedBoxArtArray[appId] !== undefined) { + if (this._memCachedBoxArtArray[appId] === null) { + // This means a previous box art request failed, don't try again + return new Promise(function (resolve, reject) { + console.log('returning cached box art failure result'); + reject(null); + return; + }.bind(this)); + } else if (this._memCachedBoxArtArray[appId] !== undefined) { return new Promise(function (resolve, reject) { console.log('returning memory cached box art'); resolve(this._memCachedBoxArtArray[appId]); @@ -392,9 +399,13 @@ NvHTTP.prototype = { console.log('returning streamed box art'); resolve(streamedBoxArt); return; + }.bind(this), function(error) { + // Cache the failure but not persistently + this._memCachedBoxArtArray[appId] = null; + console.log('box art request failed'); + reject(error); + return; }.bind(this)); - - }.bind(this)); }.bind(this)); diff --git a/static/res/no_app_image.png b/static/res/no_app_image.png new file mode 100755 index 0000000000000000000000000000000000000000..4cbad3e0439718265ea3c96656475d0c83fd4a49 GIT binary patch literal 1622 zcma)7eKb^Q93Iz=>-!ePwxb;nth!;%kJrq-E+@--+Q0)d!FC>d*9!E?&&=q zbREt0ngjwthq24W8_Z$?K}8c$15f^X>wg53+97wk3qiSbUAbNQ13)yQcLl~02wM6} zLxqr=Zv;T~?-)#)`mlyEOwx$R9IPP_R>>GHpMR0iuNYKZ$lYa>)FXK~q>LMR;7UVt zJ!vr~BAL(lj&^y~UeEKJ7++~W^kEL@+-T%19@7ZvG2{_o2vWh5FpNY(Q3QcuXleWx z^jGA+qL!gM#(OLMwq&vvM)%y=VSUMcD)E!Jpf<0KM$(=;y#t_X)3;;E( zawqAyTdyt6&7xnhSTd=JPjsgoOwIBp>hkoIWJt=smIX8%FL%XH=D;mMomQf%`i`zm zsFRB%?!5P$bS)d7$ZF>=bTjHOVMj-q#P=254CSQlxY=%nZg^nJyg59soJ}sogb}5^ z7H5itX|-B-w1Y0sIV<#|HrZ{{fm@hhwV+Ue!soc}W|Z?d^|fg2NDa>feZTe|r|GO9%2*qZj%pgF z_uA@mv232y+l|y|UE=NLC8-7UTCgeQ<(~6#l~};TxS*`icj11Gt6J){ThaN&_gBY% zL6N2>uM^UX%nLdCSFzaxh0`2ue8MMq{Asr`>9PhE~YPvU}Rm@%kniqA1wS85~x6^YW@FgEe z+AfVwrFKP`8z7Pg&tpf9vcFHovMb6hz1_g_h4z`OKlo%1>r%KSzM{|aOwmLVj8o#N z8(4J%Ib1DnM4`h*bjZk#Pp*;qkvi!aMdp!Y10=SU;!^nBRR^bpeI~*Jx@QuBurdqF z?y`GBt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