app: deduplicate config detection, suppress hold-mode PTT spam
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import dataclasses
|
||||||
import html
|
import html
|
||||||
import logging
|
import logging
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
@@ -737,39 +738,32 @@ class TuimbleApp(App):
|
|||||||
safe: list[str] = []
|
safe: list[str] = []
|
||||||
restart: list[str] = []
|
restart: list[str] = []
|
||||||
|
|
||||||
if old.ptt.key != new.ptt.key:
|
# PTT: all fields are safe to hot-reload
|
||||||
safe.append(f"ptt key: {old.ptt.key} -> {new.ptt.key}")
|
old_ptt = dataclasses.asdict(old.ptt)
|
||||||
if old.ptt.mode != new.ptt.mode:
|
new_ptt = dataclasses.asdict(new.ptt)
|
||||||
safe.append(f"ptt mode: {old.ptt.mode} -> {new.ptt.mode}")
|
for key in old_ptt:
|
||||||
if old.ptt.backend != new.ptt.backend:
|
if old_ptt[key] != new_ptt[key]:
|
||||||
safe.append(
|
safe.append(f"ptt {key}: {old_ptt[key]} -> {new_ptt[key]}")
|
||||||
f"ptt backend: {old.ptt.backend} -> {new.ptt.backend}"
|
|
||||||
)
|
|
||||||
if old.audio.input_gain != new.audio.input_gain:
|
|
||||||
safe.append(
|
|
||||||
f"input gain: {old.audio.input_gain} -> "
|
|
||||||
f"{new.audio.input_gain}"
|
|
||||||
)
|
|
||||||
if old.audio.output_gain != new.audio.output_gain:
|
|
||||||
safe.append(
|
|
||||||
f"output gain: {old.audio.output_gain} -> "
|
|
||||||
f"{new.audio.output_gain}"
|
|
||||||
)
|
|
||||||
|
|
||||||
o_srv, n_srv = old.server, new.server
|
# Audio: gains are safe; hardware settings require restart
|
||||||
for attr in ("host", "port", "username", "password",
|
safe_audio = {"input_gain", "output_gain"}
|
||||||
"certfile", "keyfile"):
|
old_aud = dataclasses.asdict(old.audio)
|
||||||
ov, nv = getattr(o_srv, attr), getattr(n_srv, attr)
|
new_aud = dataclasses.asdict(new.audio)
|
||||||
if ov != nv:
|
for key in old_aud:
|
||||||
label = "password" if attr == "password" else attr
|
if old_aud[key] != new_aud[key]:
|
||||||
|
if key in safe_audio:
|
||||||
|
safe.append(f"{key}: {old_aud[key]} -> {new_aud[key]}")
|
||||||
|
else:
|
||||||
|
restart.append(f"audio.{key} changed")
|
||||||
|
|
||||||
|
# Server: all changes require restart
|
||||||
|
old_srv = dataclasses.asdict(old.server)
|
||||||
|
new_srv = dataclasses.asdict(new.server)
|
||||||
|
for key in old_srv:
|
||||||
|
if old_srv[key] != new_srv[key]:
|
||||||
|
label = "password" if key == "password" else key
|
||||||
restart.append(f"server.{label} changed")
|
restart.append(f"server.{label} changed")
|
||||||
|
|
||||||
o_aud, n_aud = old.audio, new.audio
|
|
||||||
for attr in ("input_device", "output_device", "sample_rate"):
|
|
||||||
ov, nv = getattr(o_aud, attr), getattr(n_aud, attr)
|
|
||||||
if ov != nv:
|
|
||||||
restart.append(f"audio.{attr} changed")
|
|
||||||
|
|
||||||
return safe, restart
|
return safe, restart
|
||||||
|
|
||||||
def _apply_safe_changes(self, new: Config) -> None:
|
def _apply_safe_changes(self, new: Config) -> None:
|
||||||
@@ -791,17 +785,11 @@ class TuimbleApp(App):
|
|||||||
old = self._config
|
old = self._config
|
||||||
|
|
||||||
server_changed = (
|
server_changed = (
|
||||||
old.server.host != new.server.host
|
dataclasses.asdict(old.server) != dataclasses.asdict(new.server)
|
||||||
or old.server.port != new.server.port
|
|
||||||
or old.server.username != new.server.username
|
|
||||||
or old.server.password != new.server.password
|
|
||||||
or old.server.certfile != new.server.certfile
|
|
||||||
or old.server.keyfile != new.server.keyfile
|
|
||||||
)
|
)
|
||||||
audio_hw_changed = (
|
audio_hw_changed = any(
|
||||||
old.audio.input_device != new.audio.input_device
|
getattr(old.audio, a) != getattr(new.audio, a)
|
||||||
or old.audio.output_device != new.audio.output_device
|
for a in ("input_device", "output_device", "sample_rate")
|
||||||
or old.audio.sample_rate != new.audio.sample_rate
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if server_changed:
|
if server_changed:
|
||||||
@@ -929,6 +917,8 @@ class TuimbleApp(App):
|
|||||||
self._audio.capturing = transmitting
|
self._audio.capturing = transmitting
|
||||||
status = self.query_one("#status", StatusBar)
|
status = self.query_one("#status", StatusBar)
|
||||||
status.ptt_active = transmitting
|
status.ptt_active = transmitting
|
||||||
|
if self._config.ptt.mode == "hold":
|
||||||
|
return
|
||||||
chatlog = self.query_one("#chatlog", ChatLog)
|
chatlog = self.query_one("#chatlog", ChatLog)
|
||||||
if transmitting:
|
if transmitting:
|
||||||
chatlog.write("[#e0af68]● transmitting[/]")
|
chatlog.write("[#e0af68]● transmitting[/]")
|
||||||
|
|||||||
Reference in New Issue
Block a user