Minor EWW script cleanup

This commit is contained in:
Michael Bradley 2025-06-22 14:34:42 -04:00
parent 287df92d65
commit abbd3df78b
Signed by: MichaelBradley
SSH key fingerprint: SHA256:BKO2eI2LPsCbQS3n3i5SdwZTAIV3F1lHezR07qP+Ob0
5 changed files with 23 additions and 35 deletions

View file

@ -3,10 +3,7 @@
DELTA="1%" DELTA="1%"
case "$1" in case "$1" in
"up") pactl set-sink-volume @DEFAULT_SINK@ +"$DELTA" up) pactl set-sink-volume @DEFAULT_SINK@ +"$DELTA";;
;; down) pactl set-sink-volume @DEFAULT_SINK@ -"$DELTA";;
"down") pactl set-sink-volume @DEFAULT_SINK@ -"$DELTA" *) exit 1;;
;;
*) exit 1
;;
esac esac

View file

@ -3,12 +3,8 @@
DELTA="1%" DELTA="1%"
case "$1" in case "$1" in
up) brightnessctl -m -c backlight set +"$DELTA" up) brightnessctl -m -c backlight set +"$DELTA";;
;; down) brightnessctl -m -c backlight set "$DELTA"-;;
down) brightnessctl -m -c backlight set "$DELTA"- get) brightnessctl -m -c backlight get;;
;; *) echo "Unrecognized command"; exit 1;;
get) brightnessctl -m -c backlight get
;;
*) echo "Unrecognized command"; exit 1
;;
esac esac

View file

@ -11,14 +11,9 @@ get_or_default() {
} }
case "$1" in case "$1" in
"headphones") echo "$DEFAULT_HEADPHONES" # TODO: Figure out generic regex string to match headphones headphones) echo "$DEFAULT_HEADPHONES";; # TODO: Figure out generic regex string to match headphones
;; speakers) get_or_default 'sinks' 'HiFi__Headphones__sink' "$DEFAULT_SPEAKERS";;
"speakers") get_or_default 'sinks' 'HiFi__Headphones__sink' "$DEFAULT_SPEAKERS" headphone_mic) echo "$DEFAULT_HEADPHONE_MIC";; # TODO: Figure out generic regex string to match headphone mic
;; blue_mic) get_or_default 'sources' 'Generic_Blue_Microphones[a-zA-Z0-9_.\\-]+\\.analog-stereo$' "$DEFAULT_BLUE_MIC";;
"headphone_mic") echo "$DEFAULT_HEADPHONE_MIC" # TODO: Figure out generic regex string to match headphone mic *) echo "Device name '$1' not recognized"; exit 1;;
;;
"blue_mic") get_or_default 'sources' 'Generic_Blue_Microphones[a-zA-Z0-9_.\\-]+\\.analog-stereo$' "$DEFAULT_BLUE_MIC"
;;
*) echo "Device name '$1' not recognized"; exit 1
;;
esac esac

View file

@ -1,4 +1,4 @@
#!/bin/env sh #!/bin/env sh
# EWW doesn't seem to like listening to Python scripts directly, but this wrapper seems to work fine # EWW doesn't seem to like listening to Python scripts directly, but this wrapper seems to work fine
"$(dirname "$0")"/network-statistics $@ "$(dirname "$0")"/network-statistics "$@"

View file

@ -9,14 +9,14 @@ from typing import Literal, NoReturn
def get_interfaces() -> list[Path]: def get_interfaces() -> list[Path]:
return list(Path("/sys/class/net/").glob("*")) return list(Path("/sys/class/net/").iterdir())
class TransferredBytes: class TransferredBytes:
def __init__(self, interface: Path, statistic: Literal["tx"] | Literal["rx"]) -> None: def __init__(self, interface: Path, statistic: Literal["tx"] | Literal["rx"]) -> None:
self._statistic = interface / f"statistics/{statistic}_bytes" self._statistic: Path = interface / f"statistics/{statistic}_bytes"
self._current = int(self._statistic.read_text()) self._current: int = int(self._statistic.read_text())
self._previous = self._current self._previous: int = self._current
def update(self) -> None: def update(self) -> None:
self._previous = self._current self._previous = self._current
@ -28,7 +28,7 @@ class TransferredBytes:
class Status: class Status:
def __init__(self, interface: Path) -> None: def __init__(self, interface: Path) -> None:
self._statistic = interface / "operstate" self._statistic: Path = interface / "operstate"
def up(self) -> bool: def up(self) -> bool:
return self._statistic.read_text().strip() == "up" return self._statistic.read_text().strip() == "up"
@ -56,10 +56,10 @@ def format_bytes(num: float) -> str:
class Interface: class Interface:
def __init__(self, location: Path) -> None: def __init__(self, location: Path) -> None:
self._location = location self._location: Path = location
self._tx = TransferredBytes(location, "tx") self._tx: TransferredBytes = TransferredBytes(location, "tx")
self._rx = TransferredBytes(location, "rx") self._rx: TransferredBytes = TransferredBytes(location, "rx")
self._status = Status(location) self._status: Status = Status(location)
@property @property
def name(self) -> str: def name(self) -> str:
@ -84,7 +84,7 @@ class Interface:
class Statistics: class Statistics:
def __init__(self) -> None: def __init__(self) -> None:
self._interfaces = [Interface(location) for location in get_interfaces()] self._interfaces: list[Interface] = [Interface(location) for location in get_interfaces()]
def update(self) -> None: def update(self) -> None:
for interface in self._interfaces: for interface in self._interfaces: