Commit c60f9e9
Eric Bower
·
2026-08-28 23:19:26 -0400 EDT
parent de8d191
fix: swaybar script
2 files changed,
+64,
-26
+64,
-26
1@@ -3,6 +3,7 @@ import json
2 import sys
3 import os
4 import subprocess
5+import shutil
6 import threading
7 import time
8
9@@ -46,40 +47,77 @@ def get_battery():
10
11 def get_brightness():
12 try:
13- actual = int(subprocess.check_output(["brightnessctl", "get"], text=True).strip())
14- max_b = int(subprocess.check_output(["brightnessctl", "max"], text=True).strip())
15+ if not os.path.exists("/sys/class/backlight") or not os.listdir("/sys/class/backlight"):
16+ return None
17+ actual = int(subprocess.check_output(["brightnessctl", "-c", "backlight", "get"], text=True).strip())
18+ max_b = int(subprocess.check_output(["brightnessctl", "-c", "backlight", "max"], text=True).strip())
19 pct = int((actual / max_b) * 100)
20 return f"BRT {pct}%"
21 except Exception:
22 return None
23
24 def get_net():
25+ if shutil.which("nmcli"):
26+ try:
27+ out = subprocess.check_output(
28+ ["nmcli", "-t", "-f", "TYPE,STATE,CONNECTION", "dev"],
29+ text=True
30+ ).strip()
31+
32+ eth_name = None
33+ wifi_ssid = None
34+
35+ for line in out.splitlines():
36+ parts = line.split(":")
37+ if len(parts) >= 3 and parts[1] == "connected":
38+ dev_type = parts[0]
39+ conn_name = parts[2]
40+ if dev_type == "ethernet":
41+ eth_name = conn_name if conn_name else "Wired"
42+ elif dev_type == "wifi":
43+ wifi_ssid = conn_name if conn_name else "WiFi"
44+
45+ if eth_name:
46+ return f"ETH {eth_name}"
47+ elif wifi_ssid:
48+ return f"NET {wifi_ssid}"
49+ except Exception:
50+ pass
51+
52 try:
53- out = subprocess.check_output(
54- ["nmcli", "-t", "-f", "TYPE,STATE,CONNECTION", "dev"],
55- text=True
56- ).strip()
57-
58- eth_name = None
59- wifi_ssid = None
60-
61- for line in out.splitlines():
62- parts = line.split(":")
63- if len(parts) >= 3 and parts[1] == "connected":
64- dev_type = parts[0]
65- conn_name = parts[2]
66- if dev_type == "ethernet":
67- eth_name = conn_name if conn_name else "Wired"
68- elif dev_type == "wifi":
69- wifi_ssid = conn_name if conn_name else "WiFi"
70-
71- if eth_name:
72- return f"ETH {eth_name}"
73- elif wifi_ssid:
74- return f"NET {wifi_ssid}"
75- return "NET Disconnected"
76+ out = subprocess.check_output(["ip", "route", "show", "default"], text=True).strip()
77+ if out:
78+ tokens = out.split()
79+ if "dev" in tokens:
80+ iface = tokens[tokens.index("dev") + 1]
81+ is_wifi = (
82+ os.path.exists(f"/sys/class/net/{iface}/wireless")
83+ or os.path.exists(f"/sys/class/net/{iface}/phy80211")
84+ or iface.startswith(("wl", "wlan"))
85+ )
86+ if is_wifi:
87+ ssid = None
88+ if shutil.which("iw"):
89+ try:
90+ iw_out = subprocess.check_output(["iw", "dev", iface, "link"], text=True)
91+ for line in iw_out.splitlines():
92+ if "SSID:" in line:
93+ ssid = line.split("SSID:", 1)[1].strip()
94+ break
95+ except Exception:
96+ pass
97+ elif shutil.which("iwgetid"):
98+ try:
99+ ssid = subprocess.check_output(["iwgetid", "-r"], text=True).strip()
100+ except Exception:
101+ pass
102+ return f"NET {ssid}" if ssid else f"NET {iface}"
103+ else:
104+ return f"ETH {iface}"
105 except Exception:
106- return "NET ?"
107+ pass
108+
109+ return "NET Disconnected"
110
111 def get_time():
112 return time.strftime("%I:%M %m/%d").lstrip("0")