From 44633f082fb2cd475b6aec423201b266e655229c Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sun, 28 Jan 2024 12:13:30 -0600 Subject: [PATCH] fix: fetch full message --- src/hyprman.nim | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/hyprman.nim b/src/hyprman.nim index c18860b..b7facd5 100644 --- a/src/hyprman.nim +++ b/src/hyprman.nim @@ -1,4 +1,4 @@ -import std/[os,net, json, sugar, strformat, tables] +import std/[os,net, json, sugar, strformat, strutils, tables] const icons = { @@ -52,16 +52,20 @@ proc getData(data: string): string = raise newException(HyprlandDefect, "Could not connect to Hyprland IPC UNIX path; is Hyprland running?") socket.send(data) - let response = socket.recv(4096) + var recvData: seq[string] + while true: + let response = socket.recv(4096) + if response == "": + break + recvData.add response socket.close() # is this necessary? - return response - + return recvData.join("") proc getDefaultWorkspaces(): seq[WorkspaceIcon] = let clients = parseJson(getData("[-j]/clients")).to(seq[Client]) result = collect(for i in 1..9: WorkspaceIcon(id: i, icon:"",class:fmt"ws-button-{i - 1}")) for client in clients: - let match = icons.getOrDefault(client.class,"") + let match = icons.getOrDefault($(client.class),"") if client.workspace.id < 0: continue result[client.workspace.id - 1].icon &= match for ws in result.mitems: @@ -84,5 +88,5 @@ when isMainModule: sleep 500 try: echo (%* getState()) - except JsonParsingError: - discard + except JsonParsingError as e: + writeLine(stderr, e.msg)