File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 184184 // Get battery level and charging status.
185185 const { level, charging } = battery ;
186186
187- // The API doesn’t report Low Power Mode or similar, so let’s just assume
188- // that a device with less than 20% charge is considered ‘low’.
187+ // The API doesn’t report Low Power Mode or similar. Treat ≤5% as
188+ // ‘critical’ and ≤20% as ‘low’.
189+ const critical = Number . isFinite ( level ) ? level <= 0.05 : null ;
190+ window . obs . batteryCritical = critical ;
191+
189192 const low = Number . isFinite ( level ) ? level <= 0.2 : null ;
190193 window . obs . batteryLow = low ;
191194
192- // Add low-battery class to `html` element.
193- html . classList . toggle ( 'has-battery-low' , ! ! low ) ;
195+ // Add most urgent battery class.
196+ [ 'critical' , 'low' ] . forEach ( t => html . classList . remove ( `has-battery-${ t } ` ) ) ;
197+ if ( critical ) {
198+ html . classList . add ( 'has-battery-critical' ) ;
199+ } else if ( low ) {
200+ html . classList . add ( 'has-battery-low' ) ;
201+ }
194202
195203 // Add a class to the `html` element if the device is currently charging
196204 const isCharging = ! ! charging ;
You can’t perform that action at this time.
0 commit comments