diff postdog/main.c @ 153:790930d9bb90

[PostDog] Adding websocket to be more usable.
author June Park <parkjune1995@gmail.com>
date Sun, 11 Jan 2026 08:11:24 -0800
parents 7387eec8e7f8
children 3bb45eb67906
line wrap: on
line diff
--- a/postdog/main.c	Sun Jan 11 07:47:05 2026 -0800
+++ b/postdog/main.c	Sun Jan 11 08:11:24 2026 -0800
@@ -79,6 +79,7 @@
 int active_method_dropdown = 0;
 int active_input_tab = 0;
 Seobeo_WebSocket *ws = NULL;
+boolean WS_BREAK = FALSE;
 
 int CompareHistoryItemsByDate(const void *a, const void *b) {
   HistoryItem *itemA = (HistoryItem *)a;
@@ -290,17 +291,19 @@
     printf("Failed to send message\n");
 
   printf("Receiving responses...\n");
-
   int received = 0;
   while (TRUE)
   {
+    if (WS_BREAK) break;
+
     Seobeo_WebSocket_Message *p_msg = Seobeo_WebSocket_Receive(ws);
     if (p_msg)
     {
       if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT)
       {
         printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data);
-        snprintf(url_result_text, RESULT_BUFFER_LENGTH, "%s", p_msg->data);
+        snprintf(url_result_text + strlen(url_result_text),  RESULT_BUFFER_LENGTH - strlen(url_result_text), 
+            "\n%s", (char*)p_msg->data);
         received++;
       }
       Seobeo_WebSocket_Message_Destroy(p_msg);
@@ -308,16 +311,17 @@
     usleep(10000);
   }
   printf("Received %d/%d messages\n", received, 3);
+  Seobeo_WebSocket_Destroy(ws);
 }
 
-void* PostDog_Websocket_Thread(void* arg)
+void *PostDog_Websocket_Thread(void *arg)
 {
-    PostDog_Websocket_Send();
-    printf("Websocket request finished.\n");
-    return NULL;
+  PostDog_Websocket_Send();
+  printf("Websocket request finished.\n");
+  return NULL;
 }
 
-void Trigger_Async_Send()
+void PostDog_Websocket_Thread_Send()
 {
   pthread_t thread_id;
   
@@ -602,7 +606,7 @@
 
   Font customFont = LoadFontEx("postdog/Roboto-Regular.ttf", 20, 0, 0);
   GuiSetFont(customFont);
-  GuiSetStyle(DEFAULT, TEXT_SIZE, 10);
+  GuiSetStyle(DEFAULT, TEXT_SIZE, 15);
   Image logo_original = LoadImage("postdog/epi_all_colors.png");
   ImageResize(&logo_original, 60, 60);
   SetWindowIcon(logo_original);
@@ -901,15 +905,19 @@
         scrolled_input.height = MAX_SCROLL_HEIGHT;
         if (active_input_tab != TAB_WEBSOCKET)
         {
+          WS_BREAK = TRUE;
           if (JUNE_GuiTextBox(scrolled_input, url_body_map[active_input_tab], DEFAULT_TEXT_BUFFER_LENGTH, input_body_bool))
             input_body_bool = !input_body_bool;
         }
         else
         {
           boolean temp = true;
-          if (GuiTextInputBox(input_body, "send message", "connected", 
-              "send", url_body_map[active_input_tab], BODY_BUFFER_LENGTH, &temp) == 1)
-            Trigger_Async_Send();
+          WS_BREAK = FALSE;
+          if (GuiTextInputBox(
+                input_body,
+                "send message", ws != NULL ? "connected" : "start messaging",
+                "send", url_body_map[active_input_tab], BODY_BUFFER_LENGTH, &temp) == 1)
+            PostDog_Websocket_Thread_Send();
         }
       EndScissorMode();