(script, store, showDefault, target = script)
| 12 | * @param {object} [target] |
| 13 | */ |
| 14 | export async function loadScriptIcon(script, store, showDefault, target = script) { |
| 15 | let def; |
| 16 | let res = target[KEY]; |
| 17 | const { icon: customIcon, pathMap } = script.custom || {}; |
| 18 | const icon = customIcon || script.meta.icon; |
| 19 | const { cache = {}, isHiDPI } = store || {}; |
| 20 | const url = pathMap?.[icon] || icon || showDefault && ( |
| 21 | def = `${ICON_PREFIX}${isHiDPI && 128 || (script.config.removed ? 32 : 38)}.png` |
| 22 | ); |
| 23 | if (!url || url !== res) { |
| 24 | // exposing scripts with no icon for user's CustomCSS |
| 25 | target[KEY_DEFAULT] = def ? '' : null; |
| 26 | // creates an observable property so Vue will see the change after `await` |
| 27 | if (!(KEY in target)) { |
| 28 | target[KEY] = null; |
| 29 | } |
| 30 | if (url) { |
| 31 | target[KEY] = res = cache[url] |
| 32 | || isDataUri(url) && url |
| 33 | || isHiDPI && def // Using our big icon directly as its data URI is rendered slower |
| 34 | || (def || isValidHttpUrl(url)) |
| 35 | && (cache[url] = await sendCmdDirectly('GetImageData', url).catch(noop)); |
| 36 | } |
| 37 | } |
| 38 | return res; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Sets script's safeIcon property after the image is successfully loaded |
no test coverage detected