FelixKratz / SbarLua

A Lua API for SketchyBar
GNU General Public License v3.0
120 stars 10 forks source link

front_app_switched and space_change errors without window #34

Closed realhackcraft closed 1 month ago

realhackcraft commented 1 month ago

Problem

When using front_app_switched or space_change, they will output could not retrieve window details. if I switch to a empty space without window. This stops the supplied function from running. This differs from the bash config, where it will still run the bash script and make $INFO=.

I think the behavior with bash is better, because in my case I'm getting the focused window title using yabai.

Solution

Run the function in sbar.subscribe even when there are no window currently focused, and set env.INFO to nil.

FelixKratz commented 1 month ago

It is not sketchybar or SbarLua that prints this: could not retrieve window details.. I believe it is returned from some yabai command you are issuing in these events.

realhackcraft commented 1 month ago

Yes, I am using sbar.exec, and I did confirm that running the yabai script without a window focused prints that line.

But why is this printed on stdout when I run yabai? Isn't the output of the yabai command supposed to go to the callback function I have to sbar.exec?

realhackcraft commented 1 month ago

Is there a way to run the function even when the script fails?

I read in another issue that if the command doesn't return anything, it won't run the function. It can be fixed by adding " && echo 1", but in my case it won't work because I need to no window focus and run code different from if a window has focus.

realhackcraft commented 1 month ago

If that's not possible, I'll have to switch back to my bash config.

FelixKratz commented 1 month ago

Should be possible with current commit.