From 42b7f396e6681f4866353d29fd9ea353c168a9f6 Mon Sep 17 00:00:00 2001 From: ArthurHeitmann <37270165+ArthurHeitmann@users.noreply.github.com> Date: Sun, 1 Dec 2024 11:36:10 +0100 Subject: [PATCH] fix file open through ws on startup --- .../openFiles/types/xml/sync/syncServer.dart | 1 + lib/utils/fileOpenCommand.dart | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/stateManagement/openFiles/types/xml/sync/syncServer.dart b/lib/stateManagement/openFiles/types/xml/sync/syncServer.dart index 32dd6e1..2178595 100644 --- a/lib/stateManagement/openFiles/types/xml/sync/syncServer.dart +++ b/lib/stateManagement/openFiles/types/xml/sync/syncServer.dart @@ -81,6 +81,7 @@ void _handleWebSocket(WebSocket client) { } void _onClientData(data) { + print("Received data: $data"); var jsonData = jsonDecode(data); var method = jsonData["method"]; if (method == "openFiles") { diff --git a/lib/utils/fileOpenCommand.dart b/lib/utils/fileOpenCommand.dart index faab6d3..6c8a865 100644 --- a/lib/utils/fileOpenCommand.dart +++ b/lib/utils/fileOpenCommand.dart @@ -27,8 +27,8 @@ Future trySendFileArgs(List args) async { var completer = Completer(); WebSocket? webSocket; var timeout = Timer(const Duration(milliseconds: 500), () { - completer.complete(false); webSocket?.close(); + completer.complete(false); }); unawaited(WebSocket.connect("ws://localhost:$wsPort") .then((ws) { @@ -37,13 +37,14 @@ Future trySendFileArgs(List args) async { return; } webSocket = ws; - ws.add(jsonEncode(CustomWsMessage("openFiles", {"files": args}))); - ws.listen((data) { + ws.listen((data) async { var msg = SyncMessage.fromJson(jsonDecode(data)); if (msg.method == "connected") { - completer.complete(true); - ws.close(); timeout.cancel(); + ws.add(jsonEncode(CustomWsMessage("openFiles", {"files": args}))); + await Future.delayed(const Duration(milliseconds: 100)); + await ws.close(); + completer.complete(true); } }); })