From b6435f90101c76ea6485dc97f1722c16c7762a5c Mon Sep 17 00:00:00 2001 From: Majjo <90888719+NoxRare@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:57:47 +0200 Subject: [PATCH] fix: add language strings for companion server; fix startup logging and null safety --- common/src/main/assets/lang/en_US.json | 18 ++++++++++++++++++ .../features/impl/global/CompanionServer.kt | 15 ++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json index 7369cf61..11aa1dcd 100644 --- a/common/src/main/assets/lang/en_US.json +++ b/common/src/main/assets/lang/en_US.json @@ -2837,6 +2837,24 @@ "description": "Automatically deletes cached events that are older than the specified amount of time" } } + }, + "companion_server": { + "name": "Companion Server", + "description": "Local web server that streams live logs and network calls to a browser dashboard", + "properties": { + "enabled": { + "name": "Enabled", + "description": "Start the companion web server inside Snapchat's process. Requires a restart." + }, + "port": { + "name": "Port", + "description": "Port the server listens on (1024–65535). Default is 8484." + }, + "token": { + "name": "Auth Token", + "description": "Secret token required to access the dashboard. Must not be empty. Requires a restart." + } + } } }, "options": { diff --git a/core/src/main/kotlin/me/eternal/purrfectsnap/core/features/impl/global/CompanionServer.kt b/core/src/main/kotlin/me/eternal/purrfectsnap/core/features/impl/global/CompanionServer.kt index 8597e0ce..6bc00256 100644 --- a/core/src/main/kotlin/me/eternal/purrfectsnap/core/features/impl/global/CompanionServer.kt +++ b/core/src/main/kotlin/me/eternal/purrfectsnap/core/features/impl/global/CompanionServer.kt @@ -31,17 +31,22 @@ class CompanionServer : Feature("CompanionServer") { override fun init() { val config = context.config.companionServer - if (!config.enabled.get()) return + if (!config.enabled.get()) { + context.log.verbose("Companion Server: disabled in config", "CompanionServer") + return + } val token = config.token.get().trim() if (token.isEmpty()) { - context.log.warn("Companion Server: no token set — server disabled", "CompanionServer") + context.log.warn("Companion Server: no auth token set — server will not start", "CompanionServer") return } val port = config.port.get().coerceIn(1024, 65535) - hookLogOutput() + runCatching { hookLogOutput() }.onFailure { + context.log.warn("Companion Server: log hooking unavailable (${it.message})", "CompanionServer") + } subscribeToNetworkEvents() startServer(port, token) } @@ -57,8 +62,8 @@ class CompanionServer : Feature("CompanionServer") { isCapturing.set(true) try { val priority = param.arg(0) - val tag = param.arg(1) - val message = param.arg(2) + val tag = param.argNullable(1) ?: "" + val message = param.argNullable(2) ?: "" val level = when (priority) { Log.VERBOSE -> "V" Log.DEBUG -> "D"