push notificaitons
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 9.8 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 17 KiB |
@@ -1,57 +1,45 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"short_name": "frontend",
|
||||
"display": "standalone",
|
||||
"scope": "./",
|
||||
"start_url": "./",
|
||||
"icons": [
|
||||
{
|
||||
"src": "icons/icon-72x72.png",
|
||||
"sizes": "72x72",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-96x96.png",
|
||||
"sizes": "96x96",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-128x128.png",
|
||||
"sizes": "128x128",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-144x144.png",
|
||||
"sizes": "144x144",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-152x152.png",
|
||||
"sizes": "152x152",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-384x384.png",
|
||||
"sizes": "384x384",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
}
|
||||
]
|
||||
"name": "TKD Club Chemnitz Datenbank",
|
||||
"short_name": "TCC DB",
|
||||
"display": "standalone",
|
||||
"scope": "./",
|
||||
"start_url": "./",
|
||||
"icons": [
|
||||
{
|
||||
"src": "icons/icon-72x72.png",
|
||||
"sizes": "72x72",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-96x96.png",
|
||||
"sizes": "96x96",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-128x128.png",
|
||||
"sizes": "128x128",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-144x144.png",
|
||||
"sizes": "144x144",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-152x152.png",
|
||||
"sizes": "152x152",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -74,6 +74,6 @@ export class Events implements OnInit {
|
||||
await this.pushService.resetSubscriptions();
|
||||
}
|
||||
protected async subscribe() {
|
||||
this.pushService.subscribeToEvents();
|
||||
await this.pushService.subscribeToEvents();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
<h1>Testeite für interne Berechtigung</h1>
|
||||
<p>API: {{apiStatus()}}</p>
|
||||
<p>Auth: {{authTest()}}</p>
|
||||
<button (click)="pushService.subscribeToEvents()">Subscribe</button>
|
||||
<button (click)="pushService.resetSubscriptions()">Unsubscribe</button>
|
||||
<button (click)="pushService.publishTestMessage()">TestMessage</button>
|
||||
<p>Capabilities: {{pushCaps|json}}</p>
|
||||
<pre>More Caps: {{asyncCaps()|json}}</pre>
|
||||
<button [claimGuard]="Claim.Useradmin" (click)="crawl()">Crawl</button>
|
||||
<button
|
||||
[claimGuard]="Claim.Useradmin"
|
||||
(click)="notifyAll()"
|
||||
class="secondary-btn"
|
||||
matButton="filled">
|
||||
Notify All
|
||||
</button>
|
||||
Claim:
|
||||
<ul>
|
||||
@let claims = this.auth.claims();
|
||||
@if(claims) {
|
||||
<pre>
|
||||
@let claims = this.auth.claims(); @if(claims) {
|
||||
<pre>
|
||||
{{claims | json}}
|
||||
</pre>
|
||||
</pre
|
||||
>
|
||||
}
|
||||
</ul>
|
||||
<details name="UserInfo:">
|
||||
<pre>
|
||||
<pre>
|
||||
{{this.auth.userInfo() | json}}
|
||||
</pre>
|
||||
</pre
|
||||
>
|
||||
</details>
|
||||
|
||||
@@ -6,25 +6,35 @@ import {
|
||||
inject,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { ClaimGuardDirective } from '../../directives/claim-guard.directive';
|
||||
import * as api from '../../generated-api/api';
|
||||
import { Authentication } from '../../services/authentication';
|
||||
import { PushService } from '../../services/push/pushService';
|
||||
|
||||
@Component({
|
||||
selector: 'app-test',
|
||||
imports: [JsonPipe],
|
||||
imports: [JsonPipe, ClaimGuardDirective],
|
||||
templateUrl: './test.html',
|
||||
styleUrl: './test.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class Test {
|
||||
protected readonly pushService = inject(PushService);
|
||||
protected auth = inject(Authentication);
|
||||
protected readonly auth = inject(Authentication);
|
||||
|
||||
protected apiStatus = signal<string>('Waiting');
|
||||
protected authTest = signal<string>('Waiting');
|
||||
protected readonly apiStatus = signal<string>('Waiting');
|
||||
protected readonly authTest = signal<string>('Waiting');
|
||||
protected readonly Claim = api.Claim;
|
||||
protected readonly pushCaps = {
|
||||
serviceWorker: 'serviceWorker' in navigator,
|
||||
pushManager: 'PushManager' in window,
|
||||
notification: 'Notification' in window,
|
||||
notifyPermission: Notification.permission,
|
||||
};
|
||||
protected asyncCaps = signal<any>(null);
|
||||
|
||||
public constructor() {
|
||||
this.loadCaps();
|
||||
effect(() => {
|
||||
const loggedIn = this.auth.loggedIn();
|
||||
if (!loggedIn) {
|
||||
@@ -51,4 +61,22 @@ export class Test {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private async loadCaps() {
|
||||
const caps = {
|
||||
registraion: await navigator.serviceWorker.getRegistrations(),
|
||||
subscription: await (
|
||||
await navigator.serviceWorker.ready
|
||||
).pushManager.getSubscription(),
|
||||
};
|
||||
|
||||
this.asyncCaps.set(caps);
|
||||
}
|
||||
|
||||
protected async notifyAll() {
|
||||
await api.notifyEvents();
|
||||
}
|
||||
protected async crawl() {
|
||||
await api.crawl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,21 @@ export class PushService {
|
||||
|
||||
public async subscribeToEvents() {
|
||||
try {
|
||||
console.log('trying to subscribe');
|
||||
const subscription = await this.swPush.requestSubscription({
|
||||
serverPublicKey: VAPID.publicKey,
|
||||
});
|
||||
|
||||
console.log('returned');
|
||||
console.dir(subscription);
|
||||
console.log('end');
|
||||
|
||||
const previousCliendId = localStorage.getItem(
|
||||
SUBSCRIPTION_CLIENT_ID,
|
||||
);
|
||||
if (previousCliendId) {
|
||||
try {
|
||||
await api.clearSubscription(previousCliendId);
|
||||
await api.clearSubscription({ clientId: previousCliendId });
|
||||
console.log('previous subscription cleared');
|
||||
} catch {}
|
||||
}
|
||||
@@ -62,11 +67,10 @@ export class PushService {
|
||||
}
|
||||
|
||||
public async resetSubscriptions() {
|
||||
const clientId = localStorage.getItem(SUBSCRIPTION_CLIENT_ID);
|
||||
await this.swPush.unsubscribe();
|
||||
await api.resetSubscriptions();
|
||||
}
|
||||
|
||||
public async publishTestMessage() {
|
||||
await api.publishTestMessage();
|
||||
await api.clearSubscription({
|
||||
clientId: clientId ?? undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||