resources/js/admin/mobile/lib.
- Admin push is end‑to‑end: new backend model/migration/service/job + API endpoints, admin runtime config, push‑aware
service worker, and a settings toggle via useAdminPushSubscription. Notifications now auto‑refresh on push.
- New PHP/JS tests: admin push API feature test and queue/haptics unit tests
Added admin-specific PWA icon assets and wired them into the admin manifest, service worker, and admin shell, plus a
new “Device & permissions” card in mobile Settings with a persistent storage action and translations.
Details: public/manifest.json, public/admin-sw.js, resources/views/admin.blade.php, new icons in public/; new hook
resources/js/admin/mobile/hooks/useDevicePermissions.ts, helpers/tests in resources/js/admin/mobile/lib/
devicePermissions.ts + resources/js/admin/mobile/lib/devicePermissions.test.ts, and Settings UI updates in resources/
js/admin/mobile/SettingsPage.tsx with copy in resources/js/admin/i18n/locales/en/management.json and resources/js/
admin/i18n/locales/de/management.json.
83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Push;
|
|
|
|
use App\Models\TenantAdminPushSubscription;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Minishlink\WebPush\MessageSentReport;
|
|
use Minishlink\WebPush\Subscription as WebPushSubscription;
|
|
use Minishlink\WebPush\WebPush;
|
|
|
|
class AdminWebPushDispatcher
|
|
{
|
|
private ?WebPush $client = null;
|
|
|
|
public function send(TenantAdminPushSubscription $subscription, array $payload): ?MessageSentReport
|
|
{
|
|
if (! config('push.enabled')) {
|
|
return null;
|
|
}
|
|
|
|
$client = $this->client ??= $this->buildClient();
|
|
|
|
if (! $client) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
$body = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
|
|
} catch (\JsonException $exception) {
|
|
Log::channel('notifications')->warning('Unable to encode admin push payload', [
|
|
'reason' => $exception->getMessage(),
|
|
]);
|
|
|
|
$body = '{}';
|
|
}
|
|
|
|
try {
|
|
return $client->sendOneNotification(
|
|
WebPushSubscription::create([
|
|
'endpoint' => $subscription->endpoint,
|
|
'publicKey' => $subscription->public_key,
|
|
'authToken' => $subscription->auth_token,
|
|
'contentEncoding' => $subscription->content_encoding ?? 'aes128gcm',
|
|
]),
|
|
$body
|
|
);
|
|
} catch (\Throwable $exception) {
|
|
Log::channel('notifications')->warning('Admin web push transport error', [
|
|
'tenant_id' => $subscription->tenant_id,
|
|
'subscription_id' => $subscription->id,
|
|
'reason' => $exception->getMessage(),
|
|
]);
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private function buildClient(): ?WebPush
|
|
{
|
|
$vapid = config('push.vapid', []);
|
|
|
|
if (empty($vapid['public_key']) || empty($vapid['private_key'])) {
|
|
Log::channel('notifications')->warning('Admin web push skipped because VAPID keys are missing.');
|
|
|
|
return null;
|
|
}
|
|
|
|
$client = new WebPush([
|
|
'VAPID' => [
|
|
'subject' => $vapid['subject'] ?? config('app.url'),
|
|
'publicKey' => $vapid['public_key'],
|
|
'privateKey' => $vapid['private_key'],
|
|
],
|
|
]);
|
|
|
|
$client->setDefaultOptions([
|
|
'TTL' => (int) config('push.ttl', 900),
|
|
]);
|
|
|
|
return $client;
|
|
}
|
|
}
|