Skip to content
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

Feature request - Disable ContextMenu Item #520

Closed
elijaholmos opened this issue Apr 19, 2021 · 10 comments
Closed

Feature request - Disable ContextMenu Item #520

elijaholmos opened this issue Apr 19, 2021 · 10 comments

Comments

@elijaholmos
Copy link

As a developer, I would like the ability to toggle the enabled/disabled status of a custom ContextMenu Item. For example, the "Report" item in the below screenshot is disabled because it is grayed out and unable to be clicked.
image

@khanhas
Copy link
Contributor

khanhas commented Apr 22, 2021

shouldAdd function parameter is already for returning the condition whether API should append your context menu item in the list. Is there any other use case that disabled status would be useful for?

@elijaholmos
Copy link
Author

I know it's a little niche, but the specific situation I wanted it for was an extension that fetched the user's entire library upon initialization and cannot function properly until that is complete. I've already incorporated this into the shouldAdd method so that the button will not appear until the entire user library has been fetched- I was just thinking it would be better on the user-side if they saw the button grayed out rather than completely absent, so that they know the extension is there, just not available to use yet.

@elijaholmos
Copy link
Author

I'm not sure how much work it would be to add the ability to toggle button enabled/disabled status from the code... if it's not something you think can be done easily, don't worry about it.

@khanhas
Copy link
Contributor

khanhas commented Apr 23, 2021

Nah I think it's reasonable enough. I will add it in next version.

@elijaholmos
Copy link
Author

Ok sweet! Thanks for chatting with me.

@khanhas
Copy link
Contributor

khanhas commented Apr 26, 2021

I made the change but I won't draft a new spicetify version any time soon. So if you want to try it out, just download this file and replace with the original one in <spicetify directory>/jsHelper/:
https://raw.githubusercontent.com/khanhas/spicetify-cli/master/jsHelper/spicetifyWrapper.js
"disabled" prop should be the last parameter of Item or SubMenu constructor:

const test = new Spicetify.ContextMenu.Item("Test", () => {}, () => true, "album", true);
test.register();

You can set "disabled" prop explicitly and it will be updated visually immediately:

test.disabled = false;

@elijaholmos
Copy link
Author

Awesome! I will test this out later today when I get home from work

@elijaholmos
Copy link
Author

I replaced my previous spicetifyWrapper.js file with the one you linked, but when I run spicetify apply it is loading in the source code from the old file. Is the old javascript being cached, or could there be something else that I didn't do right?

@khanhas
Copy link
Contributor

khanhas commented Apr 27, 2021

Ah no, spicetifyWrapper.js is copied in preprocess, you gotta run spicetify restore backup apply.

@elijaholmos
Copy link
Author

That worked perfectly, thanks for the help. The new feature functioned as intended and I encountered zero problems. Thank you!

@khanhas khanhas closed this as completed May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants