swiftbar / SwiftBar

Powerful macOS menu bar customization tool
https://swiftbar.app
MIT License
2.93k stars 92 forks source link

Swiftbar taking focus from frontmost app at random #268

Closed shepazon closed 2 years ago

shepazon commented 2 years ago

I've yet to figure out if there's a pattern, but Swiftbar is periodically pulling itself to the foreground and staying there until the user retargets their focus. This is happening to me periodically while I work in other apps, which is frustrating when trying to edit code -- some number of characters I type go into the ether instead of into my source code during the brief period between focus changing and my recognizing the beeping of keystrokes without a useful focus.

I'm using version 1.4.2. This was not happening to me until I updated to 1.4.2 in the past few days, so I suspect it may be a regression of some sort.

I determined that Swiftbar was taking focus using a script that displays the name and pathname of the frontmost app whenever it changes.

I have just one plugin installed and enabled, a custom one I developed myself. It has not changed since long before the problem began to happen a couple of days ago. (It just happened to me a moment ago, right between typing the words "happen" and "a" -- and then again after typing the "o" in "words).

melonamin commented 2 years ago

Interesting, let me research it a bit, thank you for providing the focus tracking script.

Meanwhile, can you try running this build and see if it causes any trouble? SwiftBar.zip

shepazon commented 2 years ago

I’m checking it out and will let you know the results.

Eric Shepherd Senior Developer Writer Amazon Web Services

On Jan 25, 2022, at 3:18 PM, Alex Mazanov @.**@.>> wrote:

Interesting, let me research it a bit, thank you for providing the focus tracking script.

Meanwhile, can you try running this build and see if it causes any trouble? SwiftBar.ziphttps://github.com/swiftbar/SwiftBar/files/7927665/SwiftBar.zip

— Reply to this email directly, view it on GitHubhttps://github.com/swiftbar/SwiftBar/issues/268#issuecomment-1021572347, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARUXQXM5QHVORDWXVA7CUNDUX4ASNANCNFSM5MZGWJRQ. You are receiving this because you authored the thread.Message ID: @.***>

shepazon commented 2 years ago

This is definitely still happening. Can't say why...

melonamin commented 2 years ago

Hm, ok. I did run the monitoring script with SwiftBar in the background for the whole day and didn't catch it.

What plugins are you running? can you share any?

shepazon commented 2 years ago

I've figured out what's happening here. When my plugin's support script detects a state change, it issues the command open swiftbar://refreshplugin?name=mypluginname to tell Swiftbar to refresh my plugin.

Doing this causes Swiftbar to take on keyboard focus even though it has no visible UI of its own. That shouldn't happen.

melonamin commented 2 years ago

Why you didn't tell me this before? 😅

You get exactly what you ask - it "opens" the app, just use open -g and it will open it in background

shepazon commented 2 years ago

Well shoot. Can't believe I didn't think of that. I even use -g to open other things in my plugin. That said, I'd forgotten I even did this until I stumbled upon the code just now while tracing through some program logic. Making the change to my code now, will advise after testing.

shepazon commented 2 years ago

Yep, that solved the issue. Sorry about that, false alarm. (Which really is a good thing). :)