84 lines
3.2 KiB
PHP
84 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App;
|
|
|
|
use Desktop\AppRegistry;
|
|
use Desktop\AppIconResolver;
|
|
use Desktop\DesktopState;
|
|
use Desktop\SkinResolver;
|
|
use Desktop\WidgetRegistry;
|
|
use Desktop\WindowManager;
|
|
|
|
final class App
|
|
{
|
|
public function __construct(
|
|
private readonly string $projectRoot,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
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();
|
|
$activeSkin = SkinResolver::resolve($_GET['skin'] ?? null);
|
|
$apps = AppIconResolver::decorate($registry->all(), $activeSkin);
|
|
$windows = (new WindowManager($registry))->defaultWindows();
|
|
$activeWidgetIds = DesktopState::defaultWidgetIds();
|
|
$isAuthenticated = isset($_SESSION['desktop_auth']) && is_array($_SESSION['desktop_auth']);
|
|
$authUser = $isAuthenticated && is_array($_SESSION['desktop_auth']['user'] ?? null)
|
|
? $_SESSION['desktop_auth']['user']
|
|
: [];
|
|
$displayName = (string) ($authUser['name'] ?? $authUser['username'] ?? 'Gast');
|
|
|
|
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' => 'guest',
|
|
'workspace' => DesktopState::defaultWorkspace(),
|
|
'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(),
|
|
],
|
|
];
|
|
}
|
|
}
|