diff --git a/include/MaaFramework/Instance/MaaTasker.h b/include/MaaFramework/Instance/MaaTasker.h index b25a3382f..369eec85f 100644 --- a/include/MaaFramework/Instance/MaaTasker.h +++ b/include/MaaFramework/Instance/MaaTasker.h @@ -89,7 +89,8 @@ extern "C" MaaTaskId task_id, /* out */ MaaStringBuffer* entry, /* out */ MaaNodeId* node_id_list /**< array */, - /* in & out */ MaaSize* node_id_list_size); + /* in & out */ MaaSize* node_id_list_size, + /* out */ MaaStatus* status); /** * @param[out] latest_id diff --git a/source/MaaFramework/API/MaaTasker.cpp b/source/MaaFramework/API/MaaTasker.cpp index 8ad715fe9..68879868e 100644 --- a/source/MaaFramework/API/MaaTasker.cpp +++ b/source/MaaFramework/API/MaaTasker.cpp @@ -267,7 +267,8 @@ MaaBool MaaTaskerGetTaskDetail( MaaTaskId task_id, MaaStringBuffer* entry, MaaNodeId* node_id_list, - MaaSize* node_id_list_size) + MaaSize* node_id_list_size, + MaaStatus* status) { if (!tasker) { LogError << "handle is null"; @@ -300,6 +301,11 @@ MaaBool MaaTaskerGetTaskDetail( return false; } + CheckNullAndWarn(status) + { + *status = tasker->status(task_id); + } + return true; } diff --git a/source/binding/Python/maa/define.py b/source/binding/Python/maa/define.py index 42ea22c8f..896763fd5 100644 --- a/source/binding/Python/maa/define.py +++ b/source/binding/Python/maa/define.py @@ -330,6 +330,28 @@ class MaaCustomControllerCallbacks(ctypes.Structure): ] +class Status: + _status: MaaStatusEnum + + def __init__(self, status: Union[MaaStatus, MaaStatusEnum]): + self._status = MaaStatusEnum(status) + + def done(self) -> bool: + return self._status in [MaaStatusEnum.succeeded, MaaStatusEnum.failed] + + def succeeded(self) -> bool: + return self._status == MaaStatusEnum.succeeded + + def failed(self) -> bool: + return self._status == MaaStatusEnum.failed + + def pending(self) -> bool: + return self._status == MaaStatusEnum.pending + + def running(self) -> bool: + return self._status == MaaStatusEnum.running + + @dataclass class Rect: x: int = 0 @@ -487,6 +509,7 @@ class TaskDetail: task_id: int entry: str nodes: List[NodeDetail] + status: Status class LoggingLevelEnum(IntEnum): diff --git a/source/binding/Python/maa/job.py b/source/binding/Python/maa/job.py index 93658cd45..54955a434 100644 --- a/source/binding/Python/maa/job.py +++ b/source/binding/Python/maa/job.py @@ -1,30 +1,6 @@ -from typing import Union - from .define import * -class Status: - _status: MaaStatusEnum - - def __init__(self, status: Union[MaaStatus, MaaStatusEnum]): - self._status = MaaStatusEnum(status) - - def done(self) -> bool: - return self._status in [MaaStatusEnum.succeeded, MaaStatusEnum.failed] - - def succeeded(self) -> bool: - return self._status == MaaStatusEnum.succeeded - - def failed(self) -> bool: - return self._status == MaaStatusEnum.failed - - def pending(self) -> bool: - return self._status == MaaStatusEnum.pending - - def running(self) -> bool: - return self._status == MaaStatusEnum.running - - class Job: job_id: MaaId diff --git a/source/binding/Python/maa/tasker.py b/source/binding/Python/maa/tasker.py index 24d2bcc42..1b7d204df 100644 --- a/source/binding/Python/maa/tasker.py +++ b/source/binding/Python/maa/tasker.py @@ -283,6 +283,7 @@ def get_node_detail(self, node_id: int) -> Optional[NodeDetail]: def get_task_detail(self, task_id: int) -> Optional[TaskDetail]: size = MaaSize() entry = StringBuffer() + status = MaaStatus() ret = bool( Library.framework.MaaTaskerGetTaskDetail( self._handle, @@ -290,6 +291,7 @@ def get_task_detail(self, task_id: int) -> Optional[TaskDetail]: entry._handle, None, ctypes.pointer(size), + ctypes.pointer(status), ) ) if not ret: @@ -303,6 +305,7 @@ def get_task_detail(self, task_id: int) -> Optional[TaskDetail]: entry._handle, c_node_id_list, ctypes.pointer(size), + ctypes.pointer(status), ) ) if not ret: @@ -313,7 +316,7 @@ def get_task_detail(self, task_id: int) -> Optional[TaskDetail]: detail = self.get_node_detail(int(c_node_id_list[i])) nodes.append(detail) - return TaskDetail(task_id=task_id, entry=entry.get(), nodes=nodes) + return TaskDetail(task_id=task_id, entry=entry.get(), nodes=nodes, status=Status(status)) _api_properties_initialized: bool = False @@ -433,6 +436,7 @@ def _set_api_properties(): MaaStringBufferHandle, ctypes.POINTER(MaaRecoId), ctypes.POINTER(MaaSize), + ctypes.POINTER(MaaStatus), ] Library.framework.MaaTaskerGetLatestNode.restype = MaaBool