-
Notifications
You must be signed in to change notification settings - Fork 6
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
Correctly set check mark after accepting a new permission #33
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,9 +71,6 @@ async function togglePermission(tab: chrome.tabs.Tab, toggle: boolean): Promise< | |
|
||
const userAccepted = await chromeP.permissions.request(permissionData); | ||
if (!userAccepted) { | ||
chrome.contextMenus.update(contextMenuId, { | ||
checked: false, | ||
}); | ||
return; | ||
} | ||
|
||
|
@@ -117,7 +114,7 @@ async function handleClick( | |
|
||
throw error; | ||
} finally { | ||
void updateItem(); | ||
void updateItem(tab?.id ? await getTabUrl(tab?.id) : ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this only needs to be called on error, then it should be inside the catch statement right? Also I presume that if there's an error the status is "unchecked", which doesn't need a URL check. On extension with limited permissions, you can't get the tab URL (e.g. I think this fails on chrome://extensions for example) There's a demo extension in this repo you can use for testing. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather, I suppose:
right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I did think about that, but I wanted to be able to add handling for other scenarios like this one: and so it felt like a cleaner separation of concerns to only update the context menu from That said, this is just a preference rather than a strong opinion.
I wasn't sure about that. Couldn't the extension already be enabled, in which case if there's an error it should stay checked?
There are so many pitfalls in this area it's crazy 🤣
Oh thanks, I'll check it out!
You mean in addition to removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There shouldn't be an error when removing a permission. However… you can't remove a wide permission like Edit: Opened: For the intents of this PR, it should assume that removal is successful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, new version coming shortly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TL;DR: after investigation, I recommend keeping the approach in this PR, but the gory details follow. So I tried this approach: and it results in several regressions where the check mark doesn't get set correctly in multiple cases. For example, switch site access to on click, then enable for a site in the manifest via content menu toggle. Because we're relying on Chrome to update the menu item, it doesn't spot that the site is in the manifest, therefore it (correctly) enables the checkmark but fails to disable (grey out) the menu item. This means that it's now possible to attempt to remove the same permission from the still enabled menu item. In that case, this statement:
turns out to be not true, because it results in:
Even if we add some logic to deal with that case, it feels to me like a very brittle approach to assume that we can ensure As well as being brittle, it would basically require either:
IMHO this affirms the point I was making earlier about the benefit of separation of concerns: if we have one function which handles interactions with Revisiting your original comments with the benefit of hindsight:
We now know this isn't true, because of the need to disable the menu item in certain cases.
We now know this isn't true, since if something prior to this goes wrong, it can allow a misguided attempt to disable a site in the manifest would fail, in which case the status should remain checked.
I don't see a problem here, because the code in this PR should still work if the tab URL can't be retrieved. The only minor issue might be that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Nothing is "easily" fixed here obviously haha
I'm only talking about
As mentioned elsewhere, I really don't want to get into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll open a PR |
||
} | ||
} | ||
|
||
|
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 still don't understand what's the problem with this line.
finally
Or if successful:
finally
witherI can't think of another scenario in which
request()
returnstrue
but it should not be (natively) checked.To put it in other words, we only have to fix the check:
The way I see it, the only reason #29 is an issue is because
updateItem()
is called even if successful. That's it.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've been through so many scenarios now that my head is exploding, but I'll do my best to respond accurately.
I don't think I ever said there was a problem with these three lines; it's just that my PR proposed another way of tackling the issue via modified usage of
updateItem()
elsewhere, which made these three lines redundant (since we don't want to be updating the same menu item twice in rapid succession as part of the same event handling).The problematic situation I described above was not relating to when the user wants to grant permission, but rather when they are trying to remove it:
Yes it's true that in step 1 here, the item should be disabled, but as I observed above, this is not yet working reliably in all situations, which is why I was proposing a less brittle approach which doesn't assume that everything else is working perfectly.
But anyway, I think your draft approach in #38 is more promising so hopefully that will work well in which case I'm happy to leave this PR closed.
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 is where we keep butting heads. This does not happen if you keep the Chrome UI (#7) out of the equation.
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 issue with that is that you're already working on a broken piece of UI, so what you're suggesting is focusing on the wrong part of the code. Let's instead make sure that the UI is correct before the click.
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.
Sure, I've already given up worrying about the Chrome UI for now. However there are still problems, but I'll describe them in the relevant issues and PRs.