Skip to content

Commit

Permalink
Merge pull request boramalper#101 from Chaaang/support-mac-sleep
Browse files Browse the repository at this point in the history
implement the battery status check under mac environment
  • Loading branch information
boramalper authored Sep 7, 2018
2 parents 7dd0c2a + d12b5b5 commit 95076ae
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions himawaripy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from glob import iglob, glob
import threading
import time
import subprocess

import appdirs
from PIL import Image
Expand Down Expand Up @@ -108,16 +109,19 @@ def parse_args():


def is_discharging():
if not sys.platform.startswith("linux"): # I hope this will not end up like Windows 95/98 checks one day...
sys.exit("Battery saving feature works only on linux!\n")
if sys.platform.startswith("linux"):
if len(glob("/sys/class/power_supply/BAT*")) > 1:
print("Multiple batteries detected, using BAT0.")

if len(glob("/sys/class/power_supply/BAT*")) > 1:
print("Multiple batteries detected, using BAT0.")
with open("/sys/class/power_supply/BAT0/status") as f:
status = f.readline().strip()

with open("/sys/class/power_supply/BAT0/status") as f:
status = f.readline().strip()
return status == "Discharging"
elif sys.platform == 'darwin':
return b'discharging' in subprocess.check_output(["pmset", "-g", "batt"])

return status == "Discharging"
else:
sys.exit("Battery saving feature works only on linux or mac!\n")


def download(url):
Expand Down

0 comments on commit 95076ae

Please sign in to comment.