From f0e5732cc7f250cccff951907d42eb992074a5db Mon Sep 17 00:00:00 2001 From: 00asdf Date: Sat, 26 Apr 2025 03:12:13 +0200 Subject: [PATCH] prettify --- .../dev/asdf00/visionfive/hc/server/Main.kt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/dev/asdf00/visionfive/hc/server/Main.kt b/src/main/kotlin/dev/asdf00/visionfive/hc/server/Main.kt index 8d3af6f..aecd04d 100644 --- a/src/main/kotlin/dev/asdf00/visionfive/hc/server/Main.kt +++ b/src/main/kotlin/dev/asdf00/visionfive/hc/server/Main.kt @@ -92,15 +92,15 @@ fun main() {

Welcome to HeatControl

-

Please log in to view the current temperature

+

Please log in to view the current temperature.


Login Form

-
+

-
+

@@ -224,7 +224,7 @@ fun main() { } val forecastQuery = Thread { - while (!Thread.interrupted()) { + whileNotInterrupted { var success = false val request = HttpRequest.newBuilder(URI.create(GlobalDataStore.API)).GET().build() HttpClient.newHttpClient() @@ -320,7 +320,7 @@ fun main() { val pidController = PidController(c1, c2, c3) var cycles = -1 - while (!Thread.interrupted()) { + whileNotInterrupted { if (cycles < 0) { c1.runCalibrationSequence() c2.runCalibrationSequence() @@ -372,8 +372,17 @@ private fun getAuthToken(exchange: HttpExchange) = exchange.requestHeaders["Cookie"] ?.let { if (it.size > 0) it[0] else null } ?.let { it.split("; ") } - ?.filter { it.startsWith("auth=") } - ?.firstOrNull() + ?.firstOrNull { it.startsWith("auth=") } ?.let { it.split("=").let { if (it.size == 2) it[1] else "" } } ?: "" +fun whileNotInterrupted(body: () -> Unit) { + try { + while (!Thread.interrupted()) { + body() + } + Thread.currentThread().interrupt() + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + } +}