feat: add PWA support by updating manifest link and adding apple-touch-icon, enhancing mobile experience
This commit is contained in:
parent
3c5389e541
commit
5c1f92e48b
68
app/Http/Controllers/PwaManifestController.php
Normal file
68
app/Http/Controllers/PwaManifestController.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?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');
|
||||
$logoUrl = $systemData['logo_url'] ?? asset('assets/logo.png');
|
||||
|
||||
// Determine mime type from logoUrl extension
|
||||
$mimeType = 'image/png';
|
||||
$lowerLogoUrl = strtolower($logoUrl);
|
||||
if (str_contains($lowerLogoUrl, '.svg')) {
|
||||
$mimeType = 'image/svg+xml';
|
||||
} elseif (str_contains($lowerLogoUrl, '.jpg') || str_contains($lowerLogoUrl, '.jpeg')) {
|
||||
$mimeType = 'image/jpeg';
|
||||
} elseif (str_contains($lowerLogoUrl, '.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' => $logoUrl,
|
||||
'sizes' => '64x64',
|
||||
'type' => $mimeType,
|
||||
],
|
||||
[
|
||||
'src' => $logoUrl,
|
||||
'sizes' => '192x192',
|
||||
'type' => $mimeType,
|
||||
],
|
||||
[
|
||||
'src' => $logoUrl,
|
||||
'sizes' => '512x512',
|
||||
'type' => $mimeType,
|
||||
'purpose' => 'any',
|
||||
],
|
||||
[
|
||||
'src' => $logoUrl,
|
||||
'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');
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,8 @@
|
||||
<link rel="icon"
|
||||
href="{{ $page['props']['favicon_url'] ?? ($page['props']['logo_url'] ?? asset('assets/logo.png')) }}"
|
||||
sizes="any">
|
||||
<link rel="manifest" href="/build/manifest.webmanifest">
|
||||
<link rel="apple-touch-icon" href="{{ $page['props']['logo_url'] ?? asset('assets/logo.png') }}">
|
||||
<link rel="manifest" href="/pwa-manifest.json">
|
||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||
<link href="https://fonts.bunny.net/css?family=instrument-sans:400,500,600" rel="stylesheet" />
|
||||
|
||||
|
||||
@ -38,9 +38,11 @@
|
||||
use App\Http\Controllers\Auth\LogoutController;
|
||||
use App\Http\Controllers\HomeController;
|
||||
use App\Http\Controllers\PushSubscriptionController;
|
||||
use App\Http\Controllers\PwaManifestController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/', [HomeController::class, 'index'])->name('home');
|
||||
Route::get('/pwa-manifest.json', [PwaManifestController::class, 'show'])->name('pwa.manifest');
|
||||
|
||||
Route::middleware('guest')->group(function () {
|
||||
Route::get('/auth/login', [LoginController::class, 'index'])->name('login');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user