pinwheel: Toggle the work VPN from waybar without sudo
This commit is contained in:
2 files changed
+69
-26
No files matched your search
@@ -87,26 +87,33 @@ let
|
||||
esac
|
||||
'';
|
||||
|
||||
work-vpn-status = pkgs.writeShellScript "work-vpn-status" ''
|
||||
ACTIVE_ENVS=""
|
||||
work-vpn = pkgs.writeShellScript "work-vpn" ''
|
||||
connected() {
|
||||
systemctl is-active --quiet openvpn-work-staging.service openvpn-work-production.service
|
||||
}
|
||||
|
||||
STAGING_STATUS=$(systemctl is-active openvpn-work-staging.service)
|
||||
if [ "$STAGING_STATUS" == "active" ]; then
|
||||
ACTIVE_ENVS="S"
|
||||
fi
|
||||
output() {
|
||||
if connected; then
|
||||
echo '{ "text": "WORK-VPN ON", "class": "connected" }'
|
||||
else
|
||||
echo "{ \"text\": \"<span font='16' rise='-3000'></span>\", \"tooltip\": \"Work VPN off\", \"class\": \"disconnected\" }"
|
||||
fi
|
||||
}
|
||||
|
||||
PRODUCTION_STATUS=$(systemctl is-active openvpn-work-production.service)
|
||||
if [ "$PRODUCTION_STATUS" == "active" ]; then
|
||||
if [ -n "$ACTIVE_ENVS" ]; then
|
||||
ACTIVE_ENVS="$ACTIVE_ENVS&P"
|
||||
else
|
||||
ACTIVE_ENVS="P"
|
||||
fi
|
||||
fi
|
||||
toggle() {
|
||||
if connected; then
|
||||
systemctl stop work-vpn.target && ${pkgs.libnotify}/bin/notify-send "Disconnected from work VPN"
|
||||
else
|
||||
systemctl start work-vpn.target && ${pkgs.libnotify}/bin/notify-send "Connected to work VPN"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -n "$ACTIVE_ENVS" ]; then
|
||||
echo "WORK-VPN $ACTIVE_ENVS ON"
|
||||
fi
|
||||
case $1 in
|
||||
--toggle)
|
||||
toggle ;;
|
||||
--output)
|
||||
output ;;
|
||||
esac
|
||||
'';
|
||||
|
||||
toggle-bt-power = pkgs.writeShellScript "toggle-bt-power" ''
|
||||
@@ -142,20 +149,22 @@ in
|
||||
|
||||
modules-left = lib.mkIf hyprlandEnabled [ "hyprland/workspaces" ];
|
||||
modules-right = [
|
||||
"custom/work-vpn-status"
|
||||
"custom/music"
|
||||
"custom/container-status"
|
||||
"custom/dunst"
|
||||
"bluetooth"
|
||||
"wireplumber"
|
||||
"custom/work-vpn"
|
||||
"custom/tailscale"
|
||||
"network"
|
||||
"battery"
|
||||
"clock"
|
||||
];
|
||||
|
||||
"custom/work-vpn-status" = {
|
||||
exec = "${work-vpn-status}";
|
||||
"custom/work-vpn" = {
|
||||
exec = "${work-vpn} --output";
|
||||
return-type = "json";
|
||||
on-click-right = "${work-vpn} --toggle";
|
||||
interval = 2;
|
||||
};
|
||||
|
||||
@@ -247,12 +256,14 @@ in
|
||||
|
||||
modules-left = lib.mkIf hyprlandEnabled [ "hyprland/workspaces" ];
|
||||
modules-right = [
|
||||
"custom/work-vpn-status"
|
||||
"custom/work-vpn"
|
||||
"clock"
|
||||
];
|
||||
|
||||
"custom/work-vpn-status" = {
|
||||
exec = "${work-vpn-status}";
|
||||
"custom/work-vpn" = {
|
||||
exec = "${work-vpn} --output";
|
||||
return-type = "json";
|
||||
on-click-right = "${work-vpn} --toggle";
|
||||
interval = 2;
|
||||
};
|
||||
|
||||
@@ -306,10 +317,14 @@ in
|
||||
color: #${config.lib.colors.warning};
|
||||
}
|
||||
|
||||
#custom-work-vpn-status {
|
||||
#custom-work-vpn.connected {
|
||||
color: #${config.lib.colors.warning};
|
||||
}
|
||||
|
||||
#custom-work-vpn.disconnected {
|
||||
color: #${config.lib.colors.foreground-dim};
|
||||
}
|
||||
|
||||
#custom-container-status.running {
|
||||
color: #${config.lib.colors.warning};
|
||||
font-size: 30px;
|
||||
|
||||
Reference in new issue
Block a user