From 11ecd8c68f390f234d1555baae55e85b5e83a09b Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Tue, 2 Apr 2024 18:05:49 +0300 Subject: [PATCH] fix: exec debugger close logic on application exit --- .../jscript/utils/debug/DebugServer.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/java/me/topchetoeu/jscript/utils/debug/DebugServer.java b/src/java/me/topchetoeu/jscript/utils/debug/DebugServer.java index 07c76fa..db69e7f 100644 --- a/src/java/me/topchetoeu/jscript/utils/debug/DebugServer.java +++ b/src/java/me/topchetoeu/jscript/utils/debug/DebugServer.java @@ -137,6 +137,13 @@ public class DebugServer { } runAsync(() -> { + var handle = new Thread(() -> { + System.out.println("test"); + debugger.close(); + }); + + Runtime.getRuntime().addShutdownHook(handle); + try { handle(ws, debugger); } catch (RuntimeException | IOException e) { try { @@ -145,7 +152,11 @@ public class DebugServer { } catch (IOException e2) { /* Shit outta luck */ } } - finally { ws.close(); debugger.close(); } + finally { + Runtime.getRuntime().removeShutdownHook(handle); + ws.close(); + debugger.close(); + } }, "Debug Handler"); } @@ -164,7 +175,6 @@ public class DebugServer { var req = HttpRequest.read(socket); if (req == null) continue; - switch (req.path) { case "/json/version": send(req, "{\"Browser\":\"" + browserDisplayName + "\",\"Protocol-Version\":\"1.1\"}");