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