Phase 8 Mobil: REST-API, Web-Push, installierbare App (0.25.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m50s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m56s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 7m5s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m50s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m56s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 7m5s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
232dc5c59c
commit
f11a3e24b3
201 changed files with 3604 additions and 427 deletions
|
|
@ -4,6 +4,7 @@ import 'vue-sonner/style.css';
|
|||
import * as Vue from 'vue';
|
||||
import * as Inertia from '@inertiajs/vue3';
|
||||
import * as InhausUi from './sdk/ui';
|
||||
import { registerServiceWorker } from './lib/push';
|
||||
import { loadPluginPage } from './lib/pluginComponents';
|
||||
|
||||
const { createApp, h } = Vue;
|
||||
|
|
@ -44,6 +45,9 @@ createInertiaApp({
|
|||
createApp({ render: () => h(App, props) })
|
||||
.use(plugin)
|
||||
.mount(el);
|
||||
|
||||
// Service Worker: Push-Benachrichtigungen und Offline-Seite (nur angemeldet)
|
||||
if (props.initialPage.props.auth?.user) registerServiceWorker();
|
||||
},
|
||||
progress: {
|
||||
color: 'var(--brand)',
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<script setup>
|
||||
import PushToggle from '@/components/PushToggle.vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { router, usePage } from '@inertiajs/vue3';
|
||||
import { Bell, CheckCheck, FileCheck, LoaderCircle, MessageSquare, Newspaper, Undo2 } from '@lucide/vue';
|
||||
|
|
@ -75,6 +76,7 @@ function open(item) {
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="border-t px-4 py-2.5"><PushToggle compact /></div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</template>
|
||||
|
|
|
|||
67
resources/js/components/PushToggle.vue
Normal file
67
resources/js/components/PushToggle.vue
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<script setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { usePage } from '@inertiajs/vue3';
|
||||
import { BellRing, LoaderCircle } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { http } from '@/lib/http';
|
||||
import { currentSubscription, disablePush, enablePush, pushSupported } from '@/lib/push';
|
||||
|
||||
/**
|
||||
* Schalter „Push-Benachrichtigungen auf diesem Gerät“.
|
||||
*/
|
||||
defineProps({
|
||||
compact: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
const supported = ref(false);
|
||||
const enabled = ref(false);
|
||||
const busy = ref(false);
|
||||
const isIos = /iPhone|iPad|iPod/.test(navigator.userAgent) && !window.matchMedia('(display-mode: standalone)').matches;
|
||||
|
||||
onMounted(async () => {
|
||||
supported.value = pushSupported() && !!page.props.push?.key;
|
||||
|
||||
if (supported.value) {
|
||||
enabled.value = !!(await currentSubscription()) && Notification.permission === 'granted';
|
||||
}
|
||||
});
|
||||
|
||||
async function toggle(value) {
|
||||
busy.value = true;
|
||||
|
||||
try {
|
||||
if (value) {
|
||||
await enablePush(page.props.push.key);
|
||||
enabled.value = true;
|
||||
await http.post('/push/test').catch(() => {});
|
||||
toast.success('Push ist eingeschaltet – eine Testnachricht ist unterwegs.');
|
||||
} else {
|
||||
await disablePush();
|
||||
enabled.value = false;
|
||||
toast.success('Push auf diesem Gerät ausgeschaltet');
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error(error.message);
|
||||
enabled.value = !!(await currentSubscription());
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="supported" class="flex items-center gap-3" :class="compact ? 'text-[13px]' : 'text-sm'">
|
||||
<BellRing class="size-4 shrink-0 text-muted-foreground" />
|
||||
<span class="min-w-0 flex-1">
|
||||
Push auf diesem Gerät
|
||||
<span v-if="!compact" class="block text-xs text-muted-foreground">Hinweise erscheinen auch, wenn das Portal nicht geöffnet ist.</span>
|
||||
</span>
|
||||
<LoaderCircle v-if="busy" class="size-4 animate-spin text-muted-foreground" />
|
||||
<Switch :model-value="enabled" :disabled="busy" aria-label="Push-Benachrichtigungen auf diesem Gerät" @update:model-value="toggle" />
|
||||
</div>
|
||||
<p v-else-if="isIos && !compact" class="text-[13px] text-muted-foreground">
|
||||
Auf iPhone und iPad gibt es Push-Benachrichtigungen, sobald das Portal über „Teilen → Zum Home-Bildschirm“ als App hinzugefügt wurde.
|
||||
</p>
|
||||
</template>
|
||||
93
resources/js/components/profile/DevicesPanel.vue
Normal file
93
resources/js/components/profile/DevicesPanel.vue
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { router } from '@inertiajs/vue3';
|
||||
import { Copy, KeyRound, LoaderCircle, Plus, Smartphone, Trash2 } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import PushToggle from '@/components/PushToggle.vue';
|
||||
import { http } from '@/lib/http';
|
||||
import { formatRelative } from '@/lib/format';
|
||||
|
||||
/**
|
||||
* „Benachrichtigungen & Apps“: Push auf diesem Gerät und Zugänge für Apps (REST-API).
|
||||
*/
|
||||
defineProps({
|
||||
tokens: { type: Array, default: () => [] },
|
||||
});
|
||||
|
||||
const adding = ref(false);
|
||||
const name = ref('');
|
||||
const busy = ref(false);
|
||||
const created = ref(null);
|
||||
|
||||
async function create() {
|
||||
busy.value = true;
|
||||
|
||||
try {
|
||||
const data = await http.post('/profil/apps', { name: name.value });
|
||||
created.value = data.token;
|
||||
name.value = '';
|
||||
adding.value = false;
|
||||
router.reload({ only: ['tokens'] });
|
||||
} catch (error) {
|
||||
toast.error(error.data?.errors?.name?.[0] ?? error.message);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function copy() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(created.value);
|
||||
toast.success('Zugangsschlüssel kopiert');
|
||||
} catch {
|
||||
toast.error('Kopieren nicht möglich – bitte markieren und kopieren.');
|
||||
}
|
||||
}
|
||||
|
||||
function remove(token) {
|
||||
if (window.confirm(`Zugang „${token.name}“ entfernen? Die App wird sofort abgemeldet.`)) {
|
||||
router.delete(`/profil/apps/${token.id}`, { preserveScroll: true, only: ['tokens'], onSuccess: () => toast.success('Zugang entfernt') });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel title="Benachrichtigungen & Apps">
|
||||
<PushToggle />
|
||||
|
||||
<div class="mt-5 border-t pt-4">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<h3 class="text-sm font-medium">Apps & Geräte</h3>
|
||||
<Button v-if="!adding" size="sm" variant="ghost" @click="(adding = true), (created = null)"><Plus /> Zugang</Button>
|
||||
</div>
|
||||
<p class="mt-1 text-[13px] text-muted-foreground">Für Apps, die das Portal über die Schnittstelle nutzen. Jeder Zugang lässt sich einzeln entfernen.</p>
|
||||
|
||||
<form v-if="adding" class="mt-3 flex gap-2" @submit.prevent="create">
|
||||
<Input v-model="name" maxlength="100" placeholder="z. B. Diensthandy" aria-label="Name des Geräts" autofocus />
|
||||
<Button type="submit" size="sm" class="h-9" :disabled="busy || !name.trim()"><LoaderCircle v-if="busy" class="animate-spin" /> Anlegen</Button>
|
||||
</form>
|
||||
|
||||
<div v-if="created" class="mt-3 rounded-md border border-amber-300 bg-amber-50 p-3 dark:border-amber-800 dark:bg-amber-950/40">
|
||||
<p class="flex items-center gap-1.5 text-[13px] font-medium"><KeyRound class="size-4" /> Zugangsschlüssel – wird nur jetzt angezeigt</p>
|
||||
<div class="mt-2 flex items-center gap-2">
|
||||
<code class="min-w-0 flex-1 truncate rounded bg-card px-2 py-1 text-xs select-all">{{ created }}</code>
|
||||
<Button size="icon" variant="outline" class="size-8" aria-label="Kopieren" @click="copy"><Copy /></Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul v-if="tokens.length" class="mt-3 divide-y rounded-md border">
|
||||
<li v-for="token in tokens" :key="token.id" class="flex items-center gap-3 px-3 py-2">
|
||||
<Smartphone class="size-4 shrink-0 text-muted-foreground" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="truncate text-sm">{{ token.name }}</p>
|
||||
<p class="text-xs text-muted-foreground">{{ token.last_used_at ? `zuletzt ${formatRelative(token.last_used_at)}` : 'noch nicht benutzt' }}</p>
|
||||
</div>
|
||||
<Button size="icon" variant="ghost" class="size-8 text-muted-foreground hover:text-destructive" :aria-label="`${token.name} entfernen`" @click="remove(token)"><Trash2 /></Button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</Panel>
|
||||
</template>
|
||||
71
resources/js/lib/push.js
Normal file
71
resources/js/lib/push.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { http } from '@/lib/http';
|
||||
|
||||
/**
|
||||
* Web-Push im Browser: Service Worker registrieren, Push je Gerät an- und abmelden.
|
||||
* Funktioniert nur über HTTPS (oder localhost); auf iPhone/iPad erst, wenn das Portal
|
||||
* als App zum Home-Bildschirm hinzugefügt wurde.
|
||||
*/
|
||||
export const pushSupported = () => typeof window !== 'undefined' && window.isSecureContext && 'serviceWorker' in navigator && 'PushManager' in window && 'Notification' in window;
|
||||
|
||||
let registration = null;
|
||||
|
||||
export function registerServiceWorker() {
|
||||
if (typeof window === 'undefined' || !window.isSecureContext || !('serviceWorker' in navigator)) return Promise.resolve(null);
|
||||
|
||||
registration ??= navigator.serviceWorker.register('/sw.js', { scope: '/' }).catch(() => null);
|
||||
|
||||
return registration;
|
||||
}
|
||||
|
||||
function keyToBytes(base64url) {
|
||||
const base64 = (base64url + '='.repeat((4 - (base64url.length % 4)) % 4)).replace(/-/g, '+').replace(/_/g, '/');
|
||||
|
||||
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
||||
}
|
||||
|
||||
export async function currentSubscription() {
|
||||
if (!pushSupported()) return null;
|
||||
|
||||
const reg = await registerServiceWorker();
|
||||
|
||||
return reg ? reg.pushManager.getSubscription() : null;
|
||||
}
|
||||
|
||||
export async function enablePush(publicKey) {
|
||||
if (!pushSupported()) throw new Error('Dieser Browser unterstützt keine Push-Benachrichtigungen.');
|
||||
|
||||
const permission = await Notification.requestPermission();
|
||||
|
||||
if (permission !== 'granted') {
|
||||
throw new Error('Benachrichtigungen sind für dieses Portal im Browser blockiert. Bitte in den Website-Einstellungen erlauben.');
|
||||
}
|
||||
|
||||
const reg = await registerServiceWorker();
|
||||
await navigator.serviceWorker.ready;
|
||||
let subscription = await reg.pushManager.getSubscription();
|
||||
|
||||
// Anderer Serverschlüssel (z. B. nach Umzug) → neu abonnieren
|
||||
if (subscription && subscription.options?.applicationServerKey) {
|
||||
const current = new Uint8Array(subscription.options.applicationServerKey);
|
||||
const expected = keyToBytes(publicKey);
|
||||
|
||||
if (current.length !== expected.length || current.some((byte, i) => byte !== expected[i])) {
|
||||
await subscription.unsubscribe();
|
||||
subscription = null;
|
||||
}
|
||||
}
|
||||
|
||||
subscription ??= await reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: keyToBytes(publicKey) });
|
||||
await http.post('/push/abo', subscription.toJSON());
|
||||
|
||||
return subscription;
|
||||
}
|
||||
|
||||
export async function disablePush() {
|
||||
const subscription = await currentSubscription();
|
||||
|
||||
if (!subscription) return;
|
||||
|
||||
await http.delete('/push/abo', { endpoint: subscription.endpoint }).catch(() => {});
|
||||
await subscription.unsubscribe();
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import { Textarea } from '@/components/ui/textarea';
|
|||
import FormField from '@/components/FormField.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import CoverBanner from '@/components/CoverBanner.vue';
|
||||
import DevicesPanel from '@/components/profile/DevicesPanel.vue';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
|
||||
|
|
@ -18,6 +19,7 @@ const props = defineProps({
|
|||
managed: { type: Array, default: () => [] },
|
||||
customFields: { type: Array, default: () => [] },
|
||||
sections: { type: Array, default: () => [] },
|
||||
tokens: { type: Array, default: () => [] },
|
||||
});
|
||||
|
||||
// Abschnitte aus Plugins (App\Profile\ProfileSections): „<plugin>::Name“ aus plugins-core/<plugin>/resources/js/profile
|
||||
|
|
@ -191,6 +193,8 @@ function savePassword() {
|
|||
<p v-if="coverForm.errors.cover" class="mt-3 text-[13px] text-destructive">{{ coverForm.errors.cover }}</p>
|
||||
<p class="mt-3 text-[13px] text-muted-foreground">Erscheint oben in Ihrem Profil und in der Begrüßung auf der Startseite – mit einer Fläche in der Hausfarbe darüber. Querformat, höchstens 8 MB.</p>
|
||||
</Panel>
|
||||
|
||||
<DevicesPanel :tokens="tokens" class="mt-6" />
|
||||
</div>
|
||||
|
||||
<div class="grid content-start gap-6 lg:col-span-8">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue