Refine reboot notices and sounds for in-progress state

This commit is contained in:
Jage9
2026-02-27 19:23:09 -05:00
parent 71a190866d
commit ef5fa024c0
5 changed files with 47 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
// Maintainer-controlled web client version. // Maintainer-controlled web client version.
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2) // Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
window.CHGRID_WEB_VERSION = "2026.02.27 R296"; window.CHGRID_WEB_VERSION = "2026.02.27 R297";
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid. // Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
window.CHGRID_TIME_ZONE = "America/Detroit"; window.CHGRID_TIME_ZONE = "America/Detroit";

View File

@@ -883,7 +883,7 @@ function classifySystemMessageSound(message: string): keyof typeof SYSTEM_SOUND_
if (normalized.includes(' is now known as ') || normalized.startsWith('you are now known as ')) { if (normalized.includes(' is now known as ') || normalized.startsWith('you are now known as ')) {
return 'notify'; return 'notify';
} }
if (normalized.startsWith('server rebooting in ') || normalized === 'server reboot already scheduled.') { if (normalized.startsWith('server rebooting in ')) {
return 'notify'; return 'notify';
} }
return null; return null;

View File

@@ -231,6 +231,11 @@ export function createOnMessageHandler(deps: MessageHandlerDeps): (message: Inco
deps.playSample(deps.ACTION_SOUND_URL, 1); deps.playSample(deps.ACTION_SOUND_URL, 1);
} else if (message.system) { } else if (message.system) {
deps.pushChatMessage(message.message); deps.pushChatMessage(message.message);
const normalized = message.message.trim().toLowerCase();
if (normalized === 'server reboot already in progress.') {
deps.audioUiBlip();
break;
}
const sound = deps.classifySystemMessageSound(message.message); const sound = deps.classifySystemMessageSound(message.message);
if (sound) { if (sound) {
deps.playSample(deps.SYSTEM_SOUND_URLS[sound], 1); deps.playSample(deps.SYSTEM_SOUND_URLS[sound], 1);

View File

@@ -1686,11 +1686,10 @@ class SignalingServer:
return True return True
reboot_message = remainder if separator else "" reboot_message = remainder if separator else ""
if not self._schedule_reboot(client.username or client.nickname, reboot_message): if not self._schedule_reboot(client.username or client.nickname, reboot_message):
await self._send( await self._broadcast(
client.websocket,
BroadcastChatMessagePacket( BroadcastChatMessagePacket(
type="chat_message", type="chat_message",
message="Server reboot already scheduled.", message="Server reboot already in progress.",
system=True, system=True,
), ),
) )

View File

@@ -583,3 +583,41 @@ async def test_chat_reboot_schedules_and_broadcasts_message(monkeypatch: pytest.
assert getattr(packet, "type", "") == "chat_message" assert getattr(packet, "type", "") == "chat_message"
assert packet.system is True assert packet.system is True
assert packet.message == "Server rebooting in 5 seconds. maintenance" assert packet.message == "Server rebooting in 5 seconds. maintenance"
@pytest.mark.asyncio
async def test_chat_reboot_already_in_progress_broadcasts_notice(monkeypatch: pytest.MonkeyPatch) -> None:
server = SignalingServer("127.0.0.1", 8765, None, None)
ws = _fake_ws()
client = ClientConnection(
websocket=ws,
id="u1",
nickname="Tester",
authenticated=True,
user_id="1",
username="tester",
permissions={"chat.send", "server.allow_reboot"},
)
server.clients[ws] = client
broadcast_payloads: list[object] = []
send_payloads: list[object] = []
async def fake_broadcast(packet: object, exclude: ServerConnection | None = None) -> None:
broadcast_payloads.append(packet)
async def fake_send(websocket: ServerConnection, packet: object) -> None:
send_payloads.append(packet)
monkeypatch.setattr(server, "_broadcast", fake_broadcast)
monkeypatch.setattr(server, "_send", fake_send)
monkeypatch.setattr(server, "_schedule_reboot", lambda _requested_by, _message: False)
await server._handle_message(client, json.dumps({"type": "chat_message", "message": "/reboot maintenance"}))
assert send_payloads == []
assert len(broadcast_payloads) == 1
packet = broadcast_payloads[0]
assert getattr(packet, "type", "") == "chat_message"
assert packet.system is True
assert packet.message == "Server reboot already in progress."