Skip to content

Commit

Permalink
fix: handle program exit and improve resource data handling in RetiBB…
Browse files Browse the repository at this point in the history
…SClient
  • Loading branch information
kc1awv committed Jan 17, 2025
1 parent 9c5c445 commit ed81d68
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion client/retibbs_textual.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ async def action_quit(self) -> None:
except Exception as e:
self.write_debug_log(f"[QUIT] Error during cleanup: {e}")
finally:
try:
RNS.exit()
except SystemExit:
self.write_debug_log("[QUIT] Program exited via Reticulum.")
self.exit()

def action_show_help(self):
Expand Down Expand Up @@ -426,7 +430,10 @@ def on_link_closed(self, link):
self.write_log("Disconnected from the RetiBBS server.")

def on_resource_started(self, resource):
self.write_log(f"[RESOURCE] Started: {resource.id} (size={resource.size})")
input_box = self.query_one("#command_input", Input)
input_box.disabled = True
input_box.placeholder = "Receiving Data..."
#DEBUG: self.write_debug_log(f"[RESOURCE] Started (size={resource.size})")

def on_resource_concluded(self, resource):
if resource.data is not None:
Expand All @@ -436,11 +443,17 @@ def on_resource_concluded(self, resource):
data = fileobj.read()
text = data.decode("utf-8", "ignore")
self.write_log(f"{text}")
#DEBUG: self.write_debug_log(f"[RESOURCE] Received data (size={resource.size})")
except Exception as e:
self.write_log(f"[RESOURCE] Error processing resource data: {e}")
else:
self.write_log("Transfer concluded, but no data received!")

input_box = self.query_one("#command_input", Input)
input_box.disabled = False
input_box.placeholder = "Enter command..."
input_box.focus()

def on_packet_received(self, message_bytes, packet):
if message_bytes == b"PONG":
self.last_pong_time = time.time()
Expand Down

0 comments on commit ed81d68

Please sign in to comment.