OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 var BatterySettings = Polymer({ | 5 var BatterySettings = Polymer({ |
6 is: 'battery-settings', | 6 is: 'battery-settings', |
7 | 7 |
8 properties: { | 8 properties: { |
9 /** | 9 /** |
10 * The system's battery percentage. | 10 * The system's battery percentage. |
11 */ | 11 */ |
12 batteryPercent: { | 12 batteryPercent: { |
13 type: Number, | 13 type: Number, |
14 }, | 14 }, |
15 | 15 |
16 /** | 16 /** |
17 * A string representing the value of an | 17 * A string representing the value of an |
michaelpg
2015/07/27 20:46:22
nit: "of a"
mozartalouis
2015/07/27 23:58:41
Done.
| |
18 * PowerSupplyProperties_BatteryState enumeration. | |
19 */ | |
20 batteryState: { | |
21 type: String, | |
22 }, | |
23 | |
24 /** | |
25 * An array representing the battery state options. | |
michaelpg
2015/07/27 20:46:22
fix indent (-1)
mozartalouis
2015/07/27 23:58:41
Done.
| |
26 * The names are ordered based on the | |
27 * PowerSupplyProperties_BatteryState enumeration. These values must be | |
28 * in sync. | |
29 */ | |
30 batteryStateOptions: { | |
31 type: Array, | |
32 value: function() { return ['Full', 'Charging', 'Disharging', | |
33 'Not Present']; } | |
34 }, | |
35 | |
36 /** | |
37 * A string representing the value of an | |
michaelpg
2015/07/27 20:46:22
nit: "of a"
mozartalouis
2015/07/27 23:58:41
Done.
| |
18 * PowerSupplyProperties_ExternalPower enumeration. | 38 * PowerSupplyProperties_ExternalPower enumeration. |
19 */ | 39 */ |
20 externalPower: { | 40 externalPower: { |
21 type: String, | 41 type: String, |
22 }, | 42 }, |
23 | 43 |
24 /** | 44 /** |
25 * An array representing the external power options. | 45 * An array representing the external power options. |
26 * The names are ordered based on the | 46 * The names are ordered based on the |
27 * PowerSupplyProperties_ExternalPower enumeration. These values must be | 47 * PowerSupplyProperties_ExternalPower enumeration. These values must be |
(...skipping 25 matching lines...) Expand all Loading... | |
53 type: String, | 73 type: String, |
54 }, | 74 }, |
55 }, | 75 }, |
56 | 76 |
57 ready: function() { | 77 ready: function() { |
58 this.title = 'Power Settings'; | 78 this.title = 'Power Settings'; |
59 }, | 79 }, |
60 | 80 |
61 observers: [ | 81 observers: [ |
62 'batteryPercentChanged(batteryPercent)', | 82 'batteryPercentChanged(batteryPercent)', |
83 'batteryStateChanged(batteryState)', | |
63 'externalPowerChanged(externalPower)', | 84 'externalPowerChanged(externalPower)', |
64 'timeUntilEmptyChanged(timeUntilEmpty)', | 85 'timeUntilEmptyChanged(timeUntilEmpty)', |
65 'timeUntilFullChanged(timeUntilFull)', | 86 'timeUntilFullChanged(timeUntilFull)', |
66 ], | 87 ], |
67 | 88 |
68 batteryPercentChanged: function(percent) { | 89 batteryPercentChanged: function(percent) { |
69 chrome.send('updateBatteryPercent', [parseInt(percent)]); | 90 chrome.send('updateBatteryPercent', [parseInt(percent)]); |
70 }, | 91 }, |
71 | 92 |
93 batteryStateChanged: function(state) { | |
94 var index = -1; | |
95 | |
96 // Find the index of the selected battery state. | |
97 for (var i = 0; i < this.batteryStateOptions.length; i++) { | |
michaelpg
2015/07/27 20:46:22
var index = this.batteryStateOptions.indexOf(state
mozartalouis
2015/07/27 23:58:41
Done.
michaelpg
2015/07/28 00:05:39
Take another look at how indexOf works -- you don'
| |
98 if (this.batteryStateOptions[i] == state) { | |
99 index = i; | |
100 break; | |
101 } | |
102 } | |
103 | |
104 if (index >= 0) | |
105 chrome.send('updateBatteryState', [index]); | |
michaelpg
2015/07/27 20:46:22
indent
mozartalouis
2015/07/27 23:58:41
Done.
| |
106 }, | |
107 | |
72 externalPowerChanged: function(source) { | 108 externalPowerChanged: function(source) { |
73 var index = -1; | 109 var index = -1; |
74 | 110 |
75 // Find the index of the selected power source. | 111 // Find the index of the selected power source. |
76 for (var i = 0; i < this.externalPowerOptions.length; i++) { | 112 for (var i = 0; i < this.externalPowerOptions.length; i++) { |
77 if (this.externalPowerOptions[i] == source) { | 113 if (this.externalPowerOptions[i] == source) { |
78 index = i; | 114 index = i; |
79 break; | 115 break; |
80 } | 116 } |
81 } | 117 } |
82 | 118 |
83 if (index >= 0) | 119 if (index >= 0) |
84 chrome.send('updateExternalPower', [index]); | 120 chrome.send('updateExternalPower', [index]); |
85 }, | 121 }, |
86 | 122 |
87 timeUntilEmptyChanged: function(time) { | 123 timeUntilEmptyChanged: function(time) { |
88 chrome.send('updateTimeToEmpty', [parseInt(time)]); | 124 chrome.send('updateTimeToEmpty', [parseInt(time)]); |
89 }, | 125 }, |
90 | 126 |
91 timeUntilFullChanged: function(time) { | 127 timeUntilFullChanged: function(time) { |
92 chrome.send('updateTimeToFull', [parseInt(time)]); | 128 chrome.send('updateTimeToFull', [parseInt(time)]); |
93 }, | 129 }, |
94 | 130 |
95 updatePowerProperties: function(percent, external_power, empty, full) { | 131 updatePowerProperties: function(percent, state, source, empty, full) { |
96 this.batteryPercent = percent; | 132 this.batteryPercent = percent; |
97 this.externalPower = this.externalPowerOptions[external_power]; | 133 this.batteryState = this.batteryStateOptions[state]; |
134 this.externalPower = this.externalPowerOptions[source]; | |
98 this.timeUntilEmpty = empty; | 135 this.timeUntilEmpty = empty; |
99 this.timeUntilFull = full; | 136 this.timeUntilFull = full; |
100 } | 137 } |
101 }); | 138 }); |
OLD | NEW |