JakeStanger / ironbar

Customisable Wayland gtk bar written in Rust.
https://crates.io/crates/ironbar
MIT License
486 stars 36 forks source link

Allow scripts in src image prop / script output not captured #94

Closed yavko closed 1 year ago

yavko commented 1 year ago

Is your feature request related to a problem? Please describe.

I want to display cover image of current song in bar

Describe the solution you'd like

Allow scripts in src

Describe alternatives you've considered

I would still like scripts to be allowed to be used in src, but cover in bar could also be added to the music widget.

Additional context

image

JakeStanger commented 1 year ago

Makes sense, don't think this will be too hard to do.

yavko commented 1 year ago

yay

yavko commented 1 year ago

Doesn't work on latest commit image

config:

music_img = rec {
        type = "custom";
        name = "music-img";
        class = name;
        bar = [
          {
            type = "image";
            src = ''file:///{{poll:5000:playerctl metadata mpris:artUrl | sed -E "s/file:\/\/\///"}}'';
          }
        ];
      };

doesn't matter what combination of /s I use, it just won't work

JakeStanger commented 1 year ago

That's odd, looks like the script output isn't getting captured. Also those slashes are horrible :upside_down_face:

If you try just a label element with the same script, can you get the URL to display as text? Also, can you double check it's writing to stdout (idk why it wouldn't)?

yavko commented 1 year ago

That's odd, looks like the script output isn't getting captured.

WAIT! That explains it, since i'm not able to get the uptime script thing you have in the power thing to work either

Also those slashes are horrible upside_down_face

I agree, I was trying everything, this just happened to be the last thing I tried lmao

If you try just a label element with the same script, can you get the URL to display as text?

YEAH IT DOESN'T image

Also, can you double check it's writing to stdout (idk why it wouldn't)?

image stdout works, unless this isn't stdout?

Ig this can re-closed, and a diff issue could be used, since it seems that no script is running.

yavko commented 1 year ago

Works in my repl, idk why it aint working image

Though I know ironbar also uses pipes and listens for updates over channels, its probably a ironbar issue.

JakeStanger commented 1 year ago

stdout works, unless this isn't stdout?

Standard pipe will be stdout, so that rules that out.

Ig this can re-closed, and a diff issue could be used, since it seems that no script is running.

I'm happy to keep it here since we've got the context here. Have updated the issue to reflect that.

Though I know ironbar also uses pipes and listens for updates over channels, its probably a ironbar issue.

Ironbar runs commands by spawning a sh -c '<your script here>'. Could it be a nixos quirk causing some kind of env issue with that? Clearly not based on the REPL, scrap that. Scripts definitely do work for me on Arch on latest commit though.

JakeStanger commented 1 year ago

I've just pushed up a commit into master that adds some additional logging to the script module. Could you try running a minimal config (ie just custom module with a single label with a script in it) using IRONBAR_LOG=trace (or IRONBAR_FILE_LOG=trace) and send the log pls? (It'll probably be very long)

yavko commented 1 year ago

I've just pushed up a commit into master that adds some additional logging to the script module. Could you try running a minimal config (ie just custom module with a single label with a script in it) using IRONBAR_LOG=trace (or IRONBAR_FILE_LOG=trace) and send the log pls? (It'll probably be very long)

with a minimal example it works?!??!

yavko commented 1 year ago

This is weird maybe when one command fails, it brings down all the other commands? But why would some commands fail, they are all valid?

JakeStanger commented 1 year ago

Oh very interesting, I've no idea why that would happen, unless you're triggering some kind of hrottling (why would dbus or a unix socket do that?) or there's some wires getting crossed in Ironbar.

Are you able to share your full config file (preferably in the compiled JSON format rather than Nix) and I can try and replicate exactly what's happening?

yavko commented 1 year ago

Oh very interesting, I've no idea why that would happen, unless you're triggering some kind of hrottling (why would dbus or a unix socket do that?) or there's some wires getting crossed in Ironbar.

Are you able to share your full config file (preferably in the compiled JSON format rather than Nix) and I can try and replicate exactly what's happening?

Here:

{
  "anchor_to_edges": true,
  "center": [
    {
      "format": "{title}",
      "music_dir": "/home/yavor/Music",
      "player_type": "mpris",
      "truncate": "end",
      "type": "music"
    }
  ],
  "end": [
    {
      "type": "tray"
    },
    {
      "format": [
        " {cpu_percent}%",
        " {memory_percent}%"
      ],
      "type": "sys_info"
    },
    {
      "bar": [
        {
          "label": "",
          "name": "power-btn",
          "on_click": "popup:toggle",
          "type": "button"
        }
      ],
      "class": "power-menu",
      "popup": [
        {
          "orientation": "vertical",
          "type": "box",
          "widgets": [
            {
              "label": "Power menu",
              "name": "header",
              "type": "label"
            },
            {
              "type": "box",
              "widgets": [
                {
                  "class": "power-btn",
                  "label": "<span font-size='40pt'></span>",
                  "on_click": "!shutdown now",
                  "type": "button"
                },
                {
                  "class": "power-btn",
                  "label": "<span font-size='40pt'></span>",
                  "on_click": "!reboot",
                  "type": "button"
                }
              ]
            },
            {
              "label": "Uptime: {{30000:uptime -p | cut -d ' ' -f2-}}",
              "name": "uptime",
              "type": "label"
            }
          ]
        }
      ],
      "tooltip": "Up: {{30000:uptime -p | cut -d ' ' -f2-}}",
      "type": "custom"
    },
    {
      "format": "%l:%M %P",
      "type": "clock"
    }
  ],
  "height": 32,
  "icon_theme": "Papirus-Dark",
  "position": "top",
  "start": [
    {
      "bar": [
        {
          "label": "",
          "on_click": "!hyprctl dispatch exec \"zsh -c 'rofi -show drun'\"",
          "type": "button"
        }
      ],
      "class": "nix-launcher",
      "name": "nix-launcher",
      "type": "custom"
    },
    {
      "all_monitors": false,
      "name_map": {
        "1": "●",
        "10": "●",
        "2": "●",
        "3": "●",
        "4": "●",
        "5": "●",
        "6": "●",
        "7": "●",
        "8": "●",
        "9": "●"
      },
      "type": "workspaces"
    }
  ]
}
JakeStanger commented 1 year ago

So! I think I've found the bug and it's in the script input parser - because the playerctl command contains a colon, it's hitting that and only taking everything after as the command. I don't think that'll be too hard to fix.

yavko commented 1 year ago

So! I think I've found the bug and it's in the script input parser - because the playerctl command contains a colon, it's hitting that and only taking everything after as the command. I don't think that'll be too hard to fix.

Ohhh, that would make sense

JakeStanger commented 1 year ago

The linked PR works for me at least with your config - are you able to give it a shot when you get a few mins and confirm please?

yavko commented 1 year ago

Sure, I'm at school rn so I'll do it in like 2 hours

yavko commented 1 year ago

Sorry something came up, but it does work! It fixed it!!

JakeStanger commented 1 year ago

No worries at all, work and sleep keep me busy most the day so it's never a rush. Thanks for testing, I'll merge the PR now.