*/ public function desktopPayload(): array { $keycloakConfig = ConfigLoader::load($this->projectRoot, 'keycloak'); $auth = new KeycloakAuth($keycloakConfig); $registry = new AppRegistry($this->projectRoot . '/config/apps.php'); $widgetRegistry = new WidgetRegistry($this->projectRoot . '/config/widgets.php'); $skins = SkinResolver::all(); $isAuthenticated = isset($_SESSION['desktop_auth']) && is_array($_SESSION['desktop_auth']); $authUser = $isAuthenticated && is_array($_SESSION['desktop_auth']['user'] ?? null) ? $_SESSION['desktop_auth']['user'] : []; $authGroups = array_values(array_map('strval', (array) ($authUser['groups'] ?? []))); $visibleApps = AppVisibility::filterByGroups($registry->all(), $authGroups); $userSelfManagement = new UserSelfManagementService($this->projectRoot); $resolvedSkin = $userSelfManagement->resolveActiveSkin( isset($_GET['skin']) ? (string) $_GET['skin'] : null, $authUser, $visibleApps, $widgetRegistry->all(), $skins ); $userSettings = $resolvedSkin['settings']; $activeSkin = (string) $resolvedSkin['skin']; $enabledApps = AppVisibility::filterByEnabledIds( $visibleApps, array_values(array_map('strval', (array) ($userSettings['apps']['enabled_ids'] ?? []))), [UserSelfManagementService::APP_ID] ); $apps = AppIconResolver::decorate($enabledApps, $activeSkin); $windows = (new WindowManager($registry))->defaultWindows(); $activeWidgetIds = array_values(array_map('strval', (array) ($userSettings['widgets']['active_ids'] ?? DesktopState::defaultWidgetIds()))); $displayName = (string) ($authUser['name'] ?? $authUser['username'] ?? 'Gast'); $storageScope = $isAuthenticated ? strtolower((string) ($authUser['username'] ?? $authUser['sub'] ?? 'user')) : 'guest'; return [ 'meta' => [ 'title' => 'Kusche.Berlin Desktop UI', 'active_skin' => $activeSkin, 'available_skins' => $skins, 'base_skin_profile' => SkinResolver::profile('base'), 'skin_profile' => SkinResolver::profile($activeSkin), ], 'desktop' => [ 'greeting' => 'Neue Desktop-Shell fuer Kusche.Berlin', 'wallpaper' => SkinResolver::wallpaper($activeSkin), 'storage_scope' => preg_replace('/[^a-z0-9._-]+/i', '-', $storageScope) ?: 'guest', 'workspace' => DesktopState::defaultWorkspace(), 'settings_api' => '/api/user-self-management/index.php', 'user_preferences' => $userSettings, 'login' => [ 'authenticated' => $isAuthenticated, 'mode' => $isAuthenticated ? 'authenticated' : 'login-required', 'keycloak_theme_handoff' => '/docs/keycloak-theme-handoff.md', 'user' => [ 'name' => (string) ($authUser['name'] ?? ''), 'username' => (string) ($authUser['username'] ?? ''), 'email' => (string) ($authUser['email'] ?? ''), ], ], ], 'apps' => $apps, 'windows' => $windows, 'widgets' => [ 'active' => $widgetRegistry->active($activeWidgetIds), 'registry' => $widgetRegistry->all(), 'active_ids' => $activeWidgetIds, ], 'tray' => DesktopState::trayItems(), 'session' => [ 'display_name' => $displayName, 'authenticated' => $isAuthenticated, 'logout_url' => $isAuthenticated && $auth->isConfigured() ? '/auth/logout' : null, ], 'menu' => [ 'quick_actions' => DesktopState::quickActions(), ], ]; } }