matryer / xbar

Put the output from any script or program into your macOS Menu Bar (the BitBar reboot)
https://xbarapp.com
MIT License
17.45k stars 641 forks source link

Refresh does not reflect config changes #914

Open halilim opened 5 months ago

halilim commented 5 months ago

https://github.com/matryer/xbar-plugins/blob/main/CONTRIBUTING.md#plugin-variable-json-files :

You can programmatically modify the JSON files to adjust the values. Use the refresh control API above to refresh plugins after changing variables.

~/Library/Application Support/xbar/plugins/config_refresh_issue.sh:

#!/usr/bin/env bash
set -eo pipefail
IFS=$'\n\t'

# <xbar.var>string(VAR_TEST="initial"): Test</xbar.var>

config_file="$0.vars.json"

if [[ $1 == modify ]]; then
  sed -i '' -E "s/(\"VAR_TEST\": \")[[:alnum:]]*/\1$RANDOM/" "$config_file"
fi

echo '🧪'
echo '---'
echo "Modify config | bash=$0 | param1=modify | refresh=true"
echo "VAR_TEST=\"$VAR_TEST\""

To reproduce: Hit "Modify config" in the plugin menu Actual: VAR_TEST remains the same in the menu Expected: VAR_TEST reflects the change

The file itself (~/Library/Application Support/xbar/plugins/config_refresh_issue.sh.vars.json) changes, it's just not reflected in the running plugin.

Hitting the submenu item "xbar > Refresh" doesn't work.

Workaround: submenu "xbar > Refresh all" (or reopen the xbar app). Or get configs manually, e.g.:

config=$(< "$config_file")
function get_config() {
  grep "$1" <<< "$config" | cut -d' ' -f2 | tr -d '",'
}
VAR_TEST=$(get_config 'VAR_TEST')