Skip to content

Commit

Permalink
fix: browserAction.setIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Nov 22, 2022
1 parent 6dc3488 commit 4e17043
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
3 changes: 3 additions & 0 deletions add-on/manifest.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"page": "dist/options/options.html"
},
"web_accessible_resources": [
"icons/png/ipfs-logo-off_19.png",
"icons/png/ipfs-logo-off_38.png",
"icons/png/ipfs-logo-off_128.png",
"icons/ipfs-logo-on.svg",
"icons/ipfs-logo-off.svg"
],
Expand Down
31 changes: 3 additions & 28 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,33 +504,8 @@ export default async function init () {
return ('#' + r + g + b).toUpperCase()
}

/* Alternative: raster images generated on the fly
const rasterIconDefinition = pMemoize((svgPath) => {
const rasterData = (size) => {
const icon = new Image()
icon.src = svgPath
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
context.clearRect(0, 0, size, size)
context.drawImage(icon, 0, 0, size, size)
return context.getImageData(0, 0, size, size)
}
// icon sizes to cover ranges from:
// - https://bugs.chromium.org/p/chromium/issues/detail?id=647182
// - https://developer.chrome.com/extensions/manifest/icons
const r19 = rasterData(19)
const r38 = rasterData(38)
const r128 = rasterData(128)
// return computed values to be cached by p-memoize
return { imageData: { 19: r19, 38: r38, 128: r128 } }
})
*/

async function setBrowserActionIcon (iconPath) {
return browser.browserAction.setIcon(rasterIconDefinition(iconPath))
/* Below fallback does not work since Chromium 80
* (it fails in a way that does not produce error we can catch)
const iconDefinition = { path: iconPath }
let iconDefinition = { path: iconPath }
try {
// Try SVG first -- Firefox supports it natively
await browser.browserAction.setIcon(iconDefinition)
Expand All @@ -539,9 +514,9 @@ export default async function init () {
// Chromium does not support SVG [ticket below is 8 years old, I can't even..]
// https://bugs.chromium.org/p/chromium/issues/detail?id=29683
// Still, we want icon, so we precompute rasters of popular sizes and use them instead
await browser.browserAction.setIcon(rasterIconDefinition(iconPath))
iconDefinition = await rasterIconDefinition(iconPath)
await browser.browserAction.setIcon(iconDefinition)
}
*/
}

// OPTIONS
Expand Down
64 changes: 43 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"multiaddr-to-uri": "8.0.0",
"node-fetch": "2.6.7",
"os-browserify": "0.3.0",
"p-memoize": "4.0.2",
"p-memoize": "7.1.1",
"p-queue": "7.2.0",
"p-wait-for": "4.1.0",
"path-browserify": "1.0.1",
Expand Down

0 comments on commit 4e17043

Please sign in to comment.