aboutsummaryrefslogtreecommitdiff
path: root/home-manager
diff options
context:
space:
mode:
Diffstat (limited to 'home-manager')
-rwxr-xr-xhome-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh48
-rw-r--r--home-manager/homeModules/waybar.nix12
2 files changed, 47 insertions, 13 deletions
diff --git a/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh b/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh
index a712a1e..c7f42be 100755
--- a/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh
+++ b/home-manager/homeModules/attachments/hypr-scripts/toggle-vpn.sh
@@ -2,8 +2,12 @@
ROFI_CMD="rofi -dmenu -theme-str listview{enabled:false;} -p"
LOCAL_STORAGE=~/.local/share/toggle
+TMP_PATH=/tmp/vpn-status
V2RAYA_URL="http://localhost:2017"
+DBUS_INTERFACE="com.vpn_status"
+DBUS_MEMBER="StatusChanged"
+
set_token() {
login=$(echo "" | $ROFI_CMD "Enter login > ")
password=$(echo "" | $ROFI_CMD "Enter password > " -theme-str 'entry {enabled: false;}')
@@ -33,6 +37,19 @@ toggle() {
echo $response | jq ".data.running" -r
}
+check_status() {
+ case $(cat $TMP_PATH) in
+ true)
+ output='{"text": "󰠥"}'
+ ;;
+ *)
+ output='{"text": ""}'
+ ;;
+ esac
+ echo $output | jq --unbuffered --compact-output
+}
+
+
if [[ ! -d "${LOCAL_STORAGE}" ]]; then
mkdir "${LOCAL_STORAGE}"
fi
@@ -48,14 +65,29 @@ if [[ -z "${TOKEN}" ]]; then
fi
STATUS=$(get_status $TOKEN)
-if [[ $STATUS == "true" ]]; then
- NEW_STATUS=$(toggle $TOKEN DELETE)
+echo $STATUS > $TMP_PATH
+
+if [[ $1 == "waybar" ]]; then
+ check_status
+
+ dbus-monitor --profile "interface='${DBUS_INTERFACE}',member='${DBUS_MEMBER}'" |
+ while read -r line; do
+ check_status
+ done
else
- NEW_STATUS=$(toggle $TOKEN POST)
-fi
+ if [[ $STATUS == "true" ]]; then
+ NEW_STATUS=$(toggle $TOKEN DELETE)
+ else
+ NEW_STATUS=$(toggle $TOKEN POST)
+ fi
-if [[ $NEW_STATUS == "null" ]]; then
- set_token
-fi
+ if [[ $NEW_STATUS == "null" ]]; then
+ set_token
+ exit 0
+ fi
-notify-send v2rayA "running: ${NEW_STATUS}"
+ echo $NEW_STATUS > $TMP_PATH
+ dbus-send --type=signal / "${DBUS_INTERFACE}.${DBUS_MEMBER}"
+
+ notify-send v2rayA "running: ${NEW_STATUS}"
+fi
diff --git a/home-manager/homeModules/waybar.nix b/home-manager/homeModules/waybar.nix
index 4862d0e..ae3e57f 100644
--- a/home-manager/homeModules/waybar.nix
+++ b/home-manager/homeModules/waybar.nix
@@ -29,7 +29,7 @@
margin-down = 5;
modules-left = ["hyprland/workspaces"];
modules-center = ["clock"];
- modules-right = ["network" "memory" "backlight" "pulseaudio" "hyprland/language" "tray" "battery"];
+ modules-right = ["network" "custom/vpn" "memory" "backlight" "pulseaudio" "hyprland/language" "tray" "battery"];
"hyprland/workspaces" = {
format = "{icon}";
"format-icons" = {
@@ -55,11 +55,9 @@
format = "{:%H:%M 󰅐}";
tooltip-format = "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>";
format-alt = "{:%d %h %Y 󰃮}";
- on-click = "killall calcure || alacritty -t calcure -e calcure;sudo ydotool click 0xc1";
};
"memory" = {
format = "{}% ";
- on-click = "killall btop || alacritty -t btop -e btop;sudo ydotool click 0xc1";
};
"backlight" = {
format = "{percent}% {icon}";
@@ -85,7 +83,11 @@
tooltip-format = "{ifname} via {gwaddr} 󰩟";
format-linked = "{ifname} (No IP) 󰩟";
format-disconnected = "󰤫";
- on-click = "killall connman-gtk || connman-gtk;sudo ydotool click 0xc1";
+ };
+ "custom/vpn" = {
+ format = "{text}";
+ exec = "${./attachments/hypr-scripts/toggle-vpn.sh} waybar";
+ return-type = "json";
};
"pulseaudio" = {
format = "{volume}% {icon} {format_source}";
@@ -94,7 +96,7 @@
format-muted = "󰝟 {format_source}";
format-source = "{volume}% 󰍬";
format-source-muted = "󰍭";
- on-click = "killall bluetuith || alacritty -t blue -e bluetuith; sudo ydotool click 0xc1";
+
"format-icons" = {
headphone = "󰋋";
hands-free = "";