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, | |
68 type: Array, | |
69 value: function() { | |
70 return [ | |
71 { | |
72 value: settings.IdleBehavior.DISPLAY_OFF_SLEEP, | |
73 name: loadTimeData.getString('powerIdleDisplayOffSleep'), | |
74 }, | |
75 { | |
76 value: settings.IdleBehavior.DISPLAY_OFF_STAY_AWAKE, | |
77 name: loadTimeData.getString('powerIdleDisplayOffStayAwake'), | |
78 }, | |
79 { | |
80 value: settings.IdleBehavior.DISPLAY_ON, | |
81 name: loadTimeData.getString('powerIdleDisplayOn'), | |
82 }, | |
83 ]; | |
84 }, | |
85 }, | |
86 | |
87 /** @private */ | |
88 lidClosedOptions_: { | |
89 readOnly: true, | |
90 type: Array, | |
91 value: function() { | |
92 return [ | |
93 { | |
94 value: settings.LidClosedBehavior.SLEEP, | |
95 name: loadTimeData.getString('powerLidClosedSleep'), | |
96 }, | |
97 { | |
98 value: settings.LidClosedBehavior.STAY_AWAKE, | |
99 name: loadTimeData.getString('powerLidClosedStayAwake'), | |
100 }, | |
101 ]; | |
102 }, | |
103 }, | |
58 }, | 104 }, |
59 | 105 |
60 /** @override */ | 106 /** @override */ |
61 ready: function() { | 107 ready: function() { |
62 // enablePowerSettings comes from loadTimeData, so it will always be set | 108 // enablePowerSettings comes from loadTimeData, so it will always be set |
63 // before attached() is called. | 109 // before attached() is called. |
64 if (!this.enablePowerSettings) | 110 if (!this.enablePowerSettings) |
65 settings.navigateToPreviousRoute(); | 111 settings.navigateToPreviousRoute(); |
66 }, | 112 }, |
67 | 113 |
68 /** @override */ | 114 /** @override */ |
69 attached: function() { | 115 attached: function() { |
70 this.addWebUIListener( | 116 this.addWebUIListener( |
71 'battery-status-changed', this.set.bind(this, 'batteryStatus_')); | 117 'battery-status-changed', this.set.bind(this, 'batteryStatus_')); |
72 this.addWebUIListener( | 118 this.addWebUIListener( |
73 'power-sources-changed', this.powerSourcesChanged_.bind(this)); | 119 'power-sources-changed', this.powerSourcesChanged_.bind(this)); |
74 settings.DevicePageBrowserProxyImpl.getInstance().updatePowerStatus(); | 120 settings.DevicePageBrowserProxyImpl.getInstance().updatePowerStatus(); |
121 | |
122 this.addWebUIListener( | |
123 'power-management-settings-changed', | |
124 this.powerManagementSettingsChanged_.bind(this)); | |
125 settings.DevicePageBrowserProxyImpl.getInstance() | |
126 .requestPowerManagementSettings(); | |
75 }, | 127 }, |
76 | 128 |
77 /** | 129 /** |
78 * @param {!Array<!settings.PowerSource>|undefined} powerSources | 130 * @param {!Array<!settings.PowerSource>|undefined} powerSources |
79 * @param {boolean} calculating | 131 * @param {boolean} calculating |
80 * @return {string} The primary label for the power source row. | 132 * @return {string} The primary label for the power source row. |
81 * @private | 133 * @private |
82 */ | 134 */ |
83 computePowerSourceLabel_: function(powerSources, calculating) { | 135 computePowerSourceLabel_: function(powerSources, calculating) { |
84 return this.i18n( | 136 return this.i18n( |
(...skipping 21 matching lines...) Expand all Loading... | |
106 * @private | 158 * @private |
107 */ | 159 */ |
108 computePowerSourceName_: function(powerSources, lowPowerCharger) { | 160 computePowerSourceName_: function(powerSources, lowPowerCharger) { |
109 if (lowPowerCharger) | 161 if (lowPowerCharger) |
110 return this.i18n('powerSourceLowPowerCharger'); | 162 return this.i18n('powerSourceLowPowerCharger'); |
111 if (powerSources.length) | 163 if (powerSources.length) |
112 return this.i18n('powerSourceAcAdapter'); | 164 return this.i18n('powerSourceAcAdapter'); |
113 return ''; | 165 return ''; |
114 }, | 166 }, |
115 | 167 |
168 /** @private */ | |
116 onPowerSourceChange_: function() { | 169 onPowerSourceChange_: function() { |
117 settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource( | 170 settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource( |
118 this.$$('#powerSource').value); | 171 this.$$('#powerSource').value); |
119 }, | 172 }, |
120 | 173 |
174 /** @private */ | |
175 onIdleSelectChange_: function() { | |
176 var behavior = /** @type {settings.IdleBehavior} */ | |
Daniel Erat
2017/05/02 00:58:42
are these casts bogus, or okay? i'm not even sure
michaelpg
2017/05/04 17:36:26
I think this is fine. parseInt makes sense. The ca
Daniel Erat
2017/05/06 00:15:47
Acknowledged.
| |
177 (parseInt(this.$$('#idleSelect').value, 10)); | |
michaelpg
2017/05/04 17:36:26
nit: this.$.idleSelect: https://www.polymer-projec
Daniel Erat
2017/05/06 00:15:47
Done.
| |
178 settings.DevicePageBrowserProxyImpl.getInstance().setIdleBehavior(behavior); | |
179 }, | |
180 | |
181 /** @private */ | |
182 onLidClosedSelectChange_: function() { | |
183 var behavior = /** @type {settings.LidClosedBehavior} */ | |
184 (parseInt(this.$$('#lidClosedSelect').value, 10)); | |
michaelpg
2017/05/04 17:36:26
this.$.foo
Daniel Erat
2017/05/06 00:15:47
Done.
| |
185 settings.DevicePageBrowserProxyImpl.getInstance().setLidClosedBehavior( | |
186 behavior); | |
187 }, | |
188 | |
121 /** | 189 /** |
122 * @param {!Array<settings.PowerSource>} sources External power sources. | 190 * @param {!Array<settings.PowerSource>} sources External power sources. |
123 * @param {string} selectedId The ID of the currently used power source. | 191 * @param {string} selectedId The ID of the currently used power source. |
124 * @param {boolean} lowPowerCharger Whether the currently used power source | 192 * @param {boolean} lowPowerCharger Whether the currently used power source |
125 * is a low-powered USB charger. | 193 * is a low-powered USB charger. |
126 * @private | 194 * @private |
127 */ | 195 */ |
128 powerSourcesChanged_: function(sources, selectedId, lowPowerCharger) { | 196 powerSourcesChanged_: function(sources, selectedId, lowPowerCharger) { |
129 this.powerSources_ = sources; | 197 this.powerSources_ = sources; |
130 this.selectedPowerSourceId_ = selectedId; | 198 this.selectedPowerSourceId_ = selectedId; |
131 this.lowPowerCharger_ = lowPowerCharger; | 199 this.lowPowerCharger_ = lowPowerCharger; |
132 }, | 200 }, |
133 | 201 |
134 /** | 202 /** |
203 * @param {!settings.PowerManagementSettings} settings Current power | |
204 * management settings. | |
205 * @private | |
206 */ | |
207 powerManagementSettingsChanged_: function(settings) { | |
208 this.idleManaged_ = settings.idleManaged; | |
209 this.lidClosedManaged_ = settings.lidClosedManaged; | |
210 this.$$('#idleSelect').value = settings.idleBehavior; | |
211 this.$$('#lidClosedSelect').value = settings.lidClosedBehavior; | |
michaelpg
2017/05/04 17:36:26
this.$.foo x2
Daniel Erat
2017/05/06 00:15:47
Done.
| |
212 }, | |
213 | |
214 /** | |
135 * @param {*} lhs | 215 * @param {*} lhs |
136 * @param {*} rhs | 216 * @param {*} rhs |
137 * @return {boolean} | 217 * @return {boolean} |
138 * @private | 218 * @private |
139 */ | 219 */ |
140 isEqual_: function(lhs, rhs) { | 220 isEqual_: function(lhs, rhs) { |
141 return lhs === rhs; | 221 return lhs === rhs; |
142 }, | 222 }, |
143 }); | 223 }); |
OLD | NEW |