mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-17 22:36:35 +00:00
Migrate to push notification store
This commit is contained in:
parent
5962786494
commit
9b5ae6e8de
@ -1 +1 @@
|
|||||||
Subproject commit bf4adea64549d0adb95597f1846d90bc47648c0e
|
Subproject commit 3a2a1b288e1685cd6e5ce656656f1e5adb87fe76
|
@ -202,16 +202,17 @@ Polymer({
|
|||||||
|
|
||||||
supportPush: {
|
supportPush: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: 'PushManager' in window &&
|
value: false,
|
||||||
(document.location.protocol === 'https:' ||
|
bindNuclear: function (hass) {
|
||||||
document.location.hostname === 'localhost' ||
|
return hass.pushNotificationGetters.isSupported;
|
||||||
document.location.hostname === '127.0.0.1'),
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
pushToggleChecked: {
|
pushToggleChecked: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: 'Notification' in window &&
|
bindNuclear: function (hass) {
|
||||||
Notification.permission === 'granted',
|
return hass.pushNotificationGetters.isActive;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -294,53 +295,18 @@ Polymer({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handlePushChange: function (ev) {
|
handlePushChange: function (ev) {
|
||||||
var subscribe = ev.target.checked;
|
if (ev.target.checked) {
|
||||||
|
this.hass.pushNotificationActions.subscribePushNotifications()
|
||||||
// MVP, will move later.
|
.then(function (success) {
|
||||||
var promise = navigator.serviceWorker.getRegistration().then(function (reg) {
|
this.pushToggleChecked = success;
|
||||||
if (!reg) {
|
|
||||||
throw new Error('No service worker registered');
|
|
||||||
}
|
|
||||||
|
|
||||||
return reg.pushManager.subscribe({
|
|
||||||
userVisibleOnly: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!subscribe) {
|
|
||||||
promise.then(function (sub) {
|
|
||||||
sub.unsubscribe();
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
promise.then(function (sub) {
|
|
||||||
var browserName;
|
|
||||||
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
|
|
||||||
browserName = 'firefox';
|
|
||||||
} else {
|
|
||||||
browserName = 'chrome';
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.hass.callApi('POST', 'notify.html5', {
|
|
||||||
subscription: sub,
|
|
||||||
browser: browserName,
|
|
||||||
});
|
|
||||||
}.bind(this)).catch(function (err) {
|
|
||||||
var message;
|
|
||||||
|
|
||||||
if (err.message && err.message.indexOf('gcm_sender_id') !== -1) {
|
|
||||||
message = 'Please setup the notify.html5 platform.';
|
|
||||||
} else {
|
|
||||||
message = 'Notification registration failed.';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
console.error(err);
|
|
||||||
/* eslint-enable no-console */
|
|
||||||
this.hass.notificationActions.createNotification(message);
|
|
||||||
this.pushToggleChecked = false;
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.hass.pushNotificationActions.unsubscribePushNotifications()
|
||||||
|
.then(function (success) {
|
||||||
|
this.pushToggleChecked = !success;
|
||||||
|
}.bind(this));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleLogOut: function () {
|
handleLogOut: function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user