-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
media-sound/mpdris2: add 0.9.1_p20231017, drop 0.9.1_p20220630
add support for socket activation Bug: eonpatapon/mpDris2#161
- Loading branch information
Showing
4 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DIST mpdris2-0.9.1_p20220630.tar.gz 36286 BLAKE2B d8c2f40e363b72da53603de2c6f9c5f3527ab7006ecbe6dbea21fe591b58c347444a8c216f84ad14f80b01926b2aaef8d9770088b138c1a1ffe0ea2dc3958a42 SHA512 41d877874552458001496834208122982bc2050efd51555070445ba92e8ace6421363af5881fc52a09cc42b41ceb1a86e4aa719ac2da854d2d29fc60b553d065 | ||
DIST mpdris2-0.9.1_p20231017.tar.gz 36304 BLAKE2B 42863e4d01ccfa0826a06ac630dd40da23e210ebd5f33dc79370a98b603bff45f6228d9cf4cce42833e85e978a403b9e498f015ea4bc9f37d20f8f01f1fc67d5 SHA512 63878018935af3a32e1a946b0e6b29e18cad36d53d605f86793db1f68985ec2144e7fcdcdf3764b63778e1532071f1bb59fa1c26d0229faa451e8ed09d10916a |
140 changes: 140 additions & 0 deletions
140
media-sound/mpdris2/files/0001-Add-managed-option-to-disable-timer.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
From ba12d0ac2cdf407f981751ad451674bd6ae7b391 Mon Sep 17 00:00:00 2001 | ||
From: williamvds <[email protected]> | ||
Date: Fri, 29 Dec 2023 12:37:47 +0000 | ||
Subject: [PATCH 1/2] Add --managed option to disable timer | ||
|
||
When idle is available, the main purpose of the timer loop is to reconnect the | ||
socket when it is disconnected. | ||
|
||
An alternative is to allow systemd to handle this for us. We can bind the daemon | ||
to the mpd service, so that it is started automatically with the mpd service. | ||
|
||
Add a new command-line option `--managed`. If this is set, the daemon will exit | ||
cleanly instead of attempting a reconnect loop, under the assmption that systemd | ||
will restart it when mpd is available again. | ||
--- | ||
src/mpDris2.in.py | 44 +++++++++++++++++++++++++++++++----------- | ||
src/mpDris2.service.in | 6 ++++-- | ||
2 files changed, 37 insertions(+), 13 deletions(-) | ||
|
||
diff --git a/src/mpDris2.in.py b/src/mpDris2.in.py | ||
index a07793d..13cf591 100755 | ||
--- a/src/mpDris2.in.py | ||
+++ b/src/mpDris2.in.py | ||
@@ -64,6 +64,7 @@ params = { | ||
'port': None, | ||
'password': None, | ||
'bus_name': None, | ||
+ 'managed': False, | ||
# Library | ||
'music_dir': '', | ||
'cover_regex': None, | ||
@@ -242,6 +243,7 @@ class MPDWrapper(object): | ||
self._dbus = dbus | ||
self._params = params | ||
self._dbus_service = None | ||
+ self._should_reconnect = not params['managed'] | ||
|
||
self._can_single = False | ||
self._can_idle = False | ||
@@ -328,8 +330,10 @@ class MPDWrapper(object): | ||
# Init internal state to throw events at start | ||
self.init_state() | ||
|
||
- # Add periodic status check for sending MPRIS events | ||
- if not self._poll_id: | ||
+ # If idle is not available, add periodic status check for sending MPRIS events | ||
+ # Otherwise the timer will connect the socket if disconnected | ||
+ # If reconnection is not necessary and idle is supported, this timer isn't enabled. | ||
+ if not self._poll_id and (not self._can_idle or self._should_reconnect): | ||
interval = 15 if self._can_idle else 1 | ||
self._poll_id = GLib.timeout_add_seconds(interval, | ||
self.timer_callback) | ||
@@ -436,13 +440,27 @@ class MPDWrapper(object): | ||
|
||
def socket_callback(self, fd, event): | ||
logger.debug("Socket event %r on fd %r" % (event, fd)) | ||
- if event & GLib.IO_HUP: | ||
- self.reconnect() | ||
+ | ||
+ def handle_disconnect(): | ||
+ if self._should_reconnect: | ||
+ self.reconnect() | ||
+ else: | ||
+ logger.debug("Not reconnecting, quitting main loop") | ||
+ loop.quit() | ||
return True | ||
+ | ||
+ if event & GLib.IO_HUP: | ||
+ return handle_disconnect() | ||
+ | ||
elif event & GLib.IO_IN: | ||
if self._idling: | ||
self._idling = False | ||
- data = fd._fetch_objects("changed") | ||
+ | ||
+ try: | ||
+ data = fd._fetch_objects("changed") | ||
+ except mpd.base.ConnectionError: | ||
+ return handle_disconnect() | ||
+ | ||
logger.debug("Idle events: %r" % data) | ||
updated = False | ||
for item in data: | ||
@@ -1394,6 +1412,7 @@ if __name__ == '__main__': | ||
['help', 'bus-name=', 'config=', | ||
'debug', 'host=', 'music-dir=', | ||
'use-journal', 'path=', 'port=', | ||
+ 'managed', | ||
'version']) | ||
except getopt.GetoptError as ex: | ||
(msg, opt) = ex.args | ||
@@ -1420,6 +1439,8 @@ if __name__ == '__main__': | ||
music_dir = arg | ||
elif opt in ['--port']: | ||
params['port'] = int(arg) | ||
+ elif opt in ['--managed']: | ||
+ params['managed'] = True | ||
elif opt in ['-v', '--version']: | ||
v = __version__ | ||
if __git_version__: | ||
@@ -1564,9 +1585,10 @@ if __name__ == '__main__': | ||
logger.debug('Caught SIGINT, exiting.') | ||
|
||
# Clean up | ||
- try: | ||
- mpd_wrapper.client.close() | ||
- mpd_wrapper.client.disconnect() | ||
- logger.debug('Exiting') | ||
- except mpd.ConnectionError: | ||
- logger.error('Failed to disconnect properly') | ||
+ if mpd_wrapper.connected: | ||
+ try: | ||
+ mpd_wrapper.client.close() | ||
+ mpd_wrapper.client.disconnect() | ||
+ logger.debug('Exiting') | ||
+ except mpd.ConnectionError: | ||
+ logger.error('Failed to disconnect properly') | ||
diff --git a/src/mpDris2.service.in b/src/mpDris2.service.in | ||
index b612804..d6deab2 100644 | ||
--- a/src/mpDris2.service.in | ||
+++ b/src/mpDris2.service.in | ||
@@ -1,11 +1,13 @@ | ||
[Unit] | ||
Description=mpDris2 - Music Player Daemon D-Bus bridge | ||
+Wants=mpd.service | ||
+BindsTo=mpd.service | ||
|
||
[Service] | ||
Restart=on-failure | ||
-ExecStart=@bindir@/mpDris2 --use-journal | ||
+ExecStart=@bindir@/mpDris2 --use-journal --managed | ||
BusName=org.mpris.MediaPlayer2.mpd | ||
|
||
[Install] | ||
WantedBy=default.target | ||
-# WantedBy=daemon.target | ||
+WantedBy=mpd.service | ||
-- | ||
2.45.2 | ||
|
23 changes: 23 additions & 0 deletions
23
media-sound/mpdris2/files/0002-mpDris2.service.in-remove-WantedBy-default.target.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
From 07480db0469811137db89e0d6880485826d9adc4 Mon Sep 17 00:00:00 2001 | ||
From: Poncho <[email protected]> | ||
Date: Wed, 13 Nov 2024 15:13:33 +0100 | ||
Subject: [PATCH 2/2] mpDris2.service.in: remove WantedBy=default.target | ||
|
||
Required to not trigger socket activation of mpd | ||
--- | ||
src/mpDris2.service.in | 1 - | ||
1 file changed, 1 deletion(-) | ||
|
||
diff --git a/src/mpDris2.service.in b/src/mpDris2.service.in | ||
index d6deab2..c2d6b5c 100644 | ||
--- a/src/mpDris2.service.in | ||
+++ b/src/mpDris2.service.in | ||
@@ -9,5 +9,4 @@ ExecStart=@bindir@/mpDris2 --use-journal --managed | ||
BusName=org.mpris.MediaPlayer2.mpd | ||
|
||
[Install] | ||
-WantedBy=default.target | ||
WantedBy=mpd.service | ||
-- | ||
2.45.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters