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. This will be set when | |
michaelpg
2017/04/07 21:47:03
"button" singular?
stevenjb
2017/04/07 23:36:05
There are two, one in this page and one in the sub
| |
37 * the adapter state change or when the user changes the toggle. | |
38 * @private | |
39 */ | |
40 bluetoothToggleState_: { | |
michaelpg
2017/04/07 21:47:03
"state" is generally an unfortunate word, but hard
stevenjb
2017/04/07 23:36:05
I agree it isn't great, but there are not a lot of
| |
41 type: Boolean, | |
42 observer: 'bluetoothToggleStateChanged_', | |
43 }, | |
44 | |
45 /** | |
46 * Set to true before the adapter state is received, when the adapter is | |
47 * unavailable, and while an adapter state change is requested. This | |
48 * prevents user changes while a change is in progress or when the adapter | |
49 * is not available. | |
50 * @private | |
51 */ | |
52 bluetoothToggleDisabled_: { | |
53 type: Boolean, | |
54 value: true, | |
55 }, | |
56 | |
57 /** | |
43 * The cached bluetooth adapter state. | 58 * The cached bluetooth adapter state. |
44 * @type {!chrome.bluetooth.AdapterState|undefined} | 59 * @type {!chrome.bluetooth.AdapterState|undefined} |
45 * @private | 60 * @private |
46 */ | 61 */ |
47 adapterState_: { | 62 adapterState_: { |
48 type: Object, | 63 type: Object, |
49 notify: true, | 64 notify: true, |
50 }, | 65 }, |
51 | 66 |
52 /** | 67 /** |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 this.bluetooth.onAdapterStateChanged.removeListener( | 119 this.bluetooth.onAdapterStateChanged.removeListener( |
105 this.bluetoothAdapterStateChangedListener_); | 120 this.bluetoothAdapterStateChangedListener_); |
106 } | 121 } |
107 }, | 122 }, |
108 | 123 |
109 /** | 124 /** |
110 * @return {string} | 125 * @return {string} |
111 * @private | 126 * @private |
112 */ | 127 */ |
113 getIcon_: function() { | 128 getIcon_: function() { |
114 if (!this.bluetoothEnabled_) | 129 if (!this.bluetoothToggleState_) |
115 return 'settings:bluetooth-disabled'; | 130 return 'settings:bluetooth-disabled'; |
116 return 'settings:bluetooth'; | 131 return 'settings:bluetooth'; |
117 }, | 132 }, |
118 | 133 |
119 /** | 134 /** |
120 * @param {boolean} enabled | 135 * @param {boolean} enabled |
121 * @param {string} onstr | 136 * @param {string} onstr |
122 * @param {string} offstr | 137 * @param {string} offstr |
123 * @return {string} | 138 * @return {string} |
124 * @private | 139 * @private |
125 */ | 140 */ |
126 getOnOffString_: function(enabled, onstr, offstr) { | 141 getOnOffString_: function(enabled, onstr, offstr) { |
127 return enabled ? onstr : offstr; | 142 return enabled ? onstr : offstr; |
128 }, | 143 }, |
129 | 144 |
130 /** | 145 /** |
131 * Process bluetooth.onAdapterStateChanged events. | 146 * Process bluetooth.onAdapterStateChanged events. |
132 * @param {!chrome.bluetooth.AdapterState} state | 147 * @param {!chrome.bluetooth.AdapterState} state |
133 * @private | 148 * @private |
134 */ | 149 */ |
135 onBluetoothAdapterStateChanged_: function(state) { | 150 onBluetoothAdapterStateChanged_: function(state) { |
136 this.adapterState_ = state; | 151 this.adapterState_ = state; |
137 this.bluetoothEnabled_ = state.powered; | 152 this.bluetoothToggleState_ = state.powered; |
153 this.bluetoothToggleDisabled_ = !state.available; | |
138 }, | 154 }, |
139 | 155 |
140 /** @private */ | 156 /** @private */ |
141 onTap_: function() { | 157 onTap_: function() { |
142 if (this.adapterState_.available === false) | 158 if (this.adapterState_.available === false) |
143 return; | 159 return; |
144 if (!this.bluetoothEnabled_) | 160 if (!this.bluetoothToggleState_) |
145 this.bluetoothEnabled_ = true; | 161 this.bluetoothToggleState_ = true; |
146 else | 162 else |
147 this.openSubpage_(); | 163 this.openSubpage_(); |
148 }, | 164 }, |
149 | 165 |
150 /** | 166 /** |
151 * @param {Event} e | 167 * @param {Event} e |
152 * @private | 168 * @private |
153 */ | 169 */ |
154 stopTap_: function(e) { | 170 stopTap_: function(e) { |
155 e.stopPropagation(); | 171 e.stopPropagation(); |
156 }, | 172 }, |
157 | 173 |
158 /** | 174 /** |
159 * @param {Event} e | 175 * @param {Event} e |
160 * @private | 176 * @private |
161 */ | 177 */ |
162 onSubpageArrowTap_: function(e) { | 178 onSubpageArrowTap_: function(e) { |
163 this.openSubpage_(); | 179 this.openSubpage_(); |
164 e.stopPropagation(); | 180 e.stopPropagation(); |
165 }, | 181 }, |
166 | 182 |
167 /** @private */ | 183 /** @private */ |
168 bluetoothEnabledChanged_: function() { | 184 bluetoothToggleStateChanged_: function() { |
185 if (!this.adapterState_ || this.bluetoothToggleDisabled_ || | |
186 this.bluetoothToggleState_ == this.adapterState_.powered) { | |
187 return; | |
188 } | |
189 this.bluetoothToggleDisabled_ = true; | |
michaelpg
2017/04/07 21:47:03
I understand disabling at startup, but is disablin
stevenjb
2017/04/07 23:36:05
We do the disable specifically for times when it i
| |
169 this.bluetoothPrivate.setAdapterState( | 190 this.bluetoothPrivate.setAdapterState( |
170 {powered: this.bluetoothEnabled_}, function() { | 191 {powered: this.bluetoothToggleState_}, function() { |
171 if (chrome.runtime.lastError) { | 192 if (chrome.runtime.lastError) { |
172 console.error( | 193 console.error( |
173 'Error enabling bluetooth: ' + | 194 'Error enabling bluetooth: ' + |
174 chrome.runtime.lastError.message); | 195 chrome.runtime.lastError.message); |
175 } | 196 } |
176 }); | 197 }); |
177 }, | 198 }, |
178 | 199 |
179 /** @private */ | 200 /** @private */ |
180 openSubpage_: function() { | 201 openSubpage_: function() { |
181 settings.navigateTo(settings.Route.BLUETOOTH_DEVICES); | 202 settings.navigateTo(settings.Route.BLUETOOTH_DEVICES); |
182 } | 203 } |
183 }); | 204 }); |
OLD | NEW |