from core.models.orm_calls.application_version_calls import get_all_supported_apps from core.models.BaseProfile import ProfileType from core.errors.logger import logger from pathlib import Path def get_list_of_apps() -> list: database_object = get_all_supported_apps() if not database_object.valid: logger.error(f"Critical Database error with fetching all supported apps. {database_object.error_type} with {database_object.message}") return None list_of_data = list(database_object.data) return list_of_data def get_app_display_data(button_path: str) -> dict: all_apps = get_list_of_apps() display_dto = {} for each_app in all_apps: app_id = each_app.id app_name = each_app.application_code version = each_app.version_number button_image_path = f"{app_name}_button.png" full_image_path = Path(button_path, button_image_path) default_path = Path(button_path, "default_location_button.png") data = { 'path': default_path, 'name': app_name, 'second_line': version, 'existing_icon': full_image_path } display_dto[app_id] = data return display_dto def get_app_icon_path(image_path: Path, profile_type: ProfileType, app_name: str) -> Path: """Return a Path for the app's icon, taking into account that systemwide profiles don't have one""" if profile_type == ProfileType.SYSTEM: icon_image_path = "systemwide.png" else: icon_image_path = f"{app_name} latest_mini.png" full_image_path = Path(image_path, icon_image_path) if full_image_path.exists(): return full_image_path else: return Path(image_path, "default_browser_mini.png")