mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[welcome] fix crash on missing battery
This commit is contained in:
parent
0fdcac0dc7
commit
202f5afc3f
1 changed files with 15 additions and 3 deletions
|
@ -134,7 +134,18 @@ def disks():
|
|||
|
||||
|
||||
def battery():
|
||||
battery = psutil.sensors_battery()
|
||||
if not hasattr(psutil, 'sensors_battery'):
|
||||
return None
|
||||
|
||||
try:
|
||||
battery = psutil.sensors_battery()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
if battery is None:
|
||||
return None
|
||||
|
||||
percent = battery.percent
|
||||
|
||||
if battery.power_plugged:
|
||||
|
@ -199,8 +210,9 @@ def get_system_info():
|
|||
for disk_info in disks():
|
||||
info('Disk (%s)', '%s / %s (%s)', *disk_info)
|
||||
|
||||
if hasattr(psutil, 'sensors_battery'):
|
||||
info('Battery', '%s (%s)', *battery())
|
||||
battery_info = battery()
|
||||
if battery_info is not None:
|
||||
info('Battery', '%s (%s)', *battery_info)
|
||||
|
||||
return logo_lines, info_lines
|
||||
|
||||
|
|
Loading…
Reference in a new issue