diff --git a/Aberwyn/Views/Shared/_Layout.cshtml b/Aberwyn/Views/Shared/_Layout.cshtml
index 9fdfd5c..be49913 100644
--- a/Aberwyn/Views/Shared/_Layout.cshtml
+++ b/Aberwyn/Views/Shared/_Layout.cshtml
@@ -42,6 +42,7 @@
{
Adminpanel
}
+
diff --git a/Aberwyn/appsettings.json b/Aberwyn/appsettings.json
index 9cd3ad8..abb9b2e 100644
--- a/Aberwyn/appsettings.json
+++ b/Aberwyn/appsettings.json
@@ -10,7 +10,7 @@
"DefaultConnection": "Server=192.168.1.108;Database=Nevyn;Uid=root;Pwd=3edc4RFV;",
"ProductionConnection": "Server=192.168.1.108;Database=Nevyn;Uid=root;Pwd=3edc4RFV;"
},
- "Vapid": {
+ "VapidKeys": {
"Subject": "mailto:e@zcz.se",
"PublicKey": "BBLmMdU3X3e79SqzAy4vIAJI0jmzRME17F9UKbO8XT1dfnO-mWIPKIrFDbIZD4_3ic7uoijK61vaGdfFUk3HUfU",
"PrivateKey": "oranoCmCo8HXdc03juNgbeSlKE39N3DYus_eMunLsnc"
diff --git a/Aberwyn/wwwroot/js/site.js b/Aberwyn/wwwroot/js/site.js
index 9cc9edf..32ce6e2 100644
--- a/Aberwyn/wwwroot/js/site.js
+++ b/Aberwyn/wwwroot/js/site.js
@@ -32,6 +32,34 @@ async function subscribeToPush() {
console.log('✅ Push-prenumeration skickad');
}
+async function enablePush() {
+ const permission = await Notification.requestPermission();
+
+ if (permission !== "granted") {
+ alert("Du måste tillåta notiser för att få push.");
+ return;
+ }
+
+ const registration = await navigator.serviceWorker.ready;
+ const publicVapidKey = await fetch('/api/push/vapid-public-key').then(r => r.text());
+
+ const subscription = await registration.pushManager.subscribe({
+ userVisibleOnly: true,
+ applicationServerKey: urlBase64ToUint8Array(publicVapidKey.trim()) // 👈 .trim() viktigt
+ });
+
+
+ await fetch("/api/push/subscribe", {
+ method: "POST",
+ body: JSON.stringify(subscription),
+ headers: { "Content-Type": "application/json" }
+ });
+
+ alert("✅ Push-notiser aktiverade!");
+}
+
+
+
// utility för att konvertera nyckeln
function urlBase64ToUint8Array(base64String) {
diff --git a/Aberwyn/wwwroot/service-worker.js b/Aberwyn/wwwroot/service-worker.js
index 42a86ec..2b0b38c 100644
--- a/Aberwyn/wwwroot/service-worker.js
+++ b/Aberwyn/wwwroot/service-worker.js
@@ -3,7 +3,7 @@ const urlsToCache = [
'/',
'/css/site.css',
'/js/site.js',
- '/icons/lewel-icon.png',
+ '/images/lewel-icon.png',
'/manifest.json'
];
@@ -22,7 +22,9 @@ self.addEventListener('fetch', event => {
);
});
self.addEventListener('push', function (event) {
- const data = event.data ? event.data.json() : { title: 'LEWEL', body: 'Ny notis!' };
+ console.log("📨 Push event mottagen!", event);
+
+ const data = event.data ? event.data.json() : { title: "LEWEL", body: "Ny notis" };
const options = {
body: data.body,
@@ -34,3 +36,5 @@ self.addEventListener('push', function (event) {
self.registration.showNotification(data.title, options)
);
});
+
+