Browse Source

Adding alert dialogs

kb/add-usage-guide
Matthew Raymer 10 months ago
parent
commit
a60beb483c
  1. 8
      src/App.vue

8
src/App.vue

@ -384,16 +384,13 @@ export default class App extends Vue {
this.subscribeToPush() this.subscribeToPush()
.then(() => { .then(() => {
console.log("Subscribed successfully."); console.log("Subscribed successfully.");
// Assuming the subscription object is available
return navigator.serviceWorker.ready; return navigator.serviceWorker.ready;
}) })
.then((registration) => { .then((registration) => {
// Fetch the existing subscription object from the registration
return registration.pushManager.getSubscription(); return registration.pushManager.getSubscription();
}) })
.then((subscription) => { .then((subscription) => {
if (subscription) { if (subscription) {
console.log(subscription);
return this.sendSubscriptionToServer(subscription); return this.sendSubscriptionToServer(subscription);
} else { } else {
throw new Error("Subscription object is not available."); throw new Error("Subscription object is not available.");
@ -407,15 +404,16 @@ export default class App extends Vue {
"Subscription or server communication failed:", "Subscription or server communication failed:",
error, error,
); );
alert( "Subscription or server communication failed. Try again in a while." );
}); });
}) })
.catch((error) => { .catch((error) => {
console.error("An error occurred:", 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 { private urlBase64ToUint8Array(base64String: string): Uint8Array {
const padding = "=".repeat((4 - (base64String.length % 4)) % 4); const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
const base64 = (base64String + padding) const base64 = (base64String + padding)

Loading…
Cancel
Save