文本更新用post更新,优化ws断连标志位更新
authorluozheng <1732036298@qq.com>
Mon, 29 Sep 2025 02:45:31 +0000 (10:45 +0800)
committerluozheng <1732036298@qq.com>
Mon, 29 Sep 2025 02:45:31 +0000 (10:45 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp
code/sdk/zhihui/leiniao/imsl_ln/ln_api.c
code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp

index 4e87f19..1c8fbc3 100644 (file)
@@ -61,6 +61,7 @@ typedef enum {
     HAND_API_ERROR_NOTIFY, // 协议错误通知
     HAND_BIND_AND_UNBIND_NOTIFY, // 绑定和解绑通知
     HAND_SCREEN_IMAGE_DOWNLOAD_SUCCESS_NOTIFY, // 屏保下载成功通知
+    HAND_TEXT_UPDATE_NOTIFY, // 更新文本内容通知
     MAX_NUM_HANDLER, 
 } UiServiceMsgId;
 
index 2ae1307..4567bc6 100644 (file)
      
      void ThunderBirdModel::SetTextStr(const char *textId)
      {
-         if (textId == nullptr) {
-             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置对话文本: textId is null");
-             return;
-         }
-         ThunderBirdDialogueView::GetInstance()->UpdateDialogueText(m_currentTimeStr.c_str());
-         //清除录音内容
-         ClearTextStr();
-         
-         // 添加文本内容
-         m_currentTimeStr = textId;
-         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置对话文本: %s", m_currentTimeStr.c_str());
+        if (textId == nullptr) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置对话文本: textId is null");
+            return;
+        }
+        if(ThunderBirdDialogueView::GetInstance())
+            ThunderBirdDialogueView::GetInstance()->UpdateDialogueText(m_currentTimeStr.c_str());
+        //清除录音内容
+        ClearTextStr();
+        
+        // 添加文本内容
+        m_currentTimeStr = textId;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设置对话文本: %s", m_currentTimeStr.c_str());
      }
      
      void ThunderBirdModel::ClearTextStr()
index d7307d7..4d542c8 100644 (file)
@@ -97,6 +97,7 @@ static void HandDownloadEmojiNotify(Request *request);
 static void HandApiErrorNotify(Request *request);
 static void HandBindAndUnbindNotify(Request *request);
 static void HandScreenImageDownloadSuccessNotify(Request *request);
+static void HandTextUpdateNotify(Request *request);
 // 消息处理程序项数组(每个消息类型对应一个处理函数,函数名以 Handle 开头)
 MsgHandlerEntry msgHandlers[] = {
     {HANDLE_JUMP_OTA_VIEW, HandleJumpOtaView},
@@ -110,6 +111,7 @@ MsgHandlerEntry msgHandlers[] = {
     {HAND_API_ERROR_NOTIFY,HandApiErrorNotify},
     {HAND_BIND_AND_UNBIND_NOTIFY,HandBindAndUnbindNotify},
     {HAND_SCREEN_IMAGE_DOWNLOAD_SUCCESS_NOTIFY,HandScreenImageDownloadSuccessNotify},
+    {HAND_TEXT_UPDATE_NOTIFY,HandTextUpdateNotify},
 };
 /* -------------------------------------------------------------------------- */
 void ScreenTurnOn(int32_t timeout)
@@ -540,6 +542,14 @@ void HandScreenImageDownloadSuccessNotify(Request *request)
     //     std::bind(&OHOS::ThunderBirdModel::HandleScreenImageDownloadSuccess,OHOS::ThunderBirdModel::GetInstance()));
 }
 
+// 更新文本内容通知
+void HandTextUpdateNotify(Request *request)
+{
+    std::string value(static_cast<char*>(request->data), request->len);
+    GraphicService::GetInstance()->PostGraphicEvent(
+        std::bind(&OHOS::ThunderBirdModel::SetTextStr,OHOS::ThunderBirdModel::GetInstance(),value.c_str()));
+}
+
 /* -------------------------------------------------------------------------- */
 #ifdef __cplusplus
 }
index 9f0a85e..89197ce 100644 (file)
@@ -412,12 +412,12 @@ void ln_ws_process_message(const ws_data_msg_t *data_msg, ws_command_t type)
         printf("[LN][WS] Processing WebSocket Connected event\n");
         set_is_ln_get_device_network_success(1);
     }
-    else
+    else if(type == WS_CMD_DISCONNECTED)
     {
         printf("[LN][WS] Processing WebSocket Disconnected event\n");
         set_is_ln_get_device_network_success(0);
     }
-
+    
     if (!data_msg || !data_msg->raw_json)
     {
         printf("[WS] invalid data message\n");
index febdf30..946c434 100644 (file)
@@ -19,7 +19,7 @@ extern "C"
 // 推送文本给ui
 void push_text_to_ui(const char *text)
 {
-    OHOS::ThunderBirdModel::GetInstance()->SetTextStr(text);
+    SendMsgToUIService(HAND_TEXT_UPDATE_NOTIFY, 0, (void *)text, (int32_t)strlen(text));
 }
 // 是否开始对话标志:开始对话、结束对话、故事开始、故事结束
 static int g_start_conversation_flag = START_CONVERSATION_FLAG_UNKNOWN;