ENH check for vpn profiles before enabling vpn in xmobar

This commit is contained in:
Nathan Dwarshuis 2021-06-23 00:38:23 -04:00
parent adc2222a21
commit b93fbeee6d
2 changed files with 23 additions and 6 deletions

View File

@ -20,8 +20,10 @@ import Data.Maybe
import DBus
import System.Directory
import System.Exit
import System.FilePath.Posix
import System.IO.Error
import System.Process (readProcessWithExitCode)
import Xmobar.Plugins.Bluetooth
import Xmobar.Plugins.Device
@ -114,9 +116,28 @@ getWireless = do
where
hasWireless p = doesPathExist $ sysfsNet </> p </> "wireless"
vpnCmd :: CmdSpec
vpnCmd = CmdSpec
{ csAlias = vpnAlias
, csDepends = Just $ sysDepends vpnBus vpnPath
, csRunnable = Run
$ VPN ("<fn=2>\xf023</fn>", T.fgColor, T.backdropFgColor) 5
}
getVPN :: IO (Maybe CmdSpec)
getVPN = do
-- TODO ensure nmcli exists (or guard against an exception if it doesn't)
(ec, out, _) <- readProcessWithExitCode "nmcli" args ""
return $ case ec of
ExitSuccess -> if "vpn" `elem` lines out then Just vpnCmd else Nothing
_ -> Nothing
where
args = ["-c", "no", "-t", "-f", "TYPE", "c", "show"]
myCommands :: IO BarRegions
myCommands = do
wirelessSpec <- getWireless
vpnSpec <- getVPN
let left =
[ CmdSpec
{ csAlias = "UnsafeStdinReader"
@ -134,12 +155,7 @@ myCommands = do
$ Device ("enp7s0f1", "<fn=2>\xf0e8</fn>", T.fgColor, T.backdropFgColor) 5
}
, Just $ CmdSpec
{ csAlias = vpnAlias
, csDepends = Just $ sysDepends vpnBus vpnPath
, csRunnable = Run
$ VPN ("<fn=2>\xf023</fn>", T.fgColor, T.backdropFgColor) 5
}
, vpnSpec
, Just $ CmdSpec
{ csAlias = btAlias

View File

@ -65,6 +65,7 @@ executable xmobar
, my-xmonad
, xmobar
, xmonad >= 0.13
, process >= 1.6.5.0
, filepath >= 1.4.2.1
, xmonad-contrib >= 0.13
, directory >= 1.3.3.0