Skip to content

Commit

Permalink
Resolve Synzvato#228 by implementing a new icon state
Browse files Browse the repository at this point in the history
  • Loading branch information
Synzvato committed Jun 27, 2018
1 parent a986800 commit bfabbf3
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 9 deletions.
65 changes: 62 additions & 3 deletions core/state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,24 @@ stateManager._removeTab = function (tabIdentifier) {

stateManager._updateTab = function (details) {

let tabIdentifier, frameIdentifier;
let tabDomain, domainIsWhitelisted, tabIdentifier, frameIdentifier;

tabDomain = helpers.extractDomainFromUrl(details.url);
domainIsWhitelisted = stateManager._domainIsWhitelisted(tabDomain);

tabIdentifier = details.tabId;
frameIdentifier = details.frameId;
tabIdentifier = details.tabId;

if (tabIdentifier === -1 || frameIdentifier !== 0) {
if (frameIdentifier !== 0 || tabIdentifier === -1) {
return;
}

if (domainIsWhitelisted) {
stateManager._setIconDisabled(tabIdentifier);
} else {
stateManager._setIconDefault(tabIdentifier);
}

chrome.browserAction.setTitle({
'tabId': tabIdentifier,
'title': 'Decentraleyes'
Expand Down Expand Up @@ -182,12 +191,62 @@ stateManager._removeIconBadgeFromTab = function (tab) {
stateManager._clearBadgeText(tab.id);
};

stateManager._domainIsWhitelisted = function (domain) {

if (domain !== null) {

let whitelistRecord, isWhitelisted;

whitelistRecord = requestAnalyzer.whitelistedDomains[domain];
isWhitelisted = Boolean(whitelistRecord);

return isWhitelisted;
}

return false;
};

stateManager._setIconDefault = function (tabIdentifier) {

wrappers.setIcon({
'path': stateManager.defaultIconPath,
'tabId': tabIdentifier
});
};

stateManager._setIconDisabled = function (tabIdentifier) {

wrappers.setIcon({
'path': stateManager.disabledIconPath,
'tabId': tabIdentifier
});
};

/**
* Initializations
*/

stateManager.requests = {};
stateManager.tabs = {};

stateManager.defaultIconPath = {
'18': chrome.runtime.getURL('icons/action/icon18-default.png'),
'19': chrome.runtime.getURL('icons/action/icon19-default.png'),
'32': chrome.runtime.getURL('icons/action/icon32-default.png'),
'36': chrome.runtime.getURL('icons/action/icon36-default.png'),
'38': chrome.runtime.getURL('icons/action/icon38-default.png'),
'64': chrome.runtime.getURL('icons/action/icon64-default.png')
};

stateManager.disabledIconPath = {
'18': chrome.runtime.getURL('icons/action/icon18-disabled.png'),
'19': chrome.runtime.getURL('icons/action/icon19-disabled.png'),
'32': chrome.runtime.getURL('icons/action/icon32-disabled.png'),
'36': chrome.runtime.getURL('icons/action/icon36-disabled.png'),
'38': chrome.runtime.getURL('icons/action/icon38-disabled.png'),
'64': chrome.runtime.getURL('icons/action/icon64-disabled.png')
};

stateManager.validHosts = [];

for (let mapping in mappings) {
Expand Down
File renamed without changes
Binary file added icons/action/icon18-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added icons/action/icon19-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added icons/action/icon32-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added icons/action/icon36-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added icons/action/icon38-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
12 changes: 6 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

"browser_action": {
"default_icon": {
"18": "icons/action/icon18.png",
"19": "icons/action/icon19.png",
"32": "icons/action/icon32.png",
"36": "icons/action/icon36.png",
"38": "icons/action/icon38.png",
"64": "icons/action/icon64.png"
"18": "icons/action/icon18-default.png",
"19": "icons/action/icon19-default.png",
"32": "icons/action/icon32-default.png",
"36": "icons/action/icon36-default.png",
"38": "icons/action/icon38-default.png",
"64": "icons/action/icon64-default.png"
},
"default_popup": "pages/popup/popup.html",
"browser_style": false
Expand Down
7 changes: 7 additions & 0 deletions modules/internal/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ wrappers.setBadgeText = function (details) {
chrome.browserAction.setBadgeText(details);
}
};

wrappers.setIcon = function (details) {

if (chrome.browserAction.setIcon !== undefined) {
chrome.browserAction.setIcon(details);
}
};

0 comments on commit bfabbf3

Please sign in to comment.