Skip to content

Commit

Permalink
Merge branch 'main' into new/bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
BentiGorlich authored Sep 11, 2024
2 parents 63c8b53 + ac20a32 commit 6039939
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions assets/controllers/push_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ export default class extends Controller {

connect() {
this.applicationServerPublicKey = this.element.dataset.applicationServerPublicKey
console.log("got application server public key", this.applicationServerPublicKey)
window.navigator.serviceWorker.getRegistration()
.then((registration) => {
console.log("got service worker registration", registration)
return registration?.pushManager.getSubscription()
})
.then(pushSubscription => {
this.updateButtonVisibility(pushSubscription)
})
.catch((error) => {
console.log("there was an error in the connect method", error)
console.error("There was an error in the service worker registration method", error)
this.element.style.display = "none"
})

Expand Down Expand Up @@ -76,7 +74,6 @@ export default class extends Controller {
this.askPermission()
.then(() => window.navigator.serviceWorker.getRegistration())
.then(registration => {
console.log("got service worker registration:", registration)
const subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: this.applicationServerPublicKey,
Expand All @@ -85,10 +82,8 @@ export default class extends Controller {
return registration.pushManager.subscribe(subscribeOptions)
})
.then(pushSubscription => {
console.log("Received PushSubscription: ", JSON.stringify(pushSubscription))
this.updateButtonVisibility(pushSubscription)
const jsonSub = pushSubscription.toJSON()
console.log("registering push to server")
let payload = {
endpoint: pushSubscription.endpoint,
deviceKey: this.getDeviceKey(),
Expand All @@ -106,9 +101,6 @@ export default class extends Controller {
throw response
}
return response.json()
})
.then(data => {

})
.catch(error => {
console.error(error)
Expand All @@ -122,7 +114,6 @@ export default class extends Controller {
.then(pushSubscription => pushSubscription.unsubscribe())
.then((successful) => {
if (successful) {
console.log("removed push subscription")
this.updateButtonVisibility(null)
let payload = {
deviceKey: this.getDeviceKey(),
Expand All @@ -137,6 +128,9 @@ export default class extends Controller {
})
.catch(error => console.error(error))
}
})
.catch((error) => {
console.error("There was an error in the service worker registration method, for unsubscribing", error)
})
}

Expand Down

0 comments on commit 6039939

Please sign in to comment.