frobar-ng: Fix Glib preventing closing
This commit is contained in:
parent
f22b42a711
commit
9916cb0170
|
@ -13,6 +13,7 @@ import time
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
import gi.events
|
||||||
import i3ipc
|
import i3ipc
|
||||||
import i3ipc.aio
|
import i3ipc.aio
|
||||||
import psutil
|
import psutil
|
||||||
|
@ -756,11 +757,13 @@ class MprisProvider(MirrorProvider):
|
||||||
text += f" {clip(title)}"
|
text += f" {clip(title)}"
|
||||||
self.title.setText(text)
|
self.title.setText(text)
|
||||||
|
|
||||||
def show_players(self, manager: gi.repository.Playerctl.PlayerManager, exclude: str | None = None) -> None:
|
def show_players(
|
||||||
|
self, manager: gi.repository.Playerctl.PlayerManager, exclude: str | None = None
|
||||||
|
) -> None:
|
||||||
# FIXME Opening and closing a chromium player, it will stay there (as default),
|
# FIXME Opening and closing a chromium player, it will stay there (as default),
|
||||||
# which is not the behaviour of playerctl somehow
|
# which is not the behaviour of playerctl somehow
|
||||||
for name in manager.props.player_names:
|
for name in manager.props.player_names:
|
||||||
if name == exclude: # DEBUG
|
if name == exclude: # DEBUG
|
||||||
continue
|
continue
|
||||||
player = gi.repository.Playerctl.Player.new_from_name(name)
|
player = gi.repository.Playerctl.Player.new_from_name(name)
|
||||||
self.show_player(player)
|
self.show_player(player)
|
||||||
|
@ -824,7 +827,13 @@ class MprisProvider(MirrorProvider):
|
||||||
log.debug(f"Player name vanished: {name}")
|
log.debug(f"Player name vanished: {name}")
|
||||||
self.show_players(manager, exclude=name)
|
self.show_players(manager, exclude=name)
|
||||||
|
|
||||||
def blocking(self) -> None:
|
async def run(self) -> None:
|
||||||
|
await super().run()
|
||||||
|
self.status = self.sectionType(parent=self.module, color=self.color)
|
||||||
|
self.album = self.sectionType(parent=self.module, color=self.color)
|
||||||
|
self.artist = self.sectionType(parent=self.module, color=self.color)
|
||||||
|
self.title = self.sectionType(parent=self.module, color=self.color)
|
||||||
|
|
||||||
manager = gi.repository.Playerctl.PlayerManager()
|
manager = gi.repository.Playerctl.PlayerManager()
|
||||||
manager.connect("name-appeared", self.on_name_appeared)
|
manager.connect("name-appeared", self.on_name_appeared)
|
||||||
manager.connect("player-appeared", self.on_player_appear)
|
manager.connect("player-appeared", self.on_player_appear)
|
||||||
|
@ -836,22 +845,6 @@ class MprisProvider(MirrorProvider):
|
||||||
|
|
||||||
self.show_players(manager)
|
self.show_players(manager)
|
||||||
|
|
||||||
# FIXME Prevents graceful shutdown
|
|
||||||
main = gi.repository.GLib.MainLoop()
|
|
||||||
main.run()
|
|
||||||
|
|
||||||
async def run(self) -> None:
|
|
||||||
await super().run()
|
|
||||||
self.status = self.sectionType(parent=self.module, color=self.color)
|
|
||||||
self.album = self.sectionType(parent=self.module, color=self.color)
|
|
||||||
self.artist = self.sectionType(parent=self.module, color=self.color)
|
|
||||||
self.title = self.sectionType(parent=self.module, color=self.color)
|
|
||||||
|
|
||||||
# PyGObject can work with async code, but is experimental,
|
|
||||||
# also it running in its own event loop makes things tricky
|
|
||||||
loop = asyncio.get_running_loop()
|
|
||||||
await loop.run_in_executor(None, self.blocking)
|
|
||||||
|
|
||||||
|
|
||||||
class AlertingProvider(Provider):
|
class AlertingProvider(Provider):
|
||||||
COLOR_NORMAL = rich.color.Color.parse("green")
|
COLOR_NORMAL = rich.color.Color.parse("green")
|
||||||
|
@ -1293,4 +1286,9 @@ async def main() -> None:
|
||||||
await bar.run()
|
await bar.run()
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(main())
|
if __name__ == "__main__":
|
||||||
|
# Using GLib's event loop so we can run GLib's code
|
||||||
|
policy = gi.events.GLibEventLoopPolicy()
|
||||||
|
asyncio.set_event_loop_policy(policy)
|
||||||
|
loop = policy.get_event_loop()
|
||||||
|
loop.run_until_complete(main())
|
||||||
|
|
Loading…
Reference in a new issue