Non-functional box art caching

- appears to cache fine in memory
- does NOT want to serialize to chrome.storage.local
- promises are confusing
This commit is contained in:
R. Aidan Campbell 2016-07-09 21:24:19 -04:00
parent 88795bc126
commit e3d000e8ed
2 changed files with 46 additions and 7 deletions

View File

@ -22,6 +22,7 @@
},
"permissions": [
"storage",
"unlimitedStorage",
"pointerLock",
"system.network",
"fullscreen",

View File

@ -41,6 +41,7 @@ function NvHTTP(address, clientUid) {
this._baseUrlHttps = 'https://' + address + ':47984';
this._baseUrlHttp = 'http://' + address + ':47989';
this._appListCache = null;
this._memCachedBoxArtArray = {};
_self = this;
};
@ -142,6 +143,42 @@ NvHTTP.prototype = {
},
getBoxArt: function (appId) {
if (chrome.storage) {
// This may be bad practice to push/pull this much data through local storage?
return new Promise(function (resolve, reject) {
chrome.storage.local.get('boxArtCache', function(JSONCachedBoxArtArray) {
var cachedBoxArtArray = JSONCachedBoxArtArray.boxArtArray != undefined ? JSON.parse(JSONCachedBoxArtArray.boxArtArray) : Object
var boxArtArray = cachedBoxArtArray.boxArtArray != null ? cachedBoxArtArray.boxArtArray : _self._memCachedBoxArtArray; // yay associative arrays!
// if we already have it, load from cache
if (boxArtArray[appId] != null) {
resolve(boxArtArray[appId]);
}
// otherwise, put it in our cache, then return it
sendMessage('openUrl', [
_self._baseUrlHttps +
'/appasset?'+_self._buildUidStr() +
'&appid=' + appId +
'&AssetType=2&AssetIdx=0',
true
]).then(function(streamedBoxArt) {
// something's going wrong here. the stringified box art renders as "{}"
boxArtArray[appId] = streamedBoxArt;
var obj = {};
obj['boxArtCache'] = JSON.stringify(boxArtArray); // storage is in JSON format. JSON does not support binary data.
chrome.storage.local.set(obj, function(onSuccess) {});
resolve(streamedBoxArt);
});
});
});
} else { // shouldn't run because we always have chrome.storage, but I'm not going to antagonize other browsers
return sendMessage('openUrl', [
_self._baseUrlHttps +
'/appasset?'+_self._buildUidStr() +
@ -149,6 +186,7 @@ NvHTTP.prototype = {
'&AssetType=2&AssetIdx=0',
true
]);
}
},
launchApp: function (appId, mode, sops, rikey, rikeyid, localAudio, surroundAudioInfo) {