Philipp Hörist pushed to branch master at gajim / gajim


Commits:
6b51f1a3 by André Apitzsch at 2022-04-02T20:15:47+02:00
other: Start music track listener only if necessary

Only start music track listener if publishing media playback is enabled
for at least one account.

- - - - -


4 changed files:

- gajim/common/client.py
- gajim/common/dbus/music_track.py
- gajim/common/modules/user_tune.py
- gajim/gtk/application.py


Changes:

=====================================
gajim/common/client.py
=====================================
@@ -454,6 +454,9 @@ def _finish_connect(self) -> None:
         self.get_module('Annotations').request_annotations()
         self.get_module('Blocking').get_blocking_list()
 
+        if app.settings.get_account_setting(self._account, 'publish_tune'):
+            self.get_module('UserTune').set_enabled(True)
+
         self.notify('state-changed', SimpleClientState.CONNECTED)
 
         app.ged.raise_event(SignedIn(account=self._account, conn=self))


=====================================
gajim/common/dbus/music_track.py
=====================================
@@ -22,6 +22,7 @@
 from typing import Optional
 
 import logging
+import sys
 
 from gi.repository import Gio
 from gi.repository import GLib
@@ -49,6 +50,10 @@ def __init__(self):
         self.players = {}
         self.connection = None
         self._current_tune = None
+        self._running = False
+
+        if sys.platform not in ('win32', 'darwin'):
+            self.start()
 
     def _emit(self, info: Optional[TuneData]) -> None:
         self._current_tune = info
@@ -59,6 +64,9 @@ def current_tune(self) -> Optional[TuneData]:
         return self._current_tune
 
     def start(self):
+        if self._running:
+            return
+
         proxy = Gio.DBusProxy.new_for_bus_sync(
             Gio.BusType.SESSION,
             Gio.DBusProxyFlags.NONE,
@@ -96,6 +104,8 @@ def start(self):
         for name in list(self.players):
             self._get_playing_track(name)
 
+        self._running = True
+
     def stop(self):
         for name in list(self.players):
             if name.startswith(MPRIS_PLAYER_PREFIX):
@@ -203,7 +213,3 @@ def proxy_call_finished(proxy, res):
                    None,
                    proxy_call_finished)
 
-
-def enable():
-    listener = MusicTrackListener.get()
-    listener.start()


=====================================
gajim/common/modules/user_tune.py
=====================================
@@ -44,11 +44,6 @@ def __init__(self, con):
         self._current_tune: Optional[TuneData] = None
         self._contact_tunes: dict[JID, TuneData] = {}
 
-        self.register_events([
-            ('music-track-changed', ged.CORE, self._on_music_track_changed),
-            ('signed-in', ged.CORE, self._on_signed_in),
-        ])
-
     def get_current_tune(self) -> Optional[TuneData]:
         return self._current_tune
 
@@ -88,8 +83,13 @@ def set_tune(self, tune, force=False):
 
     def set_enabled(self, enable):
         if enable:
+            self.register_events([
+                ('music-track-changed', ged.CORE, 
self._on_music_track_changed),
+                ('signed-in', ged.CORE, self._on_signed_in),
+            ])
             self._publish_current_tune()
         else:
+            self.unregister_events()
             self.set_tune(None, force=True)
 
     def _publish_current_tune(self):


=====================================
gajim/gtk/application.py
=====================================
@@ -63,7 +63,6 @@
 from gajim.common.application import CoreApplication
 from gajim.common.const import GAJIM_FAQ_URI
 from gajim.common.const import GAJIM_WIKI_URI
-from gajim.common.dbus import music_track
 from gajim.common.exceptions import GajimGeneralException
 from gajim.common.helpers import load_json
 from gajim.common.helpers import open_uri
@@ -239,9 +238,6 @@ def _startup(self, _application: GajimApplication) -> None:
         from gajim.gui.status_icon import StatusIcon
         self.systray = StatusIcon()
 
-        if sys.platform not in ('win32', 'darwin'):
-            music_track.enable()
-
         self.add_actions()
         self._load_shortcuts()
         menus.build_accounts_menu()



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/6b51f1a3ace068511ee4415ce3085367a10761dc

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/6b51f1a3ace068511ee4415ce3085367a10761dc
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to