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

Can plugin variables be edited from the UI? #655

Closed
nicolasff opened this issue Mar 20, 2021 · 3 comments
Closed

Can plugin variables be edited from the UI? #655

nicolasff opened this issue Mar 20, 2021 · 3 comments
Labels

Comments

@nicolasff
Copy link

Hello,

I've been trying to integrate the variables feature into some of my plugins, and I've tried everything I could think of to change the values of these variables from the UI (in the ⌘+E panel for a plugin), but nothing has worked so far.

I started with the most basic plugin, saved as test.sh:

#!/bin/bash
#
#  <xbar.var>string(VAR_OPT_1=foo): Option 1.</xbar.var>
#  <xbar.var>string(VAR_OPT_2=bar): Option 2.</xbar.var>
#
echo test
echo ---
echo "Option 1: ${VAR_OPT_1}"
echo "Option 2: ${VAR_OPT_2}"

When I opened the plugin settings, I could see the two variables and their default values:
image

I tried changing these strings – meaning setting a custom value that's different from the default – and I was expecting to see test.sh.vars.json show up in the plugins directory, but no file was created. As soon as I navigated away from the details panel for this plugin and went back, the variables had been reset to their default values.

I figured if xbar couldn't create the JSON file, maybe I could create it and it would be able to edit it. So I added test.sh.vars.json with the following contents:

{
    "VAR_OPT_1": "from-json-1",
    "VAR_OPT_2": "from-json-2"
}

And after restarting the app I did see these values… not only in the menu bar:
image

but in the plugin config panel too:
image

There's even a label underneath that says "💡 You must refresh the plugin for changes to take effect."
The string fields are clearly editable, for variables defined as integers there are even up and down arrows to change the value, and booleans are displayed as checkboxes that can be changed too.

And here even though I had created the JSON file and xbar had managed to load values from it both at runtime and in the plugin config panel, nothing I did in the editor caused these values to be saved back into the file. I tried pressing Enter, I tried ⌘ + S, I tried ⌘ + R… nothing worked. The JSON file was never created if it didn't already exist, and was never updated if it did exist.

Is the editing feature for variables something that is not fully implemented yet? Or am I just using it wrong? (in which case how can I get xbar to save updated values for variables?)

@matryer matryer added the bug label Mar 21, 2021
@matryer
Copy link
Owner

matryer commented Mar 21, 2021

Hey @nicolasff looks like you've found a bug. The variables should update exactly as you're expecting. We'll look into this.

@matryer
Copy link
Owner

matryer commented Mar 28, 2021

Hey @nicolasff - please try the latest release, this should be fixed now.

@nicolasff
Copy link
Author

Thanks @matryer! I can confirm the feature works with release v2.0.34-beta.

I now see the <name>.vars.json file being created when I make changes to variables in the plugin settings panel, and the plugin receives the expected values as environment variables when I press the ⟲ button at the top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants