xmonad-config/lib/Xmobar/Plugins/VPN.hs

49 lines
1.3 KiB
Haskell
Raw Normal View History

2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | VPN plugin
--
-- Use the NetworkManger interface on DBus to check status
module Xmobar.Plugins.VPN
( VPN(..)
, vpnAlias
, vpnDep
) where
2020-03-21 18:37:26 -04:00
2020-03-25 18:55:52 -04:00
import DBus
import DBus.Internal
2020-03-21 18:37:26 -04:00
import XMonad.Internal.Dependency
2021-06-19 00:54:01 -04:00
import Xmobar
import Xmobar.Plugins.Common
2020-03-21 18:37:26 -04:00
newtype VPN = VPN (String, String, String) deriving (Read, Show)
vpnBus :: BusName
vpnBus = busName_ "org.freedesktop.NetworkManager"
vpnPath :: ObjectPath
vpnPath = objectPath_ "/org/freedesktop/NetworkManager"
vpnInterface :: InterfaceName
vpnInterface = interfaceName_ "org.freedesktop.NetworkManager"
vpnConnType :: String
vpnConnType = "PrimaryConnectionType"
vpnAlias :: String
vpnAlias = "vpn"
2020-03-21 18:37:26 -04:00
vpnDep :: DBusDep
vpnDep = Endpoint vpnBus vpnPath vpnInterface $ Property_ vpnConnType
2020-03-22 17:17:57 -04:00
instance Exec VPN where
alias (VPN _) = vpnAlias
2021-11-24 01:14:23 -05:00
start (VPN (text, colorOn, colorOff)) cb =
withDBusClientConnection True cb
2021-11-25 00:12:00 -05:00
$ startListener rule getProp fromSignal chooseColor' cb
2020-03-21 18:37:26 -04:00
where
2021-11-24 01:14:23 -05:00
rule = matchProperty vpnPath
getProp = callPropertyGet vpnBus vpnPath vpnInterface vpnConnType
fromSignal = matchPropertyChanged vpnInterface vpnConnType
chooseColor' = return . chooseColor text colorOn colorOff . ("vpn" ==)