Pārlūkot izejas kodu

fix(SplitPanel): Add null checks for content loaders to prevent errors
fix(TaskList): Enhance error handling for JSON parsing of task list and menu
fix(script_task): Update configuration to use 'oas1' instead of 'mi'

Migs 11 mēneši atpakaļ
vecāks
revīzija
3e6bde70b3

+ 15 - 0
module/gui/qml/Component/SplitPanel.qml

@@ -37,6 +37,9 @@ Item {
         anchors.bottomMargin: 12
 
         onLoaded: {
+            if (!contentDefalut.item)
+                return
+
             if(typeof contentDefalut.item.splitPanel === "undefined"){
                 return
             }
@@ -113,6 +116,10 @@ Item {
 //    }
     //设置右边显示的参数项,输入的序列的字符串
     function setLoaderData(args, value){
+        if (!contentLoader.item) {
+            console.log("SplitPanel: contentLoader.item is null in setLoaderData")
+            return
+        }
         contentLoader.item.argsData = args
         contentLoader.item.valueData = value
         contentLoader.item.updataData()
@@ -120,12 +127,20 @@ Item {
 
     //设置上下文
     function setLoaderContext(configName, taskName){
+        if (!contentLoader.item) {
+            console.log("SplitPanel: contentLoader.item is null in setLoaderContext")
+            return
+        }
         contentLoader.item.configName = configName
         contentLoader.item.taskName = taskName
     }
 
     //设置配置的名称
     function setDefalutConfig(name){
+        if (!contentDefalut.item) {
+            console.log("SplitPanel: contentDefalut.item is null in setDefalutConfig")
+            return
+        }
         contentDefalut.item.configName = name
     }
 

+ 24 - 3
module/gui/qml/Content/TaskList.qml

@@ -143,8 +143,29 @@ Item{
 
     Component.onCompleted:{
 
-        const data = JSON.parse(process_manager.gui_task_list(MainEvent.scriptName))
-        const menu = JSON.parse(process_manager.gui_menu())
+        var rawTaskList = process_manager.gui_task_list(MainEvent.scriptName)
+        var rawMenu     = process_manager.gui_menu()
+
+        console.log("TaskList rawTaskList =", rawTaskList)
+        console.log("TaskList rawMenu =", rawMenu)
+
+        var data = {}
+        var menu = {}
+
+        try {
+            data = JSON.parse(rawTaskList)
+        } catch (e) {
+            console.error("TaskList: JSON.parse task_list error:", e, "raw =", rawTaskList)
+            return   // 解析失败就不要往下走了
+        }
+
+        try {
+            menu = JSON.parse(rawMenu)
+        } catch (e) {
+            console.error("TaskList: JSON.parse menu error:", e, "raw =", rawMenu)
+            return
+        }
+
         for(const key in menu){
             if(key === "Overview" || key === 'TaskList' || key === 'Script' || key === 'Tools'){
                 continue
@@ -152,9 +173,9 @@ Item{
             const groupData = classify(menu[key], data)
             create_group(key, groupData)
         }
-
     }
 
+
     // 分类对每一个任务组,
     // 第一个参数是这个菜单组的所有, 如["Script", "Restart", "GlobalGame"]
     // 第二个参数是整个的数据

+ 1 - 2
tasks/Duel/script_task.py

@@ -474,8 +474,7 @@ class ScriptTask(GameUi, GeneralBattle, SwitchSoul, DuelAssets):
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
-
-    c = Config('mi')
+    c = Config('oas1')
     d = Device(c)
     t = ScriptTask(c, d)