OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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-power' is the settings subpage for power settings. | 7 * 'settings-power' is the settings subpage for power settings. |
8 */ | 8 */ |
9 | 9 |
10 Polymer({ | 10 Polymer({ |
11 is: 'settings-power', | 11 is: 'settings-power', |
12 | 12 |
13 behaviors: [ | 13 behaviors: [ |
14 I18nBehavior, | 14 I18nBehavior, |
15 WebUIListenerBehavior, | 15 WebUIListenerBehavior, |
16 ], | 16 ], |
17 | 17 |
18 properties: { | 18 properties: { |
19 enablePowerSettings: Boolean, | 19 enablePowerSettings: Boolean, |
20 | 20 |
21 /** @private {string} ID of the selected power source, or ''. */ | 21 /** @private {string} ID of the selected power source, or ''. */ |
22 selectedPowerSourceId_: String, | 22 selectedPowerSourceId_: String, |
23 | 23 |
24 /** @private {!settings.BatteryStatus|undefined} */ | 24 /** @private {!settings.BatteryStatus|undefined} */ |
25 batteryStatus_: Object, | 25 batteryStatus_: Object, |
26 | 26 |
27 /** @private {boolean} Whether a low-power (USB) charger is being used. */ | 27 /** @private {boolean} Whether a low-power (USB) charger is being used. */ |
28 lowPowerCharger_: Boolean, | 28 lowPowerCharger_: Boolean, |
29 | 29 |
30 /** @private {boolean} Whether the idle behavior is managed. */ | |
31 idleManaged_: Boolean, | |
32 | |
33 /** @private {boolean} Whether the lid-closed behavior is managed. */ | |
34 lidClosedManaged_: Boolean, | |
35 | |
36 /** @private {boolean} Whether the system posesses a lid. */ | |
37 hasLid_: Boolean, | |
38 | |
30 /** | 39 /** |
31 * List of available dual-role power sources, if enablePowerSettings is on. | 40 * List of available dual-role power sources, if enablePowerSettings is on. |
32 * @private {!Array<!settings.PowerSource>|undefined} | 41 * @private {!Array<!settings.PowerSource>|undefined} |
33 */ | 42 */ |
34 powerSources_: Array, | 43 powerSources_: Array, |
35 | 44 |
36 /** @private */ | 45 /** @private */ |
37 powerSourceLabel_: { | 46 powerSourceLabel_: { |
38 type: String, | 47 type: String, |
39 computed: | 48 computed: |
40 'computePowerSourceLabel_(powerSources_, batteryStatus_.calculating)', | 49 'computePowerSourceLabel_(powerSources_, batteryStatus_.calculating)', |
41 }, | 50 }, |
42 | 51 |
43 /** @private */ | 52 /** @private */ |
44 showPowerSourceDropdown_: { | 53 showPowerSourceDropdown_: { |
45 type: Boolean, | 54 type: Boolean, |
46 computed: 'computeShowPowerSourceDropdown_(powerSources_)', | 55 computed: 'computeShowPowerSourceDropdown_(powerSources_)', |
47 value: false, | 56 value: false, |
48 }, | 57 }, |
49 | 58 |
50 /** | 59 /** |
51 * The name of the dedicated charging device being used, if present. | 60 * The name of the dedicated charging device being used, if present. |
52 * @private {string} | 61 * @private {string} |
53 */ | 62 */ |
54 powerSourceName_: { | 63 powerSourceName_: { |
55 type: String, | 64 type: String, |
56 computed: 'computePowerSourceName_(powerSources_, lowPowerCharger_)', | 65 computed: 'computePowerSourceName_(powerSources_, lowPowerCharger_)', |
57 }, | 66 }, |
67 | |
68 /** @private */ | |
69 idleOptions_: { | |
70 type: Array, | |
71 computed: 'computeIdleOptions_(idleManaged_)', | |
72 }, | |
73 | |
74 /** @private */ | |
75 lidClosedOptions_: { | |
76 type: Array, | |
77 computed: 'computeLidClosedOptions_(lidClosedManaged_)', | |
78 }, | |
58 }, | 79 }, |
59 | 80 |
60 /** @override */ | 81 /** @override */ |
61 ready: function() { | 82 ready: function() { |
62 // enablePowerSettings comes from loadTimeData, so it will always be set | 83 // enablePowerSettings comes from loadTimeData, so it will always be set |
63 // before attached() is called. | 84 // before attached() is called. |
64 if (!this.enablePowerSettings) | 85 if (!this.enablePowerSettings) |
65 settings.navigateToPreviousRoute(); | 86 settings.navigateToPreviousRoute(); |
66 }, | 87 }, |
67 | 88 |
68 /** @override */ | 89 /** @override */ |
69 attached: function() { | 90 attached: function() { |
70 this.addWebUIListener( | 91 this.addWebUIListener( |
71 'battery-status-changed', this.set.bind(this, 'batteryStatus_')); | 92 'battery-status-changed', this.set.bind(this, 'batteryStatus_')); |
72 this.addWebUIListener( | 93 this.addWebUIListener( |
73 'power-sources-changed', this.powerSourcesChanged_.bind(this)); | 94 'power-sources-changed', this.powerSourcesChanged_.bind(this)); |
74 settings.DevicePageBrowserProxyImpl.getInstance().updatePowerStatus(); | 95 settings.DevicePageBrowserProxyImpl.getInstance().updatePowerStatus(); |
96 | |
97 this.addWebUIListener( | |
98 'power-management-settings-changed', | |
99 this.powerManagementSettingsChanged_.bind(this)); | |
100 settings.DevicePageBrowserProxyImpl.getInstance() | |
101 .requestPowerManagementSettings(); | |
75 }, | 102 }, |
76 | 103 |
77 /** | 104 /** |
78 * @param {!Array<!settings.PowerSource>|undefined} powerSources | 105 * @param {!Array<!settings.PowerSource>|undefined} powerSources |
79 * @param {boolean} calculating | 106 * @param {boolean} calculating |
80 * @return {string} The primary label for the power source row. | 107 * @return {string} The primary label for the power source row. |
81 * @private | 108 * @private |
82 */ | 109 */ |
83 computePowerSourceLabel_: function(powerSources, calculating) { | 110 computePowerSourceLabel_: function(powerSources, calculating) { |
84 return this.i18n( | 111 return this.i18n( |
(...skipping 21 matching lines...) Expand all Loading... | |
106 * @private | 133 * @private |
107 */ | 134 */ |
108 computePowerSourceName_: function(powerSources, lowPowerCharger) { | 135 computePowerSourceName_: function(powerSources, lowPowerCharger) { |
109 if (lowPowerCharger) | 136 if (lowPowerCharger) |
110 return this.i18n('powerSourceLowPowerCharger'); | 137 return this.i18n('powerSourceLowPowerCharger'); |
111 if (powerSources.length) | 138 if (powerSources.length) |
112 return this.i18n('powerSourceAcAdapter'); | 139 return this.i18n('powerSourceAcAdapter'); |
113 return ''; | 140 return ''; |
114 }, | 141 }, |
115 | 142 |
116 onPowerSourceChange_: function() { | 143 /** |
117 settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource( | 144 * @param {boolean} idleManaged |
118 this.$$('#powerSource').value); | 145 * @return {!Array<!{value: settings.IdleBehavior, name: string}>} Options to |
146 * display in idle-behavior select. | |
147 * @private | |
148 */ | |
149 computeIdleOptions_: function(idleManaged) { | |
150 var options = [ | |
151 { | |
152 value: settings.IdleBehavior.DISPLAY_OFF_SLEEP, | |
153 name: loadTimeData.getString('powerIdleDisplayOffSleep'), | |
154 }, | |
155 { | |
156 value: settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE, | |
157 name: loadTimeData.getString('powerIdleDisplayOffStayAwake'), | |
158 }, | |
159 { | |
160 value: settings.IdleBehavior.DISPLAY_ON, | |
161 name: loadTimeData.getString('powerIdleDisplayOn'), | |
162 }, | |
163 ]; | |
164 if (idleManaged) { | |
165 options.push({ | |
166 value: settings.IdleBehavior.OTHER, | |
167 name: loadTimeData.getString('powerIdleOther'), | |
168 }); | |
169 } | |
170 return options; | |
119 }, | 171 }, |
120 | 172 |
121 /** | 173 /** |
174 * @param {boolean} lidClosedManaged | |
175 * @return {!Array<!{value: settings.LidClosedBehavior, name: string}>} | |
176 * Options to display in lid-closed-behavior select. | |
177 * @private | |
178 */ | |
179 computeLidClosedOptions_: function(lidClosedManaged) { | |
180 var options = [ | |
181 { | |
182 value: settings.LidClosedBehavior.SUSPEND, | |
183 name: loadTimeData.getString('powerLidClosedSleep'), | |
184 }, | |
185 { | |
186 value: settings.LidClosedBehavior.DO_NOTHING, | |
187 name: loadTimeData.getString('powerLidClosedStayAwake'), | |
188 }, | |
189 ]; | |
190 if (lidClosedManaged) { | |
191 // Some options are only settable via policy. | |
192 options.push({ | |
193 value: settings.LidClosedBehavior.STOP_SESSION, | |
194 name: loadTimeData.getString('powerLidClosedSignOut'), | |
195 }, { | |
196 value: settings.LidClosedBehavior.SHUT_DOWN, | |
197 name: loadTimeData.getString('powerLidClosedShutDown'), | |
198 }); | |
199 } | |
200 return options; | |
201 }, | |
202 | |
203 /** @private */ | |
204 onPowerSourceChange_: function() { | |
205 settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource( | |
206 this.$.powerSource.value); | |
207 }, | |
208 | |
209 /** @private */ | |
210 onIdleSelectChange_: function() { | |
211 var behavior = /** @type {settings.IdleBehavior} */ | |
212 (parseInt(this.$.idleSelect.value, 10)); | |
213 settings.DevicePageBrowserProxyImpl.getInstance().setIdleBehavior(behavior); | |
214 }, | |
215 | |
216 /** @private */ | |
217 onLidClosedSelectChange_: function() { | |
218 var behavior = /** @type {settings.LidClosedBehavior} */ | |
219 (parseInt(this.$.lidClosedSelect.value, 10)); | |
220 settings.DevicePageBrowserProxyImpl.getInstance().setLidClosedBehavior( | |
221 behavior); | |
222 }, | |
223 | |
224 /** | |
122 * @param {!Array<settings.PowerSource>} sources External power sources. | 225 * @param {!Array<settings.PowerSource>} sources External power sources. |
123 * @param {string} selectedId The ID of the currently used power source. | 226 * @param {string} selectedId The ID of the currently used power source. |
124 * @param {boolean} lowPowerCharger Whether the currently used power source | 227 * @param {boolean} lowPowerCharger Whether the currently used power source |
125 * is a low-powered USB charger. | 228 * is a low-powered USB charger. |
126 * @private | 229 * @private |
127 */ | 230 */ |
128 powerSourcesChanged_: function(sources, selectedId, lowPowerCharger) { | 231 powerSourcesChanged_: function(sources, selectedId, lowPowerCharger) { |
129 this.powerSources_ = sources; | 232 this.powerSources_ = sources; |
130 this.selectedPowerSourceId_ = selectedId; | 233 this.selectedPowerSourceId_ = selectedId; |
131 this.lowPowerCharger_ = lowPowerCharger; | 234 this.lowPowerCharger_ = lowPowerCharger; |
132 }, | 235 }, |
133 | 236 |
134 /** | 237 /** |
238 * @param {!settings.PowerManagementSettings} settings Current power | |
239 * management settings. | |
240 * @private | |
241 */ | |
242 powerManagementSettingsChanged_: function(settings) { | |
243 this.idleManaged_ = settings.idleManaged; | |
244 this.lidClosedManaged_ = settings.lidClosedManaged; | |
245 this.hasLid_ = settings.hasLid; | |
246 | |
247 // The select elements include "Other" options when managed but omit them | |
248 // otherwise. Make sure that the options are there before we potentially try | |
249 // to select them. | |
250 Polymer.dom.flush(); | |
michaelpg
2017/06/16 01:35:00
use this.async(function() {...}); instead of forci
Daniel Erat
2017/06/16 02:34:24
hmm. i had this.async earlier (after you suggested
| |
251 this.$.idleSelect.value = settings.idleBehavior; | |
252 this.$.lidClosedSelect.value = settings.lidClosedBehavior; | |
253 }, | |
254 | |
255 /** | |
135 * @param {*} lhs | 256 * @param {*} lhs |
136 * @param {*} rhs | 257 * @param {*} rhs |
137 * @return {boolean} | 258 * @return {boolean} |
138 * @private | 259 * @private |
139 */ | 260 */ |
140 isEqual_: function(lhs, rhs) { | 261 isEqual_: function(lhs, rhs) { |
141 return lhs === rhs; | 262 return lhs === rhs; |
142 }, | 263 }, |
143 }); | 264 }); |
OLD | NEW |