mirror of https://github.com/gorhill/uBlock.git
Safari: make toolbar icon more robust & performant
Gets rid of background page exceptions
This commit is contained in:
parent
25222c1439
commit
21d4307a5a
|
@ -507,17 +507,22 @@
|
|||
/******************************************************************************/
|
||||
|
||||
vAPI.toolbarItem = false;
|
||||
safari.application.addEventListener("validate", function(event) {
|
||||
if(vAPI.toolbarItem === event.target) {
|
||||
return;
|
||||
var getIconForWindow = function(target) {
|
||||
var items = safari.extension.toolbarItems;
|
||||
for(var i = 0, n = items.length; i < n; i++) {
|
||||
if(items[i].browserWindow === target) {
|
||||
return items[i];
|
||||
}
|
||||
}
|
||||
vAPI.toolbarItem = event.target;
|
||||
}, true);
|
||||
};
|
||||
safari.application.addEventListener("activate", function(event) {
|
||||
if(!(event.target instanceof SafariBrowserTab)) {
|
||||
return;
|
||||
var target = event.target;
|
||||
if(target instanceof SafariBrowserTab) {
|
||||
vAPI.updateIcon(vAPI.tabs.getTabId(target));
|
||||
}
|
||||
else if(target instanceof SafariBrowserWindow) {
|
||||
vAPI.toolbarItem = getIconForWindow(target);
|
||||
}
|
||||
vAPI.updateIcon(vAPI.toolbarItem);
|
||||
}, true);
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -538,9 +543,12 @@
|
|||
TabIconState.prototype.img = "";
|
||||
|
||||
vAPI.tabIconState = { /*tabId: {badge: 0, img: suffix}*/ };
|
||||
vAPI.updateIcon = function(icon) {
|
||||
var tabId = vAPI.tabs.getTabId(icon.browserWindow.activeTab),
|
||||
state = vAPI.tabIconState[tabId];
|
||||
vAPI.updateIcon = function(tabId) {
|
||||
var icon = vAPI.toolbarItem;
|
||||
if(icon === false) {
|
||||
icon = getIconForWindow(vAPI.tabs.stack[tabId].browserWindow);
|
||||
}
|
||||
var state = vAPI.tabIconState[tabId];
|
||||
if(typeof state === "undefined") {
|
||||
state = vAPI.tabIconState[tabId] = new TabIconState();
|
||||
}
|
||||
|
@ -554,7 +562,7 @@
|
|||
}
|
||||
state.badge = badge || 0;
|
||||
state.img = (iconStatus === "on" ? "" : "-off");
|
||||
vAPI.updateIcon(vAPI.toolbarItem);
|
||||
vAPI.updateIcon(tabId);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue