From 3498eb3395a2e3ce481f7ed5292068d81b6d83e0 Mon Sep 17 00:00:00 2001 From: Melroy van den Berg Date: Wed, 11 Sep 2024 12:21:38 +0200 Subject: [PATCH 1/2] Clean-up push controller js (#1105) --- assets/controllers/push_controller.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/assets/controllers/push_controller.js b/assets/controllers/push_controller.js index aa09e80960..b30542e0ad 100644 --- a/assets/controllers/push_controller.js +++ b/assets/controllers/push_controller.js @@ -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" }) From ac20a3284989345873711bba70f364634297b545 Mon Sep 17 00:00:00 2001 From: Melroy van den Berg Date: Wed, 11 Sep 2024 13:41:05 +0200 Subject: [PATCH 2/2] Clean up push controller js even more (#1111) --- assets/controllers/push_controller.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/assets/controllers/push_controller.js b/assets/controllers/push_controller.js index b30542e0ad..5808a49f10 100644 --- a/assets/controllers/push_controller.js +++ b/assets/controllers/push_controller.js @@ -74,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, @@ -83,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(), @@ -104,9 +101,6 @@ export default class extends Controller { throw response } return response.json() - }) - .then(data => { - }) .catch(error => { console.error(error) @@ -120,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(), @@ -135,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) }) }