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