-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Indicator if website is Unsupported. #134
base: master
Are you sure you want to change the base?
Conversation
I like the idea. Maybe it would be better to store some kind of "isCompatible" flag for each tab? |
Added flags for each tab so we dont need to recheck all modules. Thanks to maciex for the suggestion ♥.
js/background_scripts/background.js
Outdated
}) | ||
}); | ||
|
||
//Recheck the selected Tab when any Tab updates | ||
//Set needCheck flag to true when Tab Updates and recheck currently selected Tab | ||
chrome.tabs.onUpdated.addListener(function(tabID, changes){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event is fired when a Tab is updated. We get the updated tab ID.
Could you please explain why you query the tabs to get the current one and update it?
Isn't it redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The currently selected Tab gets rechecked, because when you press a link it only sets the needCheck flag to true, it doesn´t actually recheck the updated tab.
Will try to change it today though.
js/background_scripts/background.js
Outdated
chrome.tabs.onActivated.addListener(function(info){ | ||
chrome.tabs.getSelected(null,function(tab){ | ||
var tabURL = tab.url; | ||
chrome.tabs.query({active: true,lastFocusedWindow: true}, function (tab) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This content of tabs.query seems exactly the same as in tab.onUpdated.
js/background_scripts/background.js
Outdated
} | ||
|
||
//Check if Tab is Compatible | ||
checkIfTabIsCompatible(tabURL,tabID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why checkIfTabIsCopatible
is run at the end?
It won't set the icon during this run when the tab needChec = true
I think this should rather look like this:
//Check if Tab needs to be Checked
if(allTabs[tabID].needCheck) {
//Check if Tab is Compatible
checkIfTabIsCompatible(tabURL,tabID);
}
if(allTabs[tabID].isCompatible) {
chrome.browserAction.setIcon({path: CompatibleIconPath});
} else {
chrome.browserAction.setIcon({path: notCompatibleIconPath});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkIfTabIsCompatible is run at the end, because i added the function in the end and didn´t really think about where to put it.
The function itself changes the icon after the check.
I really like the way you did it, it looks a lot cleaner than mine.
I also really like all the help and suggestions you have ♥ Thank you for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two more comments.
All in all it looks OK for me, but I didn't try to run this yet.
js/background_scripts/background.js
Outdated
} | ||
|
||
//Check if Tab needs to be Checked | ||
if(allTabs[tabID].needCheck){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to change this part to the code below.
I think it looks cleaner and does less operations.
//Check if Tab needs to be Checked
if(allTabs[tabID].needCheck){
allTabs[tabID].isCompatible = false;
//console.info("Checking ID", tabID, "Url", tabURL);
for (let i = 0; i < allModules.length; i++) {
var module = allModules[i];
if (module.canHandleUrl(tabURL)){
allTabs[tabID].isCompatible = true;
break;
}
}
allTabs[tabID].needCheck = false;
}
js/background_scripts/background.js
Outdated
} | ||
} | ||
|
||
if(allTabs[tabID].isCompatible && tabID == currentTabId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part could be separated into new function (ex. updateAddOnIcon
), this way both function will do one thing, exactly what the name says.
I would suggest to change this part to the code below.
I think it looks cleaner and does less operations.
if(tabID == currentTabId) {
if (allTabs[tabID].isCompatible) {
chrome.browserAction.setIcon({path: CompatibleIconPath});
} else {
chrome.browserAction.setIcon({path: notCompatibleIconPath});
}
}
@maciex Thank you for taking your time and reviewing my code ♥. I hope everything works fine with it, and that there are no problems. |
@felixire I merged your changes into my fork and I found there's a problem with Youtube site. Steps to reproduce:
From my investigation the problem is caused by the |
@felixire Wait... is it reasonable and possible to get the I quickly checked and this seems to be working as the |
So the changes I'm suggesting:
|
I got one more suggestion... |
@maciex I wasn´t able to reproduce the problem with youtube, but we could check if the updated tab has finished loading before checking if the url is compatible. That way the url should always be the new one. Currently it´s important to pass the One way of passing only the
|
I'm testing this on my Firefox port, maybe it's because of that.
OK, I missed that. You're right.
I'll check that in my environment...
Exactly... why query all tabs, if we already new the ID of the tab we want. I'll prepare my idea of the code and somehow attach here. |
@felixire Please look at the changes. Patch: background.js: All seems working for me and the code looks simpler. EDIT: |
@maciex Thank you for your code. I checked it and everything seems to be working perfectly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor problems.
- In
chrome.tabs.onUpdated.addListener
you should check if theallTabs[tabID]
is already defined - On browser start the first page is always marked as supported, until first URL/tab change
js/background_scripts/background.js
Outdated
if(tabChanges.url == null) { | ||
return; | ||
} | ||
allTabs[tabID].needCheck = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this can be called when the allTabls[tabID] does not exist yet.
I suggest changing this to:
if (allTabs[tabID]) {
allTabs[tabID].needCheck = true;
}
Added check on Startup. Added check before setting flag.
@felixire The onStartup (responsible for changing the status icon on browser startup) listener does not seem to be run at all. I tested this on Firefox. Can you confirm that it works in your env? I also tried to find a way to fix it, but I failed. |
@maciex The event runs fine for me. I tested it in Chrome and Firefox Developer Version (don´t know if it makes a difference). |
@felixire OK You're right. It works. There's still one issue. Just after the Add-on is installed the icon is in the I'll include all the changes in my for in the |
@maciex Good to hear that it works on your end. I tested these changes in chrome and firefox and everything worked fine. |
This is nice, I've merged it into my fork. Are you still accepting pull requests @khloke ? |
Changes the Icon to a gray version if the website is unsupported.