mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 23:43:02 +08:00
refactor(config): 引入 ConfigPath 值对象消除 ConfigType/ConfigKey 的消费者 API 冗余
This commit is contained in:
@@ -24,6 +24,7 @@ import managers.config.ConfigManager as ConfigManager
|
||||
|
||||
from utils.JSONReader import JSONReader
|
||||
from utils.JSONWriter import JSONWriter
|
||||
from interfaces.ConfigProvider import ConfigProvider, CfgKey
|
||||
from managers.config.ConfigUtils import ConfigUtils
|
||||
|
||||
from gui.resources.ui.Ui_ALConfigWidget import Ui_ALConfigWidget
|
||||
@@ -43,7 +44,7 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
):
|
||||
|
||||
super().__init__(parent)
|
||||
self.__cfg_mgr = ConfigManager.instance()
|
||||
self.__cfg_mgr: ConfigProvider = ConfigManager.instance()
|
||||
self.__config_paths = ConfigUtils.getAutomationConfigPaths()
|
||||
self.__config_data = {"run": {}, "user": {}}
|
||||
|
||||
@@ -985,13 +986,13 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
self.setRunConfigToWidget(data)
|
||||
self.__config_paths["run"] = run_config_path
|
||||
self.CurrentRunConfigEdit.setText(run_config_path)
|
||||
paths = self.__cfg_mgr.get(ConfigManager.ConfigType.GLOBAL, "automation.run_path.paths", [])
|
||||
paths = self.__cfg_mgr.get(CfgKey.GLOBAL.AUTOMATION.RUN_PATH.PATHS, [])
|
||||
if run_config_path not in paths:
|
||||
paths.append(run_config_path)
|
||||
index = len(paths) - 1
|
||||
else:
|
||||
index = paths.index(run_config_path)
|
||||
self.__cfg_mgr.set(ConfigManager.ConfigType.GLOBAL, "automation.run_path", {"current": index, "paths": paths})
|
||||
self.__cfg_mgr.set(CfgKey.GLOBAL.AUTOMATION.RUN_PATH.ROOT, {"current": index, "paths": paths})
|
||||
else:
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
@@ -1020,13 +1021,13 @@ class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
self.setUsersToTreeWidget(data)
|
||||
self.__config_paths["user"] = user_config_path
|
||||
self.CurrentUserConfigEdit.setText(user_config_path)
|
||||
paths = self.__cfg_mgr.get(ConfigManager.ConfigType.GLOBAL, "automation.user_path.paths", [])
|
||||
paths = self.__cfg_mgr.get(CfgKey.GLOBAL.AUTOMATION.USER_PATH.PATHS, [])
|
||||
if user_config_path not in paths:
|
||||
paths.append(user_config_path)
|
||||
index = len(paths) - 1
|
||||
else:
|
||||
index = paths.index(user_config_path)
|
||||
self.__cfg_mgr.set(ConfigManager.ConfigType.GLOBAL, "automation.user_path", {"current": index, "paths": paths})
|
||||
self.__cfg_mgr.set(CfgKey.GLOBAL.AUTOMATION.USER_PATH.ROOT, {"current": index, "paths": paths})
|
||||
else:
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
|
||||
@@ -26,7 +26,9 @@ from PySide6.QtGui import (
|
||||
)
|
||||
|
||||
import managers.config.ConfigManager as ConfigManager
|
||||
|
||||
from utils.TimerUtils import TimerUtils
|
||||
from interfaces.ConfigProvider import ConfigProvider, CfgKey
|
||||
|
||||
from gui.resources.ui.Ui_ALTimerTaskManageWidget import Ui_ALTimerTaskManageWidget
|
||||
from gui.ALTimerTaskAddDialog import ALTimerTaskAddDialog, ALTimerTaskStatus
|
||||
@@ -190,7 +192,7 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
):
|
||||
|
||||
super().__init__(parent)
|
||||
self.__cfg_mgr = ConfigManager.instance()
|
||||
self.__cfg_mgr: ConfigProvider = ConfigManager.instance()
|
||||
self.__timer_tasks = []
|
||||
self.__check_timer = None
|
||||
self.__sort_policy = self.SortPolicy.BY_EXECUTE_TIME
|
||||
@@ -244,7 +246,7 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
) -> list:
|
||||
|
||||
try:
|
||||
timer_tasks = self.__cfg_mgr.get(ConfigManager.ConfigType.TIMERTASK)
|
||||
timer_tasks = self.__cfg_mgr.get(CfgKey.TIMERTASK.ROOT)
|
||||
if timer_tasks and "timer_tasks" in timer_tasks:
|
||||
for task in timer_tasks["timer_tasks"]:
|
||||
task["added_time"] = datetime.strptime(task["added_time"], "%Y-%m-%d %H:%M:%S")
|
||||
@@ -277,7 +279,7 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
if "repeat_history" in task:
|
||||
for item in task["repeat_history"]:
|
||||
item["result"] = item["result"].value
|
||||
self.__cfg_mgr.set(ConfigManager.ConfigType.TIMERTASK, "", { "timer_tasks": timer_tasks })
|
||||
self.__cfg_mgr.set(CfgKey.TIMERTASK.ROOT, { "timer_tasks": timer_tasks })
|
||||
return True
|
||||
except Exception as e:
|
||||
QMessageBox.warning(
|
||||
@@ -437,7 +439,7 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
||||
f"下次执行时间:{datetime.strftime(timer_task["execute_time"], "%Y-%m-%d %H:%M:%S")}\n"
|
||||
f"已记录次数:{history_count}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
def deleteTask(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user