Skip to content

Commit

Permalink
fix file open through ws on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Dec 1, 2024
1 parent 35d2721 commit 42b7f39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
11 changes: 6 additions & 5 deletions lib/utils/fileOpenCommand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Future<bool> trySendFileArgs(List<String> args) async {
var completer = Completer<bool>();
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) {
Expand All @@ -37,13 +37,14 @@ Future<bool> trySendFileArgs(List<String> 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);
}
});
})
Expand Down

0 comments on commit 42b7f39

Please sign in to comment.