about summary refs log tree commit diff
path: root/pkgs/applications/window-managers/way-cooler/bar.diff
blob: e60ebabe98337afdaee0d53b27b64d0bed4eecda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--- bar.py.txt.orig	2017-12-05 18:10:20.108569182 +0300
+++ ./bar.py.txt	2017-12-10 21:42:10.622781945 +0300
@@ -5,6 +5,7 @@ import datetime
 import json
 from time import sleep
 from pydbus import SessionBus
+from glob import glob
 
 BUS = SessionBus()
 LAYOUT = BUS.get(bus_name='org.way-cooler', object_path='/org/way_cooler/Layout')
@@ -32,7 +33,7 @@ def main():
             output += func()
         print(output)
         sys.stdout.flush()
-        sleep(.1)
+        sleep(1)
 
 def get_workspaces(layout_json):
     """Gets the workspace names from the layout json"""
@@ -49,9 +50,14 @@ def get_time():
     return datetime.datetime.now().strftime('  %a %b %d  %H:%M  ')
 
 def get_battery():
-    with open("/sys/class/power_supply/BAT0/capacity", "r") as f:
-        bat = f.readlines()
-    return bat[0].strip() + "% Battery"
+    try:
+        [path] = glob("/sys/class/power_supply/BAT?/capacity")
+        with open(path, "r") as f:
+            bat = f.readlines()
+            result = bat[0].strip() + "% Battery"
+    except Exception:
+        result = ""
+    return result
 
 def format_workspaces(layout, workspaces, active_workspace):
     workspaces = "  " + workspaces.replace(" ", "  ") + "  "