change the notification detection to our own variables, and save the selected time

This commit is contained in:
2024-11-20 19:55:51 -07:00
parent 5fa2f3eef6
commit 15e09c2d81
8 changed files with 286 additions and 110 deletions

View File

@@ -229,7 +229,7 @@
? notification.onCancel(stopAsking)
: null;
close(notification.id);
stopAsking = false; // reset value
stopAsking = false; // reset value for next time they open this modal
"
class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white px-2 py-2 rounded-md"
>
@@ -292,7 +292,7 @@
<button
@click="
close(notification.id);
turnOffNotifications();
turnOffNotifications(notification);
"
class="block w-full text-center text-md font-bold uppercase bg-rose-600 text-white px-2 py-2 rounded-md mb-2"
>
@@ -318,22 +318,26 @@
<script lang="ts">
import { Vue, Component } from "vue-facing-decorator";
import { logConsoleAndDb } from "@/db/index";
import { db, logConsoleAndDb } from "@/db/index";
import { NotificationIface } from "./constants/app";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
@Component
export default class App extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
stopAsking = false;
async turnOffNotifications() {
async turnOffNotifications(notification: NotificationIface) {
let subscription;
const pushProviderSuccess = await navigator.serviceWorker?.ready
const pushProviderSuccess: boolean = await navigator.serviceWorker?.ready
.then((registration) => {
return registration.pushManager.getSubscription();
})
.then((subscript) => {
.then((subscript: PushSubscription | null) => {
subscription = subscript;
if (subscription) {
return subscription.unsubscribe();
if (subscript) {
return subscript.unsubscribe();
} else {
logConsoleAndDb("Subscription object is not available.");
return false;
@@ -347,7 +351,7 @@ export default class App extends Vue {
return false;
});
const pushServerSuccess = await fetch("/web-push/unsubscribe", {
const pushServerSuccess: boolean = await fetch("/web-push/unsubscribe", {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -365,14 +369,36 @@ export default class App extends Vue {
return false;
});
alert(
"Notifications are off. Push provider unsubscribe " +
let message;
if (pushProviderSuccess === pushServerSuccess) {
message = "Both local and server notifications ";
if (pushProviderSuccess) {
message += "are off.";
} else {
message += "failed to turn off.";
}
} else {
message =
"Local unsubscribe " +
(pushProviderSuccess ? "succeeded" : "failed") +
(pushProviderSuccess === pushServerSuccess ? " and" : " but") +
" push server unsubscribe " +
" but server unsubscribe " +
(pushServerSuccess ? "succeeded" : "failed") +
".",
);
".";
}
this.$notify({
group: "alert",
type: "info",
title: "Finished",
text: message,
});
await db.open();
await db.settings.update(MASTER_SETTINGS_KEY, {
notifyingNewActivity: false,
});
if (notification.callback) {
notification.callback(pushProviderSuccess && pushServerSuccess);
}
}
}
</script>