Reset all app settings, dashboard starts empty
The reset disconnects all DSPs first and sends them nothing, asks for two random letters (and the PIN on the web), keeps a copy of the old config and reloads a fresh app. Refused during an audio test or mute all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d53069380
commit
29a89af562
8 files changed
+117
-7
No files matched your search
@@ -16,6 +16,7 @@ import math
|
||||
import mimetypes
|
||||
import re
|
||||
import secrets
|
||||
import shutil
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
@@ -406,6 +407,34 @@ class App:
|
||||
"limiter": self.limiter, "remote": self.remote, "soundfield": self.soundfield, "logo": self.logo,
|
||||
"dashboard": self.dashboard, "djbrake": self.djbrake, "dj_ignore": self.dj_ignore, "dj_hint": self.dj_hint, "dj_hint_en": self.dj_hint_en, "dj_margin": self.dj_margin, "dj_cal": self.dj_cal}
|
||||
|
||||
async def reset_config(self):
|
||||
"""Back to a fresh app. Only the app: the DSPs get disconnected first and receive nothing."""
|
||||
if any(d.test_active for d in self.real_devices()):
|
||||
raise ValueError("End the audio test first: the DSP would stay at the lowered level")
|
||||
if self.mute_all["active"]:
|
||||
raise ValueError("Release mute all first: the DSPs would stay muted")
|
||||
self.demo_resume = set()
|
||||
if self.demo["enabled"]:
|
||||
await self.stop_demo()
|
||||
for dev in self.real_devices():
|
||||
await dev.stop()
|
||||
del self.devices[dev.id]
|
||||
self.broadcast({"type": "removed", "device": dev.id})
|
||||
if self.config_path.exists(): # one way back, in case this was a mistake
|
||||
shutil.copyfile(self.config_path, self.config_path.with_name("config.before-reset.json"))
|
||||
sessions = {k: v for k, v in self.sessions.items() if k in self.app_sessions}
|
||||
keep = {"config_path", "clients", "app_token", "app_sessions", "remote_server", "remote_writers", "failures", "dj_streams"}
|
||||
for name, value in vars(App(self.config_path)).items():
|
||||
if name not in keep:
|
||||
setattr(self, name, value)
|
||||
self.sessions = sessions
|
||||
self.apply_config({})
|
||||
self.save()
|
||||
self.broadcast({"type": "reset"})
|
||||
await asyncio.sleep(0.2) # let the phones hear it before their connection goes
|
||||
if self.app_token:
|
||||
await self.start_remote()
|
||||
|
||||
async def restore_config(self, doc: dict, session: str):
|
||||
if not isinstance(doc, dict) or doc.get("format") != CONFIG_FORMAT:
|
||||
raise ValueError("Not a DSP Control settings backup")
|
||||
@@ -1293,6 +1322,16 @@ class App:
|
||||
if path == "/api/pin" and method == "POST":
|
||||
await self.respond_json(writer, *await self.change_pin(session, data))
|
||||
return
|
||||
if path == "/api/reset" and method == "POST":
|
||||
if not is_app and not self.check_pin(str(data.get("pin", ""))):
|
||||
await self.respond_json(writer, 400, {"error": "Wrong PIN"})
|
||||
else:
|
||||
try:
|
||||
await self.reset_config()
|
||||
await self.respond_json(writer, 200, {"ok": True})
|
||||
except ValueError as e:
|
||||
await self.respond_json(writer, 400, {"error": str(e)})
|
||||
return
|
||||
if path == "/api/backup":
|
||||
if method == "GET":
|
||||
await self.respond_json(writer, 200, self.export_config())
|
||||
|
||||
Reference in new issue
Block a user