aesqe / firefox-downloads-sidebar

A Firefox web extension that displays a list of your recent downloads in the sidebar
https://addons.mozilla.org/en-US/firefox/addon/downloads-sidebar/
MIT License
17 stars 3 forks source link

Button enhancements #7

Open CharoSW opened 6 years ago

CharoSW commented 6 years ago

Would it be possible to have a couple of enhancements to the button. Firstly that it toggles the download sidebar rather than just only open it. Secondly that the icon either has a light version for dark firefox themes or is neutral and thus changes with the toolbar text color. I'm not sure how that can be achieved but there's probably an example somewhere

dfalling commented 5 years ago

I'd also love if right-clicking the button had a clear downloads option.

josalhor commented 5 years ago

I believe the toggle should be fairly easy to implement. I'll do that today when I get home today. I have no idea how to implement the right click tho, I can't find an API that would allow such thing,

josalhor commented 5 years ago

I haven't succeed implementing the toggle. I believe some security features are blocking what I'm trying to do.

The on click callback I was trying to implement checked whether or not the current sidebar is open. Whoever the function that gives me that information returns a Promise and when I append the callback to the promise then FF tells me I'm trying to close the sidebar from a function that was not interacting with the user (and that is not allowed!)

Trying to wait for the Promise makes the original callback async, and the same problem arises.

I've only been successful modifying a global variable, but still it wasn't working right. It needed two clicks to work properly, one for updating the variable and another for closing it.

I have a feeling some kind of nasty trick could be applied to make it work and wait for the promise, but I wouldn't want to do that. I'll keep trying, it is possible I could do something different (first time using Promises in JS!).

About the right click, I still haven't found anything and I don't think WebExtensions have anything like that, I'll keep looking tho.

dfalling commented 5 years ago

@josalhor do you have a branch with your work attempting this? I haven't worked on web extensions at all but have a good understanding of JS and promises and can try to help out.

josalhor commented 5 years ago

Here you go: https://github.com/josalhor/firefox-downloads-sidebar/commit/08846b22113e986585bdd725c08eb21f712fdc1c

That implementation fails telling me Error: sidebarAction.close may only be called from a user input handler

dfalling commented 5 years ago

@josalhor Oof yeah, there's no easy fix for that. There are a few bugs logged about that: 1438465, 1398833. A bigger workaround would maybe be to keep track of when the sidebar is visible in storage and use that instead of sidebarAction.isOpen.

But your promise code looks good! It's just an issue with Firefox that doesn't have a great workaround currently.