Skip to content

Commit

Permalink
download() may throw
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Dec 17, 2024
1 parent fb207da commit 5fb9aaf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/background/update-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as prefs from '/js/prefs';
import {calcStyleDigest, styleSectionsEqual} from '/js/sections-util';
import {chromeLocal} from '/js/storage-util';
import {extractUsoaId, isCdnUrl, isLocalhost, usoApi} from '/js/urls';
import {debounce, deepMerge, getHost, resolvedPromise, sleep} from '/js/util';
import {debounce, deepMerge, getHost, sleep} from '/js/util';
import {ignoreChromeError} from '/js/util-webext';
import {bgBusy} from './common';
import {db} from './db';
Expand All @@ -27,6 +27,7 @@ const STATES = /** @namespace UpdaterStates */ {
ERROR_VERSION: 'error: version is older than installed style',
};
export const getStates = () => STATES;
const NOP = () => {};
const safeSleep = __.MV3 ? ms => __.KEEP_ALIVE(sleep(ms)) : sleep;
const RH_ETAG = {responseHeaders: ['etag']}; // a hashsum of file contents
const RX_DATE2VER = new RegExp([
Expand Down Expand Up @@ -238,8 +239,8 @@ async function tryDownload(url, params, {retryDelay = HOST_THROTTLE} = {}) {
host = getHost(url);
job = hostJobs[host];
job = hostJobs[host] = (job
? job.then(() => safeSleep(HOST_THROTTLE / (isCdnUrl(url) ? 4 : 1)))
: resolvedPromise()
? job.catch(NOP).then(() => safeSleep(HOST_THROTTLE / (isCdnUrl(url) ? 4 : 1)))
: Promise.resolve()
).then(() => download(url, params));
return await job;
} catch (code) {
Expand Down
1 change: 0 additions & 1 deletion src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const hasOwn = /*@__PURE__*/Object.call.bind({}.hasOwnProperty);
/** FYI, matchMedia's onchange doesn't work in bg context, so we use it in our content script */
export const isCssDarkScheme = () => matchMedia('(prefers-color-scheme:dark)').matches;
export const isObject = val => typeof val === 'object' && val;
export const resolvedPromise = async val => val;
export const sleep = ms => new Promise(ms > 0 ? cb => setTimeout(cb, ms) : setTimeout);
export const stringAsRegExpStr = s => s.replace(/[{}()[\]\\.+*?^$|]/g, '\\$&');
export const stringAsRegExp = (s, flags) => new RegExp(stringAsRegExpStr(s), flags);
Expand Down

0 comments on commit 5fb9aaf

Please sign in to comment.