Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * 'settings-power' is the settings subpage for power settings. | |
| 8 */ | |
| 9 | |
| 10 Polymer({ | |
| 11 is: 'settings-power', | |
| 12 | |
| 13 behaviors: [ | |
| 14 I18nBehavior, | |
| 15 WebUIListenerBehavior, | |
| 16 ], | |
| 17 | |
| 18 properties: { | |
| 19 enablePowerSettings: Boolean, | |
| 20 | |
| 21 /** @private {string} ID of the selected power source, or ''. */ | |
| 22 selectedPowerSourceId_: String, | |
| 23 | |
| 24 /** @private {!settings.BatteryStatus|undefined} */ | |
| 25 batteryStatus_: Object, | |
| 26 | |
| 27 /** @private {boolean} Whether a low-power (USB) charger is being used. */ | |
| 28 lowPowerCharger_: Boolean, | |
| 29 | |
| 30 /** | |
| 31 * List of available dual-role power sources, if enablePowerSettings is on. | |
| 32 * @private {!Array<!settings.PowerSource>|undefined} | |
| 33 */ | |
| 34 powerSources_: Array, | |
| 35 | |
| 36 /** @private */ | |
| 37 powerSourceLabel_: { | |
| 38 type: String, | |
| 39 computed: | |
| 40 'computePowerSourceLabel_(powerSources_, batteryStatus_.calculating)', | |
| 41 }, | |
| 42 | |
| 43 /** @private */ | |
| 44 showPowerSourceDropdown_: { | |
| 45 type: Boolean, | |
| 46 computed: 'computeShowPowerSourceDropdown_(powerSources_)', | |
| 47 value: false, | |
| 48 }, | |
| 49 | |
| 50 /** | |
| 51 * The name of the dedicated charging device being used, if present. | |
| 52 * @private {string} | |
| 53 */ | |
| 54 powerSourceName_: { | |
| 55 type: String, | |
| 56 computed: 'computePowerSourceName_(powerSources_, lowPowerCharger_)', | |
| 57 }, | |
| 58 }, | |
| 59 | |
| 60 /** @override */ | |
| 61 ready: function() { | |
| 62 // enablePowerSettings comes from loadTimeData, so it will always be set | |
| 63 // before attached() is called. | |
| 64 if (!this.enablePowerSettings) | |
| 65 settings.navigateToPreviousRoute(); | |
| 66 }, | |
| 67 | |
| 68 /** @override */ | |
| 69 attached: function() { | |
| 70 this.addWebUIListener( | |
| 71 'battery-status-changed', this.set.bind(this, 'batteryStatus_')); | |
| 72 this.addWebUIListener( | |
| 73 'power-sources-changed', this.powerSourcesChanged_.bind(this)); | |
| 74 settings.DevicePageBrowserProxyImpl.getInstance().updatePowerStatus(); | |
|
Dan Beam
2017/03/14 21:50:09
this should only be called if (this.enablePowerSet
Daniel Erat
2017/03/14 22:08:16
thanks for pointing that out. i'll send a fix.
bu
stevenjb
2017/03/14 22:17:44
dbeam@ - This should be protected by a dom-if, in
Dan Beam
2017/03/14 22:27:24
search for device -> asplode
Daniel Erat
2017/03/14 22:56:51
yep, i'm able to reproduce this.
stevenjb
2017/03/14 23:08:14
I wasn't so much looking for a repro as for an und
Dan Beam
2017/03/14 23:17:39
or just wrap this code in an if (this.enablePowerS
Daniel Erat
2017/03/15 00:16:37
uploaded https://codereview.chromium.org/275187300
| |
| 75 }, | |
| 76 | |
| 77 /** | |
| 78 * @param {!Array<!settings.PowerSource>|undefined} powerSources | |
| 79 * @param {boolean} calculating | |
| 80 * @return {string} The primary label for the power source row. | |
| 81 * @private | |
| 82 */ | |
| 83 computePowerSourceLabel_: function(powerSources, calculating) { | |
| 84 return this.i18n( | |
| 85 calculating ? | |
| 86 'calculatingPower' : | |
| 87 powerSources.length ? 'powerSourceLabel' : 'powerSourceBattery'); | |
| 88 }, | |
| 89 | |
| 90 /** | |
| 91 * @param {!Array<!settings.PowerSource>} powerSources | |
| 92 * @return {boolean} True if at least one power source is attached and all of | |
| 93 * them are dual-role (no dedicated chargers). | |
| 94 * @private | |
| 95 */ | |
| 96 computeShowPowerSourceDropdown_: function(powerSources) { | |
| 97 return powerSources.length > 0 && powerSources.every(function(source) { | |
| 98 return source.type == settings.PowerDeviceType.DUAL_ROLE_USB; | |
| 99 }); | |
| 100 }, | |
| 101 | |
| 102 /** | |
| 103 * @param {!Array<!settings.PowerSource>} powerSources | |
| 104 * @param {boolean} lowPowerCharger | |
| 105 * @return {string} Description of the power source. | |
| 106 * @private | |
| 107 */ | |
| 108 computePowerSourceName_: function(powerSources, lowPowerCharger) { | |
| 109 if (lowPowerCharger) | |
| 110 return this.i18n('powerSourceLowPowerCharger'); | |
| 111 if (powerSources.length) | |
| 112 return this.i18n('powerSourceAcAdapter'); | |
| 113 return ''; | |
| 114 }, | |
| 115 | |
| 116 onPowerSourceChange_: function() { | |
| 117 settings.DevicePageBrowserProxyImpl.getInstance().setPowerSource( | |
| 118 this.$$('#powerSource').value); | |
| 119 }, | |
| 120 | |
| 121 /** | |
| 122 * @param {!Array<settings.PowerSource>} sources External power sources. | |
| 123 * @param {string} selectedId The ID of the currently used power source. | |
| 124 * @param {boolean} lowPowerCharger Whether the currently used power source | |
| 125 * is a low-powered USB charger. | |
| 126 * @private | |
| 127 */ | |
| 128 powerSourcesChanged_: function(sources, selectedId, lowPowerCharger) { | |
| 129 this.powerSources_ = sources; | |
| 130 this.selectedPowerSourceId_ = selectedId; | |
| 131 this.lowPowerCharger_ = lowPowerCharger; | |
| 132 }, | |
| 133 | |
| 134 /** | |
| 135 * @param {*} lhs | |
| 136 * @param {*} rhs | |
| 137 * @return {boolean} | |
| 138 * @private | |
| 139 */ | |
| 140 isEqual_: function(lhs, rhs) { | |
| 141 return lhs === rhs; | |
| 142 }, | |
| 143 }); | |
| OLD | NEW |