| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'Settings page for managing bluetooth properties and devices. This page | 7 * 'Settings page for managing bluetooth properties and devices. This page |
| 8 * just provodes a summary and link to the subpage. | 8 * just provodes a summary and link to the subpage. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 Polymer({ | 25 Polymer({ |
| 26 is: 'settings-bluetooth-page', | 26 is: 'settings-bluetooth-page', |
| 27 | 27 |
| 28 properties: { | 28 properties: { |
| 29 /** Preferences state. */ | 29 /** Preferences state. */ |
| 30 prefs: { | 30 prefs: { |
| 31 type: Object, | 31 type: Object, |
| 32 notify: true, | 32 notify: true, |
| 33 }, | 33 }, |
| 34 | 34 |
| 35 /** @private */ | |
| 36 bluetoothEnabled_: { | |
| 37 type: Boolean, | |
| 38 observer: 'bluetoothEnabledChanged_', | |
| 39 notify: true, | |
| 40 }, | |
| 41 | |
| 42 /** | 35 /** |
| 36 * Reflects the current state of the toggle buttons (in this page and the |
| 37 * subpage). This will be set when the adapter state change or when the user |
| 38 * changes the toggle. |
| 39 * @private |
| 40 */ |
| 41 bluetoothToggleState_: { |
| 42 type: Boolean, |
| 43 observer: 'bluetoothToggleStateChanged_', |
| 44 }, |
| 45 |
| 46 /** |
| 47 * Set to true before the adapter state is received, when the adapter is |
| 48 * unavailable, and while an adapter state change is requested. This |
| 49 * prevents user changes while a change is in progress or when the adapter |
| 50 * is not available. |
| 51 * @private |
| 52 */ |
| 53 bluetoothToggleDisabled_: { |
| 54 type: Boolean, |
| 55 value: true, |
| 56 }, |
| 57 |
| 58 /** |
| 43 * The cached bluetooth adapter state. | 59 * The cached bluetooth adapter state. |
| 44 * @type {!chrome.bluetooth.AdapterState|undefined} | 60 * @type {!chrome.bluetooth.AdapterState|undefined} |
| 45 * @private | 61 * @private |
| 46 */ | 62 */ |
| 47 adapterState_: { | 63 adapterState_: { |
| 48 type: Object, | 64 type: Object, |
| 49 notify: true, | 65 notify: true, |
| 50 }, | 66 }, |
| 51 | 67 |
| 52 /** | 68 /** |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 this.bluetooth.onAdapterStateChanged.removeListener( | 120 this.bluetooth.onAdapterStateChanged.removeListener( |
| 105 this.bluetoothAdapterStateChangedListener_); | 121 this.bluetoothAdapterStateChangedListener_); |
| 106 } | 122 } |
| 107 }, | 123 }, |
| 108 | 124 |
| 109 /** | 125 /** |
| 110 * @return {string} | 126 * @return {string} |
| 111 * @private | 127 * @private |
| 112 */ | 128 */ |
| 113 getIcon_: function() { | 129 getIcon_: function() { |
| 114 if (!this.bluetoothEnabled_) | 130 if (!this.bluetoothToggleState_) |
| 115 return 'settings:bluetooth-disabled'; | 131 return 'settings:bluetooth-disabled'; |
| 116 return 'settings:bluetooth'; | 132 return 'settings:bluetooth'; |
| 117 }, | 133 }, |
| 118 | 134 |
| 119 /** | 135 /** |
| 120 * @param {boolean} enabled | 136 * @param {boolean} enabled |
| 121 * @param {string} onstr | 137 * @param {string} onstr |
| 122 * @param {string} offstr | 138 * @param {string} offstr |
| 123 * @return {string} | 139 * @return {string} |
| 124 * @private | 140 * @private |
| 125 */ | 141 */ |
| 126 getOnOffString_: function(enabled, onstr, offstr) { | 142 getOnOffString_: function(enabled, onstr, offstr) { |
| 127 return enabled ? onstr : offstr; | 143 return enabled ? onstr : offstr; |
| 128 }, | 144 }, |
| 129 | 145 |
| 130 /** | 146 /** |
| 131 * Process bluetooth.onAdapterStateChanged events. | 147 * Process bluetooth.onAdapterStateChanged events. |
| 132 * @param {!chrome.bluetooth.AdapterState} state | 148 * @param {!chrome.bluetooth.AdapterState} state |
| 133 * @private | 149 * @private |
| 134 */ | 150 */ |
| 135 onBluetoothAdapterStateChanged_: function(state) { | 151 onBluetoothAdapterStateChanged_: function(state) { |
| 136 this.adapterState_ = state; | 152 this.adapterState_ = state; |
| 137 this.bluetoothEnabled_ = state.powered; | 153 this.bluetoothToggleState_ = state.powered; |
| 154 this.bluetoothToggleDisabled_ = !state.available; |
| 138 }, | 155 }, |
| 139 | 156 |
| 140 /** @private */ | 157 /** @private */ |
| 141 onTap_: function() { | 158 onTap_: function() { |
| 142 if (this.adapterState_.available === false) | 159 if (this.adapterState_.available === false) |
| 143 return; | 160 return; |
| 144 if (!this.bluetoothEnabled_) | 161 if (!this.bluetoothToggleState_) |
| 145 this.bluetoothEnabled_ = true; | 162 this.bluetoothToggleState_ = true; |
| 146 else | 163 else |
| 147 this.openSubpage_(); | 164 this.openSubpage_(); |
| 148 }, | 165 }, |
| 149 | 166 |
| 150 /** | 167 /** |
| 151 * @param {Event} e | 168 * @param {Event} e |
| 152 * @private | 169 * @private |
| 153 */ | 170 */ |
| 154 stopTap_: function(e) { | 171 stopTap_: function(e) { |
| 155 e.stopPropagation(); | 172 e.stopPropagation(); |
| 156 }, | 173 }, |
| 157 | 174 |
| 158 /** | 175 /** |
| 159 * @param {Event} e | 176 * @param {Event} e |
| 160 * @private | 177 * @private |
| 161 */ | 178 */ |
| 162 onSubpageArrowTap_: function(e) { | 179 onSubpageArrowTap_: function(e) { |
| 163 this.openSubpage_(); | 180 this.openSubpage_(); |
| 164 e.stopPropagation(); | 181 e.stopPropagation(); |
| 165 }, | 182 }, |
| 166 | 183 |
| 167 /** @private */ | 184 /** @private */ |
| 168 bluetoothEnabledChanged_: function() { | 185 bluetoothToggleStateChanged_: function() { |
| 186 if (!this.adapterState_ || this.bluetoothToggleDisabled_ || |
| 187 this.bluetoothToggleState_ == this.adapterState_.powered) { |
| 188 return; |
| 189 } |
| 190 this.bluetoothToggleDisabled_ = true; |
| 169 this.bluetoothPrivate.setAdapterState( | 191 this.bluetoothPrivate.setAdapterState( |
| 170 {powered: this.bluetoothEnabled_}, function() { | 192 {powered: this.bluetoothToggleState_}, function() { |
| 171 if (chrome.runtime.lastError) { | 193 if (chrome.runtime.lastError) { |
| 172 console.error( | 194 console.error( |
| 173 'Error enabling bluetooth: ' + | 195 'Error enabling bluetooth: ' + |
| 174 chrome.runtime.lastError.message); | 196 chrome.runtime.lastError.message); |
| 175 } | 197 } |
| 176 }); | 198 }); |
| 177 }, | 199 }, |
| 178 | 200 |
| 179 /** @private */ | 201 /** @private */ |
| 180 openSubpage_: function() { | 202 openSubpage_: function() { |
| 181 settings.navigateTo(settings.Route.BLUETOOTH_DEVICES); | 203 settings.navigateTo(settings.Route.BLUETOOTH_DEVICES); |
| 182 } | 204 } |
| 183 }); | 205 }); |
| OLD | NEW |