Index: chrome/ext/background.js |
=================================================================== |
--- a/chrome/ext/background.js |
+++ b/chrome/ext/background.js |
@@ -194,6 +194,8 @@ |
}); |
+ ext.iconSizes = [16, 19, 20, 32, 38, 40]; |
+ |
/* Browser actions */ |
var BrowserAction = function(tabId) |
@@ -202,18 +204,6 @@ |
this._changes = null; |
}; |
BrowserAction.prototype = { |
- _legacySetIcon: function(details) |
- { |
- var legacyDetails = {}; |
- for (var key in details) |
- { |
- var value = details[key]; |
- if (typeof value == "object") |
- value = {19: value[19], 38: value[38]}; |
- legacyDetails[key] = value; |
- } |
- chrome.browserAction.setIcon(legacyDetails); |
- }, |
_safeSetIcon: function(details) |
{ |
try |
@@ -222,29 +212,41 @@ |
} |
catch (e) |
{ |
- // Older versions of Chrome do not allow any sizes other than 19 and 38 |
- // to be present, but newer versions of Chrome (and Edge) prefer |
- // different sizes. |
- this._safeSetIcon = this._legacySetIcon; |
- this._legacySetIcon(details); |
Oleksandr
2016/12/05 05:29:59
In this case, the `this` pointer is refreshed for
kzar
2016/12/05 16:17:56
Well a BrowserAction is created for each page, so
|
+ // Try applying the icon the Edge way |
+ ext.iconSizes = [19, 20, 38, 40]; |
+ try |
+ { |
+ this.applyIcon(); |
+ } |
+ catch(e) |
+ { |
+ // Just stick to the bare minimum. Older versions of Chrome do not |
+ // allow any sizes other than 19 and 38 to be present |
+ ext.iconSizes = [19, 38]; |
+ applyIcon(); |
+ } |
} |
}, |
+ |
+ applyIcon: function() |
+ { |
+ var builtPath = {}; |
+ currentIconPath = this._changes.iconPath; |
+ ext.iconSizes.map(function(iconSize) |
+ { |
+ builtPath[iconSize] = currentIconPath.replace("$size", iconSize); |
+ }); |
+ |
+ this._safeSetIcon({ |
+ tabId: this._tabId, |
+ path: builtPath |
+ }); |
+ }, |
+ |
_applyChanges: function() |
{ |
if ("iconPath" in this._changes) |
- { |
- this._safeSetIcon({ |
- tabId: this._tabId, |
- path: { |
- 16: this._changes.iconPath.replace("$size", "16"), |
- 19: this._changes.iconPath.replace("$size", "19"), |
- 20: this._changes.iconPath.replace("$size", "20"), |
- 32: this._changes.iconPath.replace("$size", "32"), |
- 38: this._changes.iconPath.replace("$size", "38"), |
- 40: this._changes.iconPath.replace("$size", "40") |
- } |
- }); |
- } |
+ this.applyIcon(); |
if ("badgeText" in this._changes) |
{ |