|
7 | 7 | from typing import Literal, Type |
8 | 8 |
|
9 | 9 | import grpc |
| 10 | +from google.protobuf.json_format import MessageToDict |
10 | 11 | from PIL import Image |
11 | 12 | from typing_extensions import Self, override |
12 | 13 |
|
13 | 14 | from askui.container import telemetry |
14 | 15 | from askui.logger import logger |
15 | 16 | from askui.reporting import Reporter |
16 | | -from askui.tools.agent_os import AgentOs, Coordinate, ModifierKey, PcKey |
| 17 | +from askui.tools.agent_os import ( |
| 18 | + AgentOs, |
| 19 | + Coordinate, |
| 20 | + Display, |
| 21 | + DisplaysListResponse, |
| 22 | + ModifierKey, |
| 23 | + PcKey, |
| 24 | +) |
17 | 25 | from askui.tools.askui.askui_controller_settings import AskUiControllerSettings |
18 | 26 | from askui.tools.askui.askui_ui_controller_grpc.generated import ( |
19 | 27 | Controller_V1_pb2 as controller_v1_pbs, |
@@ -626,28 +634,49 @@ def run_command(self, command: str, timeout_ms: int = 30000) -> None: |
626 | 634 | ) |
627 | 635 |
|
628 | 636 | @telemetry.record_call() |
629 | | - def get_display_information( |
| 637 | + @override |
| 638 | + def retrieve_active_display(self) -> Display: |
| 639 | + """ |
| 640 | + Retrieve the currently active display/screen. |
| 641 | +
|
| 642 | + Returns: |
| 643 | + Display: The currently active display/screen. |
| 644 | + """ |
| 645 | + self._reporter.add_message("AgentOS", "retrieve_active_display()") |
| 646 | + displays_list_response = self.list_displays() |
| 647 | + for display in displays_list_response.data: |
| 648 | + if display.id == self._display: |
| 649 | + return display |
| 650 | + error_msg = f"Display {self._display} not found" |
| 651 | + raise ValueError(error_msg) |
| 652 | + |
| 653 | + @telemetry.record_call() |
| 654 | + @override |
| 655 | + def list_displays( |
630 | 656 | self, |
631 | | - ) -> controller_v1_pbs.Response_GetDisplayInformation: |
| 657 | + ) -> DisplaysListResponse: |
632 | 658 | """ |
633 | | - Get information about all available displays and virtual screen. |
| 659 | + List all available displays including virtual screens. |
634 | 660 |
|
635 | 661 | Returns: |
636 | | - controller_v1_pbs.Response_GetDisplayInformation: |
637 | | - - displays: List of DisplayInformation objects |
638 | | - - virtualScreenRectangle: Overall virtual screen bounds |
| 662 | + DisplaysListResponse |
639 | 663 | """ |
640 | 664 | assert isinstance(self._stub, controller_v1.ControllerAPIStub), ( |
641 | 665 | "Stub is not initialized" |
642 | 666 | ) |
643 | 667 |
|
644 | | - self._reporter.add_message("AgentOS", "get_display_information()") |
| 668 | + self._reporter.add_message("AgentOS", "list_displays()") |
645 | 669 |
|
646 | 670 | response: controller_v1_pbs.Response_GetDisplayInformation = ( |
647 | 671 | self._stub.GetDisplayInformation(controller_v1_pbs.Request_Void()) |
648 | 672 | ) |
649 | 673 |
|
650 | | - return response |
| 674 | + response_dict = MessageToDict( |
| 675 | + response, |
| 676 | + preserving_proto_field_name=True, |
| 677 | + ) |
| 678 | + |
| 679 | + return DisplaysListResponse.model_validate(response_dict) |
651 | 680 |
|
652 | 681 | @telemetry.record_call() |
653 | 682 | def get_process_list( |
|
0 commit comments