From 13b29f71396a726e3cd12c4d8d376c711e473fff Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Sun, 25 Jul 2021 13:59:58 +0200 Subject: [PATCH] Added a wifi toggle #290 Signed-off-by: Stacy Harper --- Makefile | 2 ++ configs/sudo/wifi | 1 + scripts/core/sxmo_appmenu.sh | 5 +++++ scripts/core/sxmo_wifitoggle.sh | 38 +++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 configs/sudo/wifi create mode 100755 scripts/core/sxmo_wifitoggle.sh diff --git a/Makefile b/Makefile index 62c02af..0fde409 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,8 @@ install: $(PROGRAMS) install -D -m 0644 -t $(DESTDIR)/etc/udev/rules.d/ configs/udev/*.rules + install -D -m 0700 -t $(DESTDIR)/etc/sudoers.d/ configs/sudo/* + install -D -m 0644 -t $(DESTDIR)$(PREFIX)/share/applications/ configs/xdg/mimeapps.list install -D -m 0644 -T configs/xorg/monitor.conf $(DESTDIR)$(PREFIX)/share/X11/xorg.conf.d/90-monitor.conf diff --git a/configs/sudo/wifi b/configs/sudo/wifi new file mode 100644 index 0000000..02cbf55 --- /dev/null +++ b/configs/sudo/wifi @@ -0,0 +1 @@ +ALL ALL=NOPASSWD: /usr/bin/sxmo_wifitoggle.sh diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index fa70e3c..745607c 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -142,6 +142,11 @@ programchoicesinit() { $icon_phn Modem Toggle ^ 1 ^ sxmo_modemmonitortoggle.sh $icon_inf Modem Info ^ 0 ^ sxmo_modeminfo.sh $icon_phl Modem Log ^ 0 ^ sxmo_modemlog.sh + $icon_wif Wifi $( + rfkill -rn | grep wlan | grep -qE "unblocked unblocked" && + printf %b "On → Off" || printf %b "Off → On"; + printf %b "^ 1 ^ sudo sxmo_wifitoggle.sh" + ) $icon_fll Flashlight $( grep -qE '^0$' /sys/class/leds/white:flash/brightness && printf %b "Off → On" || printf %b "On → Off"; diff --git a/scripts/core/sxmo_wifitoggle.sh b/scripts/core/sxmo_wifitoggle.sh new file mode 100755 index 0000000..f25fc7f --- /dev/null +++ b/scripts/core/sxmo_wifitoggle.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env sh + +# Note: this script should be run as root via sudo + +[ -n "$WLAN_MODULE" ] || WLAN_MODULE="8723cs" + +on() { + if lsmod | grep -qE "$WLAN_MODULE"; then + rfkill unblock wlan + else + modprobe "$WLAN_MODULE" && rfkill unblock wlan + fi +} + +off() { + if lsmod | grep -qE "$WLAN_MODULE"; then + rfkill block wlan && rmmod "$WLAN_MODULE" + else + rfkill block wlan + fi +} + +case "$1" in + on) + on + ;; + off) + off + ;; + *) #toggle + if rfkill -rn | grep wlan | grep -qE "unblocked unblocked"; then + off + else + on + fi +esac + +sxmo_statusbarupdate.sh