Browse Source

Merge branch 'sw-cleanup'

yml-fixes
Matthew Raymer 11 months ago
parent
commit
4078853558
  1. 8
      src/App.vue
  2. 36
      src/views/AccountViewView.vue

8
src/App.vue

@ -426,16 +426,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.");
@ -449,15 +446,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)

36
src/views/AccountViewView.vue

@ -105,7 +105,12 @@
<!-- toggle --> <!-- toggle -->
<div class="relative ml-2"> <div class="relative ml-2">
<!-- input --> <!-- input -->
<input type="checkbox" name="toggleNotifications" class="sr-only" /> <input
type="checkbox"
v-model="toggleNotifications"
name="toggleNotifications"
class="sr-only"
/>
<!-- line --> <!-- line -->
<div class="block bg-slate-500 w-14 h-8 rounded-full"></div> <div class="block bg-slate-500 w-14 h-8 rounded-full"></div>
<!-- dot --> <!-- dot -->
@ -136,6 +141,7 @@
type="checkbox" type="checkbox"
name="toggleMuteNotifications" name="toggleMuteNotifications"
class="sr-only" class="sr-only"
disabled
/> />
<!-- line --> <!-- line -->
<div class="block bg-slate-500 w-14 h-8 rounded-full"></div> <div class="block bg-slate-500 w-14 h-8 rounded-full"></div>
@ -451,6 +457,16 @@ export default class AccountViewView extends Vue {
showAdvanced = false; showAdvanced = false;
private isSubscribed = false;
get toggleNotifications() {
return this.isSubscribed;
}
set toggleNotifications(value) {
this.isSubscribed = value;
}
public async getIdentity(activeDid: string): Promise<IIdentifier | null> { public async getIdentity(activeDid: string): Promise<IIdentifier | null> {
try { try {
// Open the accounts database // Open the accounts database
@ -533,6 +549,7 @@ export default class AccountViewView extends Vue {
* @throws Will display specific messages to the user based on different errors. * @throws Will display specific messages to the user based on different errors.
*/ */
async created() { async created() {
console.error("created");
try { try {
await db.open(); await db.open();
@ -551,6 +568,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. * Initializes component state with values from the database or defaults.
* @param {SettingsType} settings - Object containing settings from the database. * @param {SettingsType} settings - Object containing settings from the database.
@ -760,7 +789,7 @@ export default class AccountViewView extends Vue {
}); });
this.isRegistered = true; this.isRegistered = true;
} catch (err) { } catch (err) {
console.log("Got an error updating settings:", err); console.error("Got an error updating settings:", err);
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
@ -802,10 +831,9 @@ export default class AccountViewView extends Vue {
const data = error.response?.data as ErrorResponse; const data = error.response?.data as ErrorResponse;
this.limitsMessage = this.limitsMessage =
(data?.error?.message as string) || "Bad server response."; (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:", "Got bad response retrieving limits, which usually means user isn't registered. Server says:",
this.limitsMessage, this.limitsMessage,
//error,
); );
} else if ( } else if (
error instanceof Error && error instanceof Error &&

Loading…
Cancel
Save