diff --git a/src/components/ha-push-notifications-toggle.js b/src/components/ha-push-notifications-toggle.js index fe76ec6de..6d5b0d7fe 100644 --- a/src/components/ha-push-notifications-toggle.js +++ b/src/components/ha-push-notifications-toggle.js @@ -4,29 +4,31 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import EventsMixin from '../mixins/events-mixin.js'; +export const pushSupported = ( + 'serviceWorker' in navigator && 'PushManager' in window && + (document.location.protocol === 'https:' || + document.location.hostname === 'localhost' || + document.location.hostname === '127.0.0.1')); + /* * @appliesMixin EventsMixin */ class HaPushNotificationsToggle extends EventsMixin(PolymerElement) { static get template() { return html` - + `; } static get properties() { return { hass: { type: Object, value: null }, - pushSupported: { + disabled: { type: Boolean, - readOnly: true, - notify: true, - value: ( - 'serviceWorker' in navigator && 'PushManager' in window && - (document.location.protocol === 'https:' || - document.location.hostname === 'localhost' || - document.location.hostname === '127.0.0.1') - ) + value: false, }, pushChecked: { type: Boolean, @@ -40,22 +42,20 @@ class HaPushNotificationsToggle extends EventsMixin(PolymerElement) { }; } - connectedCallback() { + async connectedCallback() { super.connectedCallback(); - if (!this.pushSupported) return; - navigator.serviceWorker.ready.then( - (reg) => { - reg.pushManager.getSubscription().then((subscription) => { - this.loading = false; - this.pushChecked = !!subscription; - }); - }, - () => { - // no service worker. - this._setPushSupported(false); - } - ); + if (!('serviceWorker' in navigator)) return; + + try { + const reg = await navigator.serviceWorker.ready; + reg.pushManager.getSubscription().then((subscription) => { + this.loading = false; + this.pushChecked = !!subscription; + }); + } catch (err) { + // We don't set loading to `false` so we remain disabled + } } handlePushChange(pushChecked) { if (!this.pushSupported) return; @@ -121,6 +121,10 @@ class HaPushNotificationsToggle extends EventsMixin(PolymerElement) { }); }); } + + _compDisabled(disabled, loading) { + return disabled || loading; + } } customElements.define('ha-push-notifications-toggle', HaPushNotificationsToggle); diff --git a/src/panels/config/core/ha-config-core.js b/src/panels/config/core/ha-config-core.js index 8f090eba0..9ef6f6a05 100644 --- a/src/panels/config/core/ha-config-core.js +++ b/src/panels/config/core/ha-config-core.js @@ -4,15 +4,11 @@ import '@polymer/paper-icon-button/paper-icon-button.js'; import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js'; -import '../../../layouts/ha-app-layout.js'; +import '../../../layouts/hass-subpage.js'; import '../../../resources/ha-style.js'; import './ha-config-section-core.js'; -import './ha-config-section-push-notifications.js'; -import './ha-config-section-themes.js'; -import './ha-config-section-translation.js'; -import isComponentLoaded from '../../../common/config/is_component_loaded.js'; import LocalizeMixin from '../../../mixins/localize-mixin.js'; /* @@ -37,33 +33,11 @@ class HaConfigCore extends LocalizeMixin(PolymerElement) { } - - - - -
[[localize('ui.panel.config.core.caption')]]
-
-
- +
- - - - - -
-
+ `; } @@ -71,34 +45,12 @@ class HaConfigCore extends LocalizeMixin(PolymerElement) { return { hass: Object, isWide: Boolean, - pushSupported: { - type: Boolean, - value: true, - }, }; } computeClasses(isWide) { return isWide ? 'content' : 'content narrow'; } - - computeIsZwaveLoaded(hass) { - return isComponentLoaded(hass, 'config.zwave'); - } - - computeIsTranslationLoaded(hass) { - return hass.translationMetadata && - Object.keys(hass.translationMetadata.translations).length; - } - - computeIsThemesLoaded(hass) { - return hass.themes && hass.themes.themes && - Object.keys(hass.themes.themes).length; - } - - _backTapped() { - history.back(); - } } customElements.define('ha-config-core', HaConfigCore); diff --git a/src/panels/config/core/ha-config-section-push-notifications.js b/src/panels/config/core/ha-config-section-push-notifications.js deleted file mode 100644 index eb5ac25a3..000000000 --- a/src/panels/config/core/ha-config-section-push-notifications.js +++ /dev/null @@ -1,53 +0,0 @@ -import '@polymer/iron-flex-layout/iron-flex-layout-classes.js'; -import '@polymer/iron-label/iron-label.js'; -import '@polymer/paper-card/paper-card.js'; -import { html } from '@polymer/polymer/lib/utils/html-tag.js'; -import { PolymerElement } from '@polymer/polymer/polymer-element.js'; - -import '../../../components/ha-push-notifications-toggle.js'; - -import '../ha-config-section.js'; -import LocalizeMixin from '../../../mixins/localize-mixin.js'; - -/* - * @appliesMixin LocalizeMixin - */ -class HaConfigSectionPushNotifications extends LocalizeMixin(PolymerElement) { - static get template() { - return html` - - - [[localize('ui.panel.config.core.section.push_notifications.header')]] - - [[localize('ui.panel.config.core.section.push_notifications.introduction')]] - - - -
- - [[localize('ui.panel.config.core.section.push_notifications.push_notifications')]] - - -
-
-
-`; - } - - static get properties() { - return { - hass: Object, - isWide: Boolean, - pushSupported: { - type: Boolean, - notify: true, - }, - }; - } -} - -customElements.define('ha-config-section-push-notifications', HaConfigSectionPushNotifications); diff --git a/src/panels/profile/ha-change-password-card.js b/src/panels/profile/ha-change-password-card.js index b841e630e..4e7657f5b 100644 --- a/src/panels/profile/ha-change-password-card.js +++ b/src/panels/profile/ha-change-password-card.js @@ -23,8 +23,6 @@ class HaChangePasswordCard extends PolymerElement { } paper-card { display: block; - max-width: 600px; - margin: 16px auto; } .currentPassword { margin-top: -4px; @@ -48,22 +46,24 @@ class HaChangePasswordCard extends PolymerElement { auto-validate error-message='Required' > - - +