2020-04-01 22:06:00 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | VPN plugin
|
|
|
|
--
|
|
|
|
-- Use the NetworkManger interface on DBus to check status
|
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
module Xmobar.Plugins.VPN
|
|
|
|
( VPN(..)
|
|
|
|
, vpnAlias
|
2021-11-24 00:43:58 -05:00
|
|
|
, vpnDep
|
2021-06-21 23:41:57 -04:00
|
|
|
) where
|
2020-03-21 18:37:26 -04:00
|
|
|
|
2021-11-27 13:24:13 -05:00
|
|
|
import Control.Monad
|
|
|
|
|
2020-03-25 18:55:52 -04:00
|
|
|
import DBus
|
2021-11-27 01:02:22 -05:00
|
|
|
import DBus.Internal
|
2020-03-21 18:37:26 -04:00
|
|
|
|
2021-11-24 00:43:58 -05:00
|
|
|
import XMonad.Internal.Dependency
|
2021-06-19 00:54:01 -04:00
|
|
|
import Xmobar
|
2021-11-24 00:43:58 -05:00
|
|
|
import Xmobar.Plugins.Common
|
2020-03-21 18:37:26 -04:00
|
|
|
|
2021-11-27 17:33:02 -05:00
|
|
|
newtype VPN = VPN (String, Colors) deriving (Read, Show)
|
2021-06-21 23:41:57 -04:00
|
|
|
|
|
|
|
vpnBus :: BusName
|
2021-11-24 00:43:58 -05:00
|
|
|
vpnBus = busName_ "org.freedesktop.NetworkManager"
|
2021-06-21 23:41:57 -04:00
|
|
|
|
|
|
|
vpnPath :: ObjectPath
|
2021-11-24 00:43:58 -05:00
|
|
|
vpnPath = objectPath_ "/org/freedesktop/NetworkManager"
|
2021-06-21 23:41:57 -04:00
|
|
|
|
2021-11-09 00:59:17 -05:00
|
|
|
vpnInterface :: InterfaceName
|
2021-11-24 00:43:58 -05:00
|
|
|
vpnInterface = interfaceName_ "org.freedesktop.NetworkManager"
|
2021-11-09 00:59:17 -05:00
|
|
|
|
|
|
|
vpnConnType :: String
|
|
|
|
vpnConnType = "PrimaryConnectionType"
|
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
vpnAlias :: String
|
|
|
|
vpnAlias = "vpn"
|
2020-03-21 18:37:26 -04:00
|
|
|
|
2021-11-24 00:43:58 -05:00
|
|
|
vpnDep :: DBusDep
|
|
|
|
vpnDep = Endpoint vpnBus vpnPath vpnInterface $ Property_ vpnConnType
|
|
|
|
|
2020-03-22 17:17:57 -04:00
|
|
|
instance Exec VPN where
|
2021-11-24 00:43:58 -05:00
|
|
|
alias (VPN _) = vpnAlias
|
2021-11-27 17:33:02 -05:00
|
|
|
start (VPN (text, colors)) cb =
|
2021-11-27 13:24:13 -05:00
|
|
|
withDBusClientConnection True cb $ \c -> do
|
|
|
|
rule <- matchPropertyFull c vpnBus (Just vpnPath)
|
|
|
|
-- TODO intelligently warn user
|
|
|
|
forM_ rule $ \r -> startListener r getProp fromSignal chooseColor' cb c
|
2020-03-21 18:37:26 -04:00
|
|
|
where
|
2021-11-27 13:24:13 -05:00
|
|
|
getProp = callPropertyGet vpnBus vpnPath vpnInterface $ memberName_ vpnConnType
|
2021-11-26 23:35:03 -05:00
|
|
|
fromSignal = matchPropertyChanged vpnInterface vpnConnType
|
2021-11-27 17:33:02 -05:00
|
|
|
chooseColor' = return . (\s -> colorText colors s text) . ("vpn" ==)
|