Backlight: fix crash in #442
This commit is contained in:
parent
115bd4d34f
commit
285ba71ba0
@ -20,6 +20,7 @@ class Backlight(File):
|
||||
|
||||
settings = (
|
||||
("format", "format string, formatters: brightness, max_brightness, percentage"),
|
||||
("format_no_backlight", "format string when no backlight file available"),
|
||||
("backlight",
|
||||
"backlight, see `/sys/class/backlight/`. Supports glob expansion, i.e. `*` matches anything. "
|
||||
"If it matches more than one filename, selects the first one in alphabetical order"),
|
||||
@ -29,6 +30,7 @@ class Backlight(File):
|
||||
|
||||
backlight = "*"
|
||||
format = "{brightness}/{max_brightness}"
|
||||
format_no_backlight = "No backlight"
|
||||
|
||||
base_path = "/sys/class/backlight/{backlight}/"
|
||||
components = {
|
||||
@ -43,7 +45,12 @@ class Backlight(File):
|
||||
|
||||
def init(self):
|
||||
self.base_path = self.base_path.format(backlight=self.backlight)
|
||||
self.base_path = sorted(glob.glob(self.base_path))[0]
|
||||
backlight_entries = sorted(glob.glob(self.base_path))
|
||||
|
||||
if len(backlight_entries) == 0:
|
||||
self.run = run_no_backlight
|
||||
|
||||
self.base_path = backlight_entries[0]
|
||||
self.has_xbacklight = shutil.which("xbacklight") is not None
|
||||
|
||||
# xbacklight expects a percentage as parameter. Calculate the percentage
|
||||
@ -59,6 +66,23 @@ class Backlight(File):
|
||||
self.step_size = 5 # default?
|
||||
super().init()
|
||||
|
||||
def run_no_backlight(self):
|
||||
cdict = {
|
||||
"brightness": -1,
|
||||
"max_brightness": -1,
|
||||
"percentage": -1
|
||||
}
|
||||
|
||||
format = self.format_no_backlight
|
||||
if not format:
|
||||
format = self.format
|
||||
|
||||
self.data = cdict
|
||||
self.output = {
|
||||
"full_text": format.format(**cdict),
|
||||
"color": self.color
|
||||
}
|
||||
|
||||
def lighter(self):
|
||||
if self.has_xbacklight:
|
||||
run_through_shell(["xbacklight", "-inc", str(self.step_size)])
|
||||
|
Loading…
Reference in New Issue
Block a user