Skip to content

Commit

Permalink
Support MPD_HOST/_PORT environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jspricke committed Jan 25, 2025
1 parent 1254d4c commit 0448792
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/plattenalbum.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,19 @@ def update(self):
self.emitter.emit("updating-db")
return job_id

def try_connect(self, remote):
def try_connect(self):
self.emitter.emit("connecting")
def callback():
if (host:=os.environ.get('MPD_HOST')):
port=int(os.environ.get('MPD_PORT', '6600'))
elif (host:=self._settings.get_string("host")):
port=self._settings.get_int("port")

# connect
if remote:
if host:
try:
self.connect(self._settings.get_string("host"), self._settings.get_int("port"))
self.connect(host, port)
self._music_directory=None
except:
self.emitter.emit("connection_error")
self._start_idle_id=None
Expand All @@ -658,6 +664,7 @@ def callback():
self.emitter.emit("connection_error")
self._start_idle_id=None
return False
self._music_directory=self.config()
# set password
if password:=self._settings.get_string("password"):
try:
Expand All @@ -669,10 +676,6 @@ def callback():
return False
# connected
commands=self.commands()
if remote:
self._music_directory=None
elif "config" in commands:
self._music_directory=self.config()
if "outputs" in commands and "enableoutput" in commands:
if len(self.outputs()) == 1:
self.enableoutput(0)
Expand All @@ -683,7 +686,6 @@ def callback():
self.disconnect()
self.emitter.emit("connection_error")
# connect successful
self._settings.set_boolean("remote-connection", remote)
self._start_idle_id=None
return False
self._start_idle_id=GLib.idle_add(callback)
Expand Down Expand Up @@ -2803,7 +2805,7 @@ def _on_disconnect(self, action, param):
self._client.disconnect()

def _on_connect(self, action, param):
self._client.try_connect(param.get_boolean())
self._client.try_connect()

def _on_state(self, emitter, state):
state_dict={"play": True, "pause": True, "stop": False}
Expand Down Expand Up @@ -2958,7 +2960,7 @@ def open(self):
while main.pending():
main.iteration()
self._settings.bind("maximize", self, "maximized", Gio.SettingsBindFlags.SET)
self._client.try_connect(self._settings.get_boolean("remote-connection"))
self._client.try_connect()

def _clear_title(self):
self.set_title("Plattenalbum")
Expand Down

0 comments on commit 0448792

Please sign in to comment.