From 3e2723b744c71313cef0bdd2e041da08742b2ca5 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Thu, 7 Dec 2023 04:20:41 -0500 Subject: [PATCH 1/2] Added auto-control on notification toggle -- be sure to empty browser cache in Storage to assure latest scripts are executing --- src/views/AccountViewView.vue | 36 +++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 7f1fa52..a121ef2 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -105,7 +105,12 @@
- +
@@ -136,6 +141,7 @@ type="checkbox" name="toggleMuteNotifications" class="sr-only" + disabled />
@@ -404,6 +410,16 @@ export default class AccountViewView extends Vue { showAdvanced = false; + private isSubscribed = false; + + get toggleNotifications() { + return this.isSubscribed; + } + + set toggleNotifications(value) { + this.isSubscribed = value; + } + public async getIdentity(activeDid: string): Promise { try { // Open the accounts database @@ -486,6 +502,7 @@ export default class AccountViewView extends Vue { * @throws Will display specific messages to the user based on different errors. */ async created() { + console.error("created"); try { await db.open(); @@ -504,6 +521,18 @@ export default class AccountViewView extends Vue { } } + async mounted() { + console.error("mounted()"); + try { + const registration = await navigator.serviceWorker.ready; + const subscription = await registration.pushManager.getSubscription(); + this.toggleNotifications = !!subscription; + } catch (error) { + console.error(error); + this.toggleNotifications = false; + } + } + /** * Initializes component state with values from the database or defaults. * @param {SettingsType} settings - Object containing settings from the database. @@ -711,7 +740,7 @@ export default class AccountViewView extends Vue { }); this.isRegistered = true; } catch (err) { - console.log("Got an error updating settings:", err); + console.error("Got an error updating settings:", err); this.$notify( { group: "alert", @@ -753,10 +782,9 @@ export default class AccountViewView extends Vue { const data = error.response?.data as ErrorResponse; this.limitsMessage = (data?.error?.message as string) || "Bad server response."; - console.log( + console.error( "Got bad response retrieving limits, which usually means user isn't registered. Server says:", this.limitsMessage, - //error, ); } else if ( error instanceof Error && From a60beb483cacc5de76bc88792c4b57d5d9dac9e4 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Fri, 8 Dec 2023 23:05:24 -0500 Subject: [PATCH 2/2] Adding alert dialogs --- src/App.vue | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/App.vue b/src/App.vue index 038ae3f..31bbc32 100644 --- a/src/App.vue +++ b/src/App.vue @@ -384,16 +384,13 @@ export default class App extends Vue { this.subscribeToPush() .then(() => { console.log("Subscribed successfully."); - // Assuming the subscription object is available return navigator.serviceWorker.ready; }) .then((registration) => { - // Fetch the existing subscription object from the registration return registration.pushManager.getSubscription(); }) .then((subscription) => { if (subscription) { - console.log(subscription); return this.sendSubscriptionToServer(subscription); } else { throw new Error("Subscription object is not available."); @@ -407,15 +404,16 @@ export default class App extends Vue { "Subscription or server communication failed:", error, ); + alert( "Subscription or server communication failed. Try again in a while." ); }); }) .catch((error) => { console.error("An error occurred:", error); - // Handle error appropriately here + alert( "Some error occurred." + error ); }); } - // Function to convert URL base64 to Uint8Array + private urlBase64ToUint8Array(base64String: string): Uint8Array { const padding = "=".repeat((4 - (base64String.length % 4)) % 4); const base64 = (base64String + padding)