Fix background & search-results

This commit is contained in:
Rob Garrison 2018-11-15 16:28:26 -06:00
parent cac86daa78
commit 3d3a2b802a
2 changed files with 18 additions and 3 deletions

View File

@ -156,7 +156,8 @@
} }
// USO can't handle POST requests for style json // USO can't handle POST requests for style json
return download(style.updateUrl, {body: null}) return download(style.updateUrl, {body: null})
.then(text => tryJSONparse(text)); // USO may not provide a correctly updated originalMd5 (#555)
.then(text => Object.assign(tryJSONparse(text), {originalMd5: md5}));
}); });
} }

View File

@ -510,7 +510,6 @@ window.addEventListener('showStyles:done', function _() {
const installButton = $('.search-result-install', entry); const installButton = $('.search-result-install', entry);
installButton.onclick = onInstallClicked; installButton.onclick = onInstallClicked;
if ((result.style_settings || []).length > 0) { if ((result.style_settings || []).length > 0) {
// Style has customizations // Style has customizations
installButton.classList.add('customize'); installButton.classList.add('customize');
@ -552,11 +551,13 @@ window.addEventListener('showStyles:done', function _() {
Promise.all([ Promise.all([
fetchStyleJson(result), fetchStyleJson(result),
fetchStyleSettings(result), fetchStyleSettings(result),
fetchMd5(result)
]) ])
.then(([style, settings]) => { .then(([style, settings, md5]) => {
pingback(result); pingback(result);
// show a 'config-on-homepage' icon in the popup // show a 'config-on-homepage' icon in the popup
style.updateUrl += settings.length ? '?' : ''; style.updateUrl += settings.length ? '?' : '';
style.originalMd5 = md5;
return API.installStyle(style); return API.installStyle(style);
}) })
.catch(reason => { .catch(reason => {
@ -578,6 +579,19 @@ window.addEventListener('showStyles:done', function _() {
return result.style_settings; return result.style_settings;
}); });
} }
function fetchMd5(result) {
return API.download({
url: UPDATE_URL.replace('%', result.id),
timeout: 60e3,
// USO can't handle POST requests for style json
body: null,
})
.catch(error => {
alert('Error' + (error ? '\n' + error : ''));
throw error;
});
}
} }
function pingback(result) { function pingback(result) {