Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from PR #14 #15

Merged
merged 3 commits into from
Sep 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions i3blocks_mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class MPRISBlocklet:

_loop = None
_stdin_stream = None
_bus = None
_bus: dbus.SessionBus | None = None
_properties_changed_signal_match = None
_specific_name_owner_changed_signal_match = None
_any_name_owner_changed_signal_match = None
Expand Down Expand Up @@ -184,9 +184,7 @@ def create_loop(cls):
DBusGMainLoop(set_as_default=True)
return loop

def bus_name_has_owner(self, bus_name=None):
if not bus_name:
bus_name = self._bus_name
def bus_name_has_owner(self, bus_name: str):
return self._bus.name_has_owner(bus_name)

def init_bus(self):
Expand Down Expand Up @@ -215,7 +213,7 @@ def run(self, *, loop=None, read_stdin=True, nowait=False):
# initially, we don't know which match mode to use
match_mode = MatchMode.UNKNOWN
player_found = False
if self.bus_name_has_owner():
if self.bus_name_has_owner(self._bus_name):
# either the player don't allow multiple instance, e.g.,
# `org.mpris.MediaPlayer2.spotify`, or the user specified the
# exact instance, e.g., `org.mpris.MediaPlayer2.chromium.instance2`
Expand All @@ -242,11 +240,8 @@ def run(self, *, loop=None, read_stdin=True, nowait=False):
self.start_stdin_read_loop()
try:
self._loop.run()
except KeyboardInterrupt:
pass
finally:
if read_stdin:
self.stop_stdin_read_loop()
self.stop_stdin_read_loop()

def _find_instances(self) -> None:
for name in self._bus.list_names():
Expand Down Expand Up @@ -284,6 +279,8 @@ def start_stdin_read_loop(self):
self._read_stdin_once()

def stop_stdin_read_loop(self):
if not self._stdin_stream:
return
self._stdin_stream.close_async(
io_priority=GLib.PRIORITY_DEFAULT,
callback=lambda *args: self._loop.quit(),
Expand Down Expand Up @@ -351,7 +348,7 @@ def _connect_to_specific_name_owner_changed_signal(self):
)
self._specific_name_owner_changed_signal_match = signal_match

def _on_specific_name_owner_changed(self, name, old_owner, new_owner):
def _on_specific_name_owner_changed(self, _name, old_owner, new_owner):
if not old_owner and new_owner:
if not self._player_connected:
self._connect_to_player()
Expand Down