fix: fetch full message

This commit is contained in:
Daylin Morgan 2024-01-28 12:13:30 -06:00
parent b09816b7b7
commit 44633f082f
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -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)
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)