Skip to content

Commit

Permalink
update automator
Browse files Browse the repository at this point in the history
  • Loading branch information
vyokky committed Jul 6, 2024
1 parent f96901f commit c8e0504
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions ufo/automator/puppeteer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_command(
:param command_name: The command name.
:param params: The arguments for the command.
"""
receiver = self.receiver_manager.get_receiver(command_name)
receiver = self.receiver_manager.get_receiver_from_command_name(command_name)
command = receiver.command_registry.get(command_name.lower(), None)

if receiver is None:
Expand All @@ -56,7 +56,7 @@ def get_command_types(self, command_name: str) -> str:
:param command_name: The command name.
:return: The command types.
"""
receiver = self.receiver_manager.get_receiver(command_name)
receiver = self.receiver_manager.get_receiver_from_command_name(command_name)

return receiver.type_name

Expand Down Expand Up @@ -182,11 +182,11 @@ def create_ui_control_receiver(
:param control: The control element.
:return: The UI controller receiver.
"""
factory: ReceiverFactory = self._receiver_factory_registry.get("UIControl").get(
factory: ReceiverFactory = self.receiver_factory_registry.get("UIControl").get(
"factory"
)
self.ui_control_receiver = factory.create_receiver(control, application)
self._receiver_list.append(self.ui_control_receiver)
self.receiver_list.append(self.ui_control_receiver)
self._update_receiver_registry()

return self.ui_control_receiver
Expand All @@ -197,15 +197,15 @@ def create_api_receiver(self, app_root_name: str, process_name: str) -> None:
:param app_root_name: The app root name.
:param process_name: The process name.
"""
for receiver_factory_dict in self._receiver_factory_registry.values():
for receiver_factory_dict in self.receiver_factory_registry.values():

# Check if the receiver is API
if receiver_factory_dict.get("is_api"):
receiver = receiver_factory_dict.get("factory").create_receiver(
app_root_name, process_name
)
if receiver is not None:
self._receiver_list.append(receiver)
self.receiver_list.append(receiver)

self._update_receiver_registry()

Expand All @@ -214,11 +214,11 @@ def _update_receiver_registry(self) -> None:
Update the receiver registry. A receiver registry is a dictionary that maps the command name to the receiver.
"""

for receiver in self._receiver_list:
for receiver in self.receiver_list:
if receiver is not None:
self.receiver_registry.update(receiver.self_command_mapping())

def get_receiver(self, command_name: str) -> ReceiverBasic:
def get_receiver_from_command_name(self, command_name: str) -> ReceiverBasic:
"""
Get the receiver from the command name.
:param command_name: The command name.
Expand All @@ -229,13 +229,31 @@ def get_receiver(self, command_name: str) -> ReceiverBasic:
raise ValueError(f"Receiver for command {command_name} is not found.")
return receiver

@property
def receiver_list(self) -> List[ReceiverBasic]:
"""
Get the receiver list.
:return: The receiver list.
"""
return self._receiver_list

@property
def receiver_factory_registry(
self,
) -> Dict[str, Dict[str, Union[str, ReceiverFactory]]]:
"""
Get the receiver factory registry.
:return: The receiver factory registry.
"""
return self._receiver_factory_registry

@property
def com_receiver(self) -> WinCOMReceiverBasic:
"""
Get the COM receiver.
:return: The COM receiver.
"""
for receiver in self._receiver_list:
for receiver in self.receiver_list:
if issubclass(receiver.__class__, WinCOMReceiverBasic):
return receiver

Expand Down

0 comments on commit c8e0504

Please sign in to comment.