Extension causes the shell to freeze momentarily

I’m creating a shell extension that will display a battery indicator for bluetooth devices ( Yes, I know some were made already ) and I created a function with mainloop that runs every 3 seconds to update the indicator. Every time it runs the shell gets frozen for a short period of time (mouse isn’t moving, windows can’t be dragged, buttons don’t work). Does the shell wait for my extension to run it’s code? If so, can I somehow run my extension in the background so that it doesn’t interfere with the shell?

Extensions do not run as separate processes, they inject code into gnome-shell itself.

That allows you to change many of gnome-shell’s internal, but it also means that blocking in your extension will block the gnome-shell process itself.

There is no way around that other than not using blocking operations in extension code.

(Most functions in platform libraries - like GIO - offer an async variant that can be used instead of the (blocking) sync function)

1 Like

It turns out that gjs.guide does have a section on non-blocking/async programming that should come in handy:

1 Like

Thank you, I was using glib’s spawn_command_line_sync which is likely the problem.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.