解决哄睡不显示文本Bug
authorxue <2144439972@qq.com>
Thu, 13 Nov 2025 09:20:57 +0000 (17:20 +0800)
committerxue <2144439972@qq.com>
Thu, 13 Nov 2025 09:20:57 +0000 (17:20 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h
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/imsl_ln/ln_api_websocket.c
code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp
code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h

index c950878..d7e8d9f 100644 (file)
@@ -73,6 +73,8 @@ typedef enum {
     HAND_NPC_EMOTION_CHANGE_NOTIFY, // npc表情变化通知
     HAND_TIMELINE_STATUS_CHANGE_NOTIFY, // 时间线状态变化通知
     HAND_UPGRADE_DESCRIPTION_NOTIFY, // 升级描述通知
+    HAND_STORY_RESPONSE_FINISHED_NOTIFY, // 故事响应finished通知
+    HAND_DIALOGUE_RESPONSE_FINISHED_NOTIFY, // 对话响应finished通知
     MAX_NUM_HANDLER, 
 } UiServiceMsgId;
 
index ca8643d..a23ea28 100644 (file)
@@ -109,6 +109,8 @@ static void HandAudioRecordingEndNotify(Request *request);
 static void HandNpcEmotionChangeNotify(Request *request);
 static void HandTimelineStatusChangeNotify(Request *request);
 static void HandUpgradeDescriptionNotify(Request *request);
+static void HandStoryResponseFinishedNotify(Request *request);
+static void HandDialogueResponseFinishedNotify(Request *request);
 // 消息处理程序项数组(每个消息类型对应一个处理函数,函数名以 Handle 开头)
 MsgHandlerEntry msgHandlers[] = {
     {HANDLE_JUMP_OTA_VIEW, HandleJumpOtaView},
@@ -134,6 +136,8 @@ MsgHandlerEntry msgHandlers[] = {
     {HAND_NPC_EMOTION_CHANGE_NOTIFY,HandNpcEmotionChangeNotify},
     {HAND_TIMELINE_STATUS_CHANGE_NOTIFY,HandTimelineStatusChangeNotify},
     {HAND_UPGRADE_DESCRIPTION_NOTIFY,HandUpgradeDescriptionNotify},
+    {HAND_STORY_RESPONSE_FINISHED_NOTIFY,HandStoryResponseFinishedNotify},
+    {HAND_DIALOGUE_RESPONSE_FINISHED_NOTIFY,HandDialogueResponseFinishedNotify},
 };
 /* -------------------------------------------------------------------------- */
 void ScreenTurnOn(int32_t timeout)
@@ -788,6 +792,30 @@ void HandUpgradeDescriptionNotify(Request *request)
     GraphicService::GetInstance()->PostGraphicEvent(
         std::bind(&OHOS::OtaModel::SetUpgradeDescription,OHOS::OtaModel::GetInstance(), description));
 }
+
+void HandStoryResponseFinishedNotify(Request *request)
+{
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandStoryResponseFinishedNotify msg_id = %d", request->msgId);
+    if (request->data && request->len == sizeof(bool)) {
+        bool finished = *(static_cast<bool*>(request->data));
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandStoryResponseFinishedNotify finished = %d", finished);
+            GraphicService::GetInstance()->PostGraphicEvent(
+                std::bind(&OHOS::ThunderBirdModel::HandleStoryResponseFinished, 
+                         OHOS::ThunderBirdModel::GetInstance(), finished));
+    }
+}
+
+void HandDialogueResponseFinishedNotify(Request *request)
+{
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandDialogueResponseFinishedNotify msg_id = %d", request->msgId);
+    if (request->data && request->len == sizeof(bool)) {
+        bool finished = *(static_cast<bool*>(request->data));
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandDialogueResponseFinishedNotify finished = %d", finished);
+            GraphicService::GetInstance()->PostGraphicEvent(
+                std::bind(&OHOS::ThunderBirdModel::HandleDialogueResponseFinished, 
+                         OHOS::ThunderBirdModel::GetInstance(), finished));
+    }
+}
 /* -------------------------------------------------------------------------- */
 #ifdef __cplusplus
 }
index 548ffc5..caf1682 100644 (file)
@@ -1080,16 +1080,28 @@ void ln_ws_process_message(const ws_data_msg_t *data_msg, ws_command_t type)
         {
             ln_parse_voice_chat_response(json_str, (int)strlen(json_str));
         }
+        // 如果finished=true,通知ThunderBirdModel
+        if (data_msg && data_msg->finished) {
+            push_dialogue_response_finished_notification(true);
+        }
         break;
     }
     case WS_CMD_CHOOSE_STORY_RESPONSE:
     {
         push_text_to_ui(data_msg->text_content);
-        break;
+        // 如果finished=true,通知ThunderBirdModel
+        if (data_msg && data_msg->finished) {
+            push_story_response_finished_notification(true);
+        }
+         break;
     }
     case WS_CMD_RANDOM_STORY_RESPONSE:
     {
         push_text_to_ui(data_msg->text_content);
+        // 如果finished=true,通知ThunderBirdModel
+        if (data_msg && data_msg->finished) {
+            push_story_response_finished_notification(true);
+        }
         break;
     }
     case WS_CMD_AUDIO_PLAYBACK_START:
index d3d362d..ed80b6b 100644 (file)
@@ -1818,10 +1818,18 @@ static int ln_ws_parse_data_message(const char *json_str, ws_data_msg_t *data_ms
             cJSON *data_data = cJSON_GetObjectItem(data_obj, "data");
             if (data_data && cJSON_IsObject(data_data)) {
                 // 解析storyTheme字段,存储到text_content中
-                cJSON *story_theme = cJSON_GetObjectItem(data_data, "storyTheme");
-                if (story_theme && cJSON_IsString(story_theme) && story_theme->valuestring) {
-                    strncpy(data_msg->text_content, story_theme->valuestring, sizeof(data_msg->text_content) - 1);
-                    data_msg->text_content[sizeof(data_msg->text_content) - 1] = '\0';
+                // cJSON *story_theme = cJSON_GetObjectItem(data_data, "storyTheme");
+                // if (story_theme && cJSON_IsString(story_theme) && story_theme->valuestring) {
+                //     strncpy(data_msg->text_content, story_theme->valuestring, sizeof(data_msg->text_content) - 1);
+                //     data_msg->text_content[sizeof(data_msg->text_content) - 1] = '\0';
+                // }
+                cJSON *story_content = cJSON_GetObjectItem(data_data, "storyContent");
+                if (story_content && cJSON_IsString(story_content) && story_content->valuestring) {
+                    // 如果text_content为空,使用storyContent填充
+                    if (strlen(data_msg->text_content) == 0) {
+                        strncpy(data_msg->text_content, story_content->valuestring, sizeof(data_msg->text_content) - 1);
+                        data_msg->text_content[sizeof(data_msg->text_content) - 1] = '\0';
+                    }
                 }
                 
                 // 解析storyAudioUrl字段,存储到audio_url中
index 109ef3c..22ec664 100644 (file)
@@ -291,11 +291,12 @@ void push_npc_emotion_change_notification(const char *emotion)
 //通知时间线状态变化
 void push_timeline_status_change_notification(const char *description, const char *emotion)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TIMELINE_STATUS_CHANGE] description=%s, emotion=%s", description, emotion);
-    char payload[512] = {0};
     const char *d = description ? description : "";
     const char *e = emotion ? emotion : "";
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TIMELINE_STATUS_CHANGE] description=[%s], emotion=[%s]", d, e);
+    char payload[512] = {0};
     (void)snprintf(payload, sizeof(payload) - 1, "%s|%s", d, e);
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[TIMELINE_STATUS_CHANGE] payload=[%s], len=%d", payload, (int)strlen(payload));
     SendMsgToUIService(HAND_TIMELINE_STATUS_CHANGE_NOTIFY, 0, (void *)payload, (int32_t)strlen(payload));
 }
 
@@ -308,6 +309,20 @@ void push_upgrade_description_notification(const char *description)
     (void)snprintf(payload, sizeof(payload) - 1, "%s", d);
     SendMsgToUIService(HAND_UPGRADE_DESCRIPTION_NOTIFY, 0, (void *)payload, (int32_t)strlen(payload));
 }
+
+//通知故事响应finished
+void push_story_response_finished_notification(bool finished)
+{
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[STORY_RESPONSE_FINISHED] finished=%d", finished);
+    SendMsgToUIService(HAND_STORY_RESPONSE_FINISHED_NOTIFY, 0, &finished, sizeof(finished));
+}
+
+//通知对话响应finished
+void push_dialogue_response_finished_notification(bool finished)
+{
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DIALOGUE_RESPONSE_FINISHED] finished=%d", finished);
+    SendMsgToUIService(HAND_DIALOGUE_RESPONSE_FINISHED_NOTIFY, 0, &finished, sizeof(finished));
+}
 #ifdef __cplusplus
 };
 #endif
\ No newline at end of file
index e6cccc3..1ca3442 100644 (file)
@@ -113,6 +113,10 @@ void push_npc_emotion_change_notification(const char *emotion);
 void push_timeline_status_change_notification(const char *description, const char *emotion);
 //推送升级描述
 void push_upgrade_description_notification(const char *description);
+//通知故事响应finished
+void push_story_response_finished_notification(bool finished);
+//通知对话响应finished
+void push_dialogue_response_finished_notification(bool finished);
 #ifdef __cplusplus
 }
 #endif