store/app/Http/Controllers/PwaManifestController.php
Yoga Pangestu 9b20d26a4e
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (8.3) (push) Waiting to run
tests / ci (8.4) (push) Waiting to run
tests / ci (8.5) (push) Waiting to run
refactor: remove PWA manifest file and update related configurations, improving project structure and icon handling in the PwaManifestController
2026-07-13 19:55:35 +07:00

68 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Services\System\Setting\SystemService;
use Illuminate\Http\JsonResponse;
class PwaManifestController extends Controller
{
public function show(SystemService $systemService): JsonResponse
{
$systemData = $systemService->systemData();
$appName = $systemData['app_name'] ?? config('app.name', 'DST Collection');
$iconUrl = $systemData['favicon_url'] ?? $systemData['logo_url'] ?? asset('assets/logo.png');
$mimeType = 'image/png';
$lowerIconUrl = strtolower($iconUrl);
if (str_contains($lowerIconUrl, '.svg')) {
$mimeType = 'image/svg+xml';
} elseif (str_contains($lowerIconUrl, '.jpg') || str_contains($lowerIconUrl, '.jpeg')) {
$mimeType = 'image/jpeg';
} elseif (str_contains($lowerIconUrl, '.webp')) {
$mimeType = 'image/webp';
}
$manifest = [
'name' => $appName,
'short_name' => $appName,
'description' => "{$appName} - Progressive Web App",
'theme_color' => '#171717',
'background_color' => '#ffffff',
'display' => 'standalone',
'orientation' => 'portrait',
'scope' => '/',
'start_url' => '/',
'id' => '/',
'icons' => [
[
'src' => $iconUrl,
'sizes' => '64x64',
'type' => $mimeType,
],
[
'src' => $iconUrl,
'sizes' => '192x192',
'type' => $mimeType,
],
[
'src' => $iconUrl,
'sizes' => '512x512',
'type' => $mimeType,
'purpose' => 'any',
],
[
'src' => $iconUrl,
'sizes' => '512x512',
'type' => $mimeType,
'purpose' => 'maskable',
],
],
];
return response()->json($manifest)
->header('Content-Type', 'application/manifest+json')
->header('Cache-Control', 'no-cache, no-store, must-revalidate');
}
}