some changes

This commit is contained in:
2026-04-11 14:34:58 +02:00
parent ab0d56a552
commit 369e7c6b42
4 changed files with 33 additions and 45 deletions
+1
View File
@@ -168,6 +168,7 @@ class Module(ActiveModifier):
if (count := data.get("set", -1)) > -1: self.skip_next = count
if (count2 := data.get("add", -1)) > -1: self.skip_next += count2
if (count3 := data.get("remove", 1)) < 0: self.skip_next += count3
self.skip_next = max(self.skip_next, 0)
return {"status": "ok", "data": self.skip_next}
activemod = Module()
+14 -36
View File
@@ -52,7 +52,6 @@
.controls{display:flex; gap:8px; margin-top:8px}
.box{display:flex; flex-direction:column; gap:8px; flex-grow: 1; overflow: hidden;}
/* --- HIDE SCROLLBARS ON ALL LISTBOXES --- */
.listbox{
height:100%;
min-height:100px;
@@ -235,8 +234,7 @@
// UI Toggle Function
function toggleSection(id) {
const el = document.getElementById(id);
el.classList.toggle('collapsed');
document.getElementById(id).classList.toggle('collapsed');
}
// Mobile Default Setup
@@ -257,7 +255,6 @@
document.getElementById("server-status").textContent = "connected";
reconnectDelay = 1000;
ws.send(JSON.stringify({action:"get_toplay"}));
ws.send(JSON.stringify({action:"skipc",set:0}));
});
ws.addEventListener("close", () => {
@@ -292,15 +289,12 @@
} else if(msg.event === "new_track"){
applyTrackState(msg.data);
ws.send(JSON.stringify({action:"get_toplay"}));
ws.send(JSON.stringify({action:"skipc",set:0}));
} else if(msg.event === "progress"){
applyProgressState(msg.data);
} else if(msg.event === "toplay") {
} else if(msg.event === "progress") applyProgressState(msg.data);
else if(msg.event === "toplay") {
Queue = msg.data.data || [];
renderQueue();
} else if(msg.event === "request_dir") {
applySubdir(msg.data || {})
} else if(msg.event === "skipc") {
} else if(msg.event === "request_dir") applySubdir(msg.data || {})
else if(msg.event === "skipc") {
skipCount = msg.data?.data ?? 0;
document.getElementById("skpn-count").textContent = skipCount;
renderPlaylist();
@@ -332,10 +326,7 @@
if(track.path){
currentTrackPath = (track.official ? "" : "!") + track.path;
document.getElementById("now-track").textContent = `${track.official ? "(official) " : ""}${track.path}`;
}
if(next_track.path){
document.getElementById("next-track").textContent = `${next_track.official ? "(official) " : ""}${next_track.path}`;
}
} if(next_track.path) document.getElementById("next-track").textContent = `${next_track.official ? "(official) " : ""}${next_track.path}`;
}
function applySubdir(payload) {
@@ -498,21 +489,11 @@
ws.send(JSON.stringify({action:"request_dir", what: selectedDir}))
}
document.getElementById("skip-btn").addEventListener("click", () => {
ws.send(JSON.stringify({action:"skip"}));
});
document.getElementById("skpn-inc").addEventListener("click", () => {
ws.send(JSON.stringify({action:"skipc", add: 1}));
});
document.getElementById("skpn-dec").addEventListener("click", () => {
ws.send(JSON.stringify({action:"skipc", remove: -1}));
});
document.getElementById("jingle-btn").addEventListener("click", () => {
ws.send(JSON.stringify({action:"jingle"}));
});
document.getElementById("clear-btn").addEventListener("click", () => {
ws.send(JSON.stringify({action:"clear_toplay"}))
});
document.getElementById("skip-btn").addEventListener("click", () => ws.send(JSON.stringify({action:"skip"})));
document.getElementById("skpn-inc").addEventListener("click", () => ws.send(JSON.stringify({action:"skipc", add: 1})));
document.getElementById("skpn-dec").addEventListener("click", () => ws.send(JSON.stringify({action:"skipc", remove: -1}))});
document.getElementById("jingle-btn").addEventListener("click", () => ws.send(JSON.stringify({action:"jingle"})));
document.getElementById("clear-btn").addEventListener("click", () => ws.send(JSON.stringify({action:"clear_toplay"})));
function addSelectedFileToQueue(top) {
let fullPath = null;
@@ -523,14 +504,11 @@
const path = (selected.official ? "" : "!") + selected.path;
ws.send(JSON.stringify({ action: "add_to_toplay", songs: [path], top: top }));
success = true;
} else if (selectedSubFile && selectedDir) {
fullPath = subbasePath.replace(/\/$/, '') + '/' + selectedSubFile;
} else {
} else if (selectedSubFile && selectedDir) fullPath = subbasePath.replace(/\/$/, '') + '/' + selectedSubFile;
else {
const dirEls = document.getElementById("dirs-box").children;
const selectedItem = Array.from(dirEls).find(el => el.classList.contains("selected"));
if (selectedItem && selectedItem.dataset.type === "file") {
fullPath = basePath.replace(/\/$/, '') + '/' + selectedItem.textContent;
}
if (selectedItem && selectedItem.dataset.type === "file") fullPath = basePath.replace(/\/$/, '') + '/' + selectedItem.textContent;
}
if (fullPath) {
+15 -6
View File
@@ -34,11 +34,11 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult
imc_q.put({"name": name, "data": data, "key": key})
start = time.monotonic()
result = None
while time.monotonic() - start < 1.5:
while time.monotonic() - start < 1:
if key in shared_data:
result = shared_data.pop(key)
break
await asyncio.sleep(0.05)
await asyncio.sleep(0.1)
return result
action = msg.get("action")
@@ -69,11 +69,11 @@ async def ws_handler(websocket: ServerConnection, shared_data: dict, imc_q: mult
elif action == "skip_next":
result = await get_imc("activemod", msg)
if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504}))
else: await websocket.send(json.dumps({"data": result, "event": "skip_next"}))
else: await websocket.send(json.dumps({"data": result, "event": action}))
elif action == "skipc":
result = await get_imc("activemod", msg)
if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504}))
else: await websocket.send(json.dumps({"data": result, "event": "skip_next"}))
else: await websocket.send(json.dumps({"data": result, "event": action}))
elif action == "jingle":
result = await get_imc("jingle", msg.get("top", False))
if result is None: await websocket.send(json.dumps({"error": "timeout", "code": 504}))
@@ -155,6 +155,14 @@ def websocket_server_process(shared_data: dict, imc_q: multiprocessing.Queue, ws
Headers([("Content-Type", "text/html"), ("Content-Length", f"{len(data)}")]),
data
)
if request.path == "/favicon.ico":
data = b"Not Found"
return Response(
404,
"Not Found",
Headers([("Content-Length", f"{len(data)}")]),
data
)
if not "upgrade" in request.headers.get("Connection", "").lower():
return Response(
426,
@@ -192,6 +200,7 @@ class Module(PlayerModule):
self.ws_process = multiprocessing.Process(target=websocket_server_process, args=(self.data, self.imc_q, self.ws_q), daemon=False)
self.ws_process.start()
if os.name == "posix":
# We have to manage the process ourselves. Linux sends signals to everyone in the process group, meaning a CTRL+C would not kill the main one, but this one would die
try: os.setpgid(self.ws_process.pid, self.ws_process.pid)
except Exception: pass
@@ -210,7 +219,6 @@ class Module(PlayerModule):
except Exception: pass
def on_new_playlist(self, playlist: list[Track], global_args: dict[str, str]) -> None:
# TODO: add global args to data
api_data = []
for track in playlist:
api_data.append({
@@ -220,7 +228,8 @@ class Module(PlayerModule):
"official": track.official,
"args": track.args,
"offset": track.offset,
"focus_time_offset": track.focus_time_offset
"focus_time_offset": track.focus_time_offset,
"global_args": global_args
})
self.data["playlist"] = json.dumps(api_data)
try: self.ws_q.put({"event": "playlist", "data": api_data})