Minor EWW script cleanup
This commit is contained in:
parent
287df92d65
commit
abbd3df78b
5 changed files with 23 additions and 35 deletions
|
@ -3,10 +3,7 @@
|
|||
DELTA="1%"
|
||||
|
||||
case "$1" in
|
||||
"up") pactl set-sink-volume @DEFAULT_SINK@ +"$DELTA"
|
||||
;;
|
||||
"down") pactl set-sink-volume @DEFAULT_SINK@ -"$DELTA"
|
||||
;;
|
||||
*) exit 1
|
||||
;;
|
||||
up) pactl set-sink-volume @DEFAULT_SINK@ +"$DELTA";;
|
||||
down) pactl set-sink-volume @DEFAULT_SINK@ -"$DELTA";;
|
||||
*) exit 1;;
|
||||
esac
|
||||
|
|
|
@ -3,12 +3,8 @@
|
|||
DELTA="1%"
|
||||
|
||||
case "$1" in
|
||||
up) brightnessctl -m -c backlight set +"$DELTA"
|
||||
;;
|
||||
down) brightnessctl -m -c backlight set "$DELTA"-
|
||||
;;
|
||||
get) brightnessctl -m -c backlight get
|
||||
;;
|
||||
*) echo "Unrecognized command"; exit 1
|
||||
;;
|
||||
up) brightnessctl -m -c backlight set +"$DELTA";;
|
||||
down) brightnessctl -m -c backlight set "$DELTA"-;;
|
||||
get) brightnessctl -m -c backlight get;;
|
||||
*) echo "Unrecognized command"; exit 1;;
|
||||
esac
|
||||
|
|
|
@ -11,14 +11,9 @@ get_or_default() {
|
|||
}
|
||||
|
||||
case "$1" in
|
||||
"headphones") echo "$DEFAULT_HEADPHONES" # TODO: Figure out generic regex string to match headphones
|
||||
;;
|
||||
"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"
|
||||
;;
|
||||
*) echo "Device name '$1' not recognized"; exit 1
|
||||
;;
|
||||
headphones) echo "$DEFAULT_HEADPHONES";; # TODO: Figure out generic regex string to match headphones
|
||||
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";;
|
||||
*) echo "Device name '$1' not recognized"; exit 1;;
|
||||
esac
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env sh
|
||||
|
||||
# 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 "$@"
|
||||
|
|
|
@ -9,14 +9,14 @@ from typing import Literal, NoReturn
|
|||
|
||||
|
||||
def get_interfaces() -> list[Path]:
|
||||
return list(Path("/sys/class/net/").glob("*"))
|
||||
return list(Path("/sys/class/net/").iterdir())
|
||||
|
||||
|
||||
class TransferredBytes:
|
||||
def __init__(self, interface: Path, statistic: Literal["tx"] | Literal["rx"]) -> None:
|
||||
self._statistic = interface / f"statistics/{statistic}_bytes"
|
||||
self._current = int(self._statistic.read_text())
|
||||
self._previous = self._current
|
||||
self._statistic: Path = interface / f"statistics/{statistic}_bytes"
|
||||
self._current: int = int(self._statistic.read_text())
|
||||
self._previous: int = self._current
|
||||
|
||||
def update(self) -> None:
|
||||
self._previous = self._current
|
||||
|
@ -28,7 +28,7 @@ class TransferredBytes:
|
|||
|
||||
class Status:
|
||||
def __init__(self, interface: Path) -> None:
|
||||
self._statistic = interface / "operstate"
|
||||
self._statistic: Path = interface / "operstate"
|
||||
|
||||
def up(self) -> bool:
|
||||
return self._statistic.read_text().strip() == "up"
|
||||
|
@ -56,10 +56,10 @@ def format_bytes(num: float) -> str:
|
|||
|
||||
class Interface:
|
||||
def __init__(self, location: Path) -> None:
|
||||
self._location = location
|
||||
self._tx = TransferredBytes(location, "tx")
|
||||
self._rx = TransferredBytes(location, "rx")
|
||||
self._status = Status(location)
|
||||
self._location: Path = location
|
||||
self._tx: TransferredBytes = TransferredBytes(location, "tx")
|
||||
self._rx: TransferredBytes = TransferredBytes(location, "rx")
|
||||
self._status: Status = Status(location)
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
|
@ -84,7 +84,7 @@ class Interface:
|
|||
|
||||
class Statistics:
|
||||
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:
|
||||
for interface in self._interfaces:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue