Fix enabling and disabling push notifications.

This commit is contained in:
Richard Lewis 2019-08-02 15:53:31 +03:00 committed by Pavel Djundik
parent 467ebab31f
commit 7fd48d8155
2 changed files with 18 additions and 6 deletions

View File

@ -264,8 +264,9 @@
id="pushNotifications" id="pushNotifications"
type="button" type="button"
class="btn" class="btn"
disabled :disabled="$root.pushNotificationState !== 'supported'"
data-text-alternate="Unsubscribe from push notifications" data-text-alternate="Unsubscribe from push notifications"
@click="onPushButtonClick"
>Subscribe to push notifications</button> >Subscribe to push notifications</button>
<div <div
v-if="$root.pushNotificationState === 'nohttps'" v-if="$root.pushNotificationState === 'nohttps'"
@ -533,6 +534,10 @@ export default {
if (window.navigator.registerProtocolHandler) { if (window.navigator.registerProtocolHandler) {
this.canRegisterProtocol = true; this.canRegisterProtocol = true;
} }
// TODO: Rework push notification code to avoid reinitializing it here
const webpush = require("../../js/webpush");
webpush.initialize();
}, },
methods: { methods: {
onChange(event) { onChange(event) {
@ -603,6 +608,10 @@ export default {
pop.src = "audio/pop.wav"; pop.src = "audio/pop.wav";
pop.play(); pop.play();
}, },
onPushButtonClick() {
const webpush = require("../../js/webpush"); // TODO: do this in a smarter way
webpush.onPushButton();
},
}, },
}; };
</script> </script>

View File

@ -67,13 +67,16 @@ module.exports.initialize = () => {
alternatePushButton(); alternatePushButton();
} }
}); });
}).catch(() => { })
vueApp.pushNotificationState = "unsupported"; .catch(() => {
}); vueApp.pushNotificationState = "unsupported";
});
} }
}; };
function onPushButton() { module.exports.onPushButton = () => {
// TODO: move dom logic to Settings.vue
pushNotificationsButton = $("#pushNotifications");
pushNotificationsButton.prop("disabled", true); pushNotificationsButton.prop("disabled", true);
navigator.serviceWorker.ready navigator.serviceWorker.ready
@ -127,7 +130,7 @@ function onPushButton() {
}); });
return false; return false;
} };
function alternatePushButton() { function alternatePushButton() {
const text = pushNotificationsButton.text(); const text = pushNotificationsButton.text();