Skip to content

Commit

Permalink
Fix the extension icons for Chrome MV3 (#1189)
Browse files Browse the repository at this point in the history
There are some differences with extension icons for Chrome MV3:
 - The API was renamed from browserAction.setIcon to action.setIcon.
 - Relative paths are handled differently.
 - SVG icons are not supported.

Workaround those differences by expanding the setBadgeIcon wrapper,
using absolute icon paths and using PNG icons.
  • Loading branch information
kzar committed May 20, 2022
1 parent 6303b43 commit 46914dd
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 11 deletions.
Binary file added shared/img/toolbar-rating-a_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shared/img/toolbar-rating-b-plus_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shared/img/toolbar-rating-b_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shared/img/toolbar-rating-c-plus_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shared/img/toolbar-rating-c_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shared/img/toolbar-rating-d-minus_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shared/img/toolbar-rating-d_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added shared/img/toolbar-rating-f_48.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions shared/js/background/classes/tab.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* }
*/
const gradeIconLocations = {
A: 'img/toolbar-rating-a.svg',
'B+': 'img/toolbar-rating-b-plus.svg',
B: 'img/toolbar-rating-b.svg',
'C+': 'img/toolbar-rating-c-plus.svg',
C: 'img/toolbar-rating-c.svg',
D: 'img/toolbar-rating-d.svg',
A: '/img/toolbar-rating-a_48.png',
'B+': '/img/toolbar-rating-b-plus_48.png',
B: '/img/toolbar-rating-b_48.png',
'C+': '/img/toolbar-rating-c-plus_48.png',
C: '/img/toolbar-rating-c_48.png',
D: '/img/toolbar-rating-d_48.png',
// we don't currently show the D- grade
'D-': 'img/toolbar-rating-d.svg',
F: 'img/toolbar-rating-f.svg'
'D-': '/img/toolbar-rating-d_48.png',
F: '/img/toolbar-rating-f_48.png'
}

const Site = require('./site.es6')
Expand Down Expand Up @@ -63,7 +63,7 @@ class Tab {

resetBadgeIcon () {
// set the new tab icon to the dax logo
browserWrapper.setBadgeIcon({ path: 'img/icon_48.png', tabId: this.id })
browserWrapper.setBadgeIcon({ path: '/img/icon_48.png', tabId: this.id })
}

updateBadgeIcon (target) {
Expand Down
8 changes: 6 additions & 2 deletions shared/js/background/wrapper.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ export function getExtensionVersion () {
return manifest.version
}

export function setBadgeIcon (badgeData) {
browser.browserAction.setIcon(badgeData)
export async function setBadgeIcon (badgeData) {
if (typeof browser.action === 'undefined') {
return await browser.browserAction.setIcon(badgeData)
}

return await browser.action.setIcon(badgeData)
}

export function syncToStorage (data) {
Expand Down

0 comments on commit 46914dd

Please sign in to comment.