Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 14 additions & 49 deletions Framework/install_handler/long_poll_handler.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import asyncio
import json
import traceback
import random
import platform
import httpx
import inspect
from colorama import Fore
from Framework.install_handler.route import Response, services
from Framework.install_handler.utils import send_response, debug, read_node_id
from pydantic import BaseModel
from Framework.install_handler.utils import debug, send_response, read_node_id, generate_services_list
from Framework.Utilities import RequestFormatter, ConfigModule
from Framework.node_server_state import STATE
from Framework.install_handler.android.emulator import create_avd_from_system_image, get_available_avds
from Framework.install_handler.android.emulator import create_avd_from_system_image
from Framework.install_handler.system_info.system_info import get_formatted_system_info

if debug:
Expand All @@ -31,48 +28,13 @@ async def on_message(self, message: Response) -> None:
return
action = message.value.action
if action == "services_list":
current_os = platform.system().lower()
if debug: print(f"[installer] Current OS: {current_os}")

# Populate AndroidEmulator services with available AVDs
try:
avds = await get_available_avds()
for category in services:
if category["category"] == "AndroidEmulator":
category["services"] = avds
if debug: print(f"[installer] Populated AndroidEmulator with {len(avds)} AVDs")
break
except Exception as e:
if debug: print(f"[installer] Error populating AVDs: {e}")
# Continue with empty services list if AVD population fails

filtered_services = []
for category in services:
filtered_category = {
"category": category["category"],
"services": []
}
for service in category["services"]:
if current_os not in service["os"]:
if debug: print(f"[installer] Skipping {service['name']} - not compatible with {current_os}")
continue

filtered_service = {
"name": service["name"],
"status": service["status"],
"comment": service["comment"],
"install_text": service["install_text"],
"os": service["os"],
"user_password": service["user_password"]
}
filtered_category["services"].append(filtered_service)

if filtered_category["services"]:
filtered_services.append(filtered_category)

services_list = generate_services_list(services)
await send_response({
"action": "services_list",
"data": filtered_services
"data": {
"system_info": None,
"services": services_list
}
})
elif action == "system_info":
if debug: print(f"[installer] Received system_info request")
Expand All @@ -81,7 +43,10 @@ async def on_message(self, message: Response) -> None:
print("system info")
system_info_response = await get_formatted_system_info()
# Send the response to server
await send_response(system_info_response)
await send_response({
"action": "system_info",
"data": system_info_response
})
if debug: print(f"[installer] System info sent successfully")
except Exception as e:
print(f"[installer] Error getting/sending system info: {e}")
Expand Down Expand Up @@ -110,13 +75,13 @@ async def on_message(self, message: Response) -> None:
print(f"[installer] No install_function found for AndroidEmulator category")
return

# Case 2: Service name is a device installation request (starts with "install device;")
if service_name.startswith("install device;"):
# Case 2: Service name is a system image (starts with "system-images;")
if service_name.startswith("system-images;"):
if action == "install":
await create_avd_from_system_image(service_name)
return
else:
print(f"[installer] Status check not supported for device installation")
print(f"[installer] Status check not supported for system images")
return

# Case 3: Service name is an existing AVD - find it in services list
Expand Down
179 changes: 63 additions & 116 deletions Framework/install_handler/route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pydantic import BaseModel, ConfigDict
from typing import Literal
import asyncio

import platform

from .web import chrome_for_testing, edge, mozilla
from .android import adb, node_js_22, appium, java, android_emulator, android_sdk, jdk, emulator
Expand All @@ -10,66 +9,16 @@
from .windows import inspector
from .android.emulator import android_emulator_install

import httpx
from Framework.Utilities import RequestFormatter, ConfigModule, CommonUtil
import datetime
from Framework.install_handler.utils import debug

version = "2.0.0"
services = [
{
"category": "Web",

"services": [
{
"name": "Chrome For Testing",
"status": "none",
"comment": "Chrome for Testing is required to run web automation in Chrome browser.",
"install_text": "install",
"os": ["windows", "linux", "darwin"],
"status_function": chrome_for_testing.check_status,
"install_function": chrome_for_testing.install,
"user_password": "no",
},
{
"name": "Mozilla",
"status": "none",
"comment": "Mozilla Firefox is required to run web automation in Mozilla Firefox browser.",
"install_text": "install",
"os": ["windows", "linux", "darwin"],
"status_function": mozilla.check_status,
"install_function": mozilla.install,
"user_password": "yes",
},
{
"name": "Edge",
"status": "none",
"comment": "Microsoft Edge is required to run web automation in Microsoft Edge browser.",
"install_text": "install",
"os": ["windows", "linux", "darwin"],
"status_function": edge.check_status,
"install_function": edge.install,
"user_password": "yes",
}

]
},
{
"category": "AndroidEmulator",
"name" : "System Images",
"install_text": "install",
"install_function": android_emulator_install,
"installables": [],
"services": [],
},
{
"category": "Android",
"services": [
{
"name": "ADB",
"status": "none",
"comment": "ADB is a tool for managing Android devices.",
"install_text": "install",
"os": ["windows", "linux", "darwin"],
"status_function": adb.check_status,
"install_function": adb.install,
"user_password": "no",
},
{
"name": "Node js 22",
"status": "none",
Expand Down Expand Up @@ -119,7 +68,62 @@
"status_function": android_sdk.check_status,
"install_function": android_sdk.install,
"user_password": "no"
},
{
"name": "ADB",
"status": "none",
"comment": "ADB is a tool for managing Android devices.",
"install_text": "install",
"os": ["windows", "linux", "darwin"],
"status_function": adb.check_status,
"install_function": adb.install,
"user_password": "no",
},
]
},
{
"category": "AndroidEmulator",
"name" : "System Images",
"install_text": "install",
"install_function": android_emulator_install,
"installables": [],
"services": [],
},
{
"category": "Web",

"services": [
{
"name": "Chrome For Testing",
"status": "none",
"comment": "Chrome for Testing is required to run web automation in Chrome browser.",
"install_text": "install",
"os": ["windows", "linux", "darwin"],
"status_function": chrome_for_testing.check_status,
"install_function": chrome_for_testing.install,
"user_password": "no",
},
{
"name": "Mozilla",
"status": "none",
"comment": "Mozilla Firefox is required to run web automation in Mozilla Firefox browser.",
"install_text": "install",
"os": ["windows", "linux", "darwin"],
"status_function": mozilla.check_status,
"install_function": mozilla.install,
"user_password": "yes",
},
{
"name": "Edge",
"status": "none",
"comment": "Microsoft Edge is required to run web automation in Microsoft Edge browser.",
"install_text": "install",
"os": ["windows", "linux", "darwin"],
"status_function": edge.check_status,
"install_function": edge.install,
"user_password": "yes",
}

]
},
{
Expand Down Expand Up @@ -201,64 +205,6 @@
]



# try:
# avds = asyncio.run(emulator.get_available_avds())
# except RuntimeError:
# # Event loop already running, use a different approach
# try:
# loop = asyncio.get_event_loop()
# if loop.is_running():
# # If loop is running, initialize empty and populate later
# avds = []
# else:
# avds = loop.run_until_complete(emulator.get_available_avds())
# except RuntimeError:
# avds = []

# def _populate_avds():
# """Populate the AndroidEmulator category with available AVDs"""
# try:
# loop = asyncio.get_event_loop()
# if loop.is_running():
# # If loop is running, we need to schedule it
# async def refresh():
# avds = await emulator.get_available_avds()
# for category in services:
# if category["category"] == "AndroidEmulator":
# category["services"] = avds
# break
# # Schedule the refresh
# asyncio.create_task(refresh())
# else:
# avds = loop.run_until_complete(emulator.get_available_avds())
# for category in services:
# if category["category"] == "AndroidEmulator":
# category["services"] = avds
# break
# except Exception as e:
# print(f"[installer][route] Error refreshing AVD list: {e}")


# async def refresh_avd_list():
# """Refresh the AVD list in the AndroidEmulator category"""
# try:
# avds = await emulator.get_available_avds()
# for category in services:
# if category["category"] == "AndroidEmulator":
# category["services"] = avds
# break
# print(f"[installer][route] Refreshed AVD list: {len(avds)} AVDs found")
# except Exception as e:
# print(f"[installer][route] Error refreshing AVD list: {e}")


# for category in services:
# if category["category"] == "AndroidEmulator":
# category["services"] = avds
# break


class Item(BaseModel):
name: str | None = None
category: str
Expand All @@ -275,4 +221,5 @@ class Value(BaseModel):
class Response(BaseModel):
model_config = ConfigDict(extra='forbid')

value: Value | None
value: Value | None

Loading
Loading