File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ type UseBatteryState =
2525 | { isSupported : true ; fetched : false } // battery API supported but not fetched yet
2626 | BatteryState & { isSupported : true ; fetched : true } ; // battery API supported and fetched
2727
28- const nav : NavigatorWithPossibleBattery = navigator ;
29- const isBatteryApiSupported = nav && typeof nav . getBattery !== 'undefined ';
28+ const isBatteryApiSupported =
29+ typeof navigator === 'object' && typeof ( navigator as NavigatorWithPossibleBattery ) . getBattery === 'function ';
3030
3131function useBatteryMock ( ) : UseBatteryState {
3232 return { isSupported : false } ;
@@ -85,7 +85,7 @@ function useBattery(): UseBatteryState {
8585 React . useEffect ( ( ) => {
8686 isMounted . current = true ;
8787
88- nav . getBattery ! ( ) . then ( ( bat : BatteryManager ) => {
88+ ( navigator as NavigatorWithPossibleBattery ) . getBattery ! ( ) . then ( ( bat : BatteryManager ) => {
8989 battery . current = bat ;
9090
9191 bindBatteryEvents ( ) ;
You can’t perform that action at this time.
0 commit comments