summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-04-12 18:36:48 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-04-12 18:36:48 -0400
commit5ede7f0368c1fab5dedd836f55a91cdc936816c6 (patch)
treebbce5ea15dbb521d42cdd652be0619255f726335 /Assistant
parent1434808d1379f3d941ab16868ef7bfabf5381770 (diff)
detect wicd network disconnection events
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/Threads/NetWatcher.hs28
1 files changed, 23 insertions, 5 deletions
diff --git a/Assistant/Threads/NetWatcher.hs b/Assistant/Threads/NetWatcher.hs
index c1115f637..9dd617822 100644
--- a/Assistant/Threads/NetWatcher.hs
+++ b/Assistant/Threads/NetWatcher.hs
@@ -130,18 +130,36 @@ listenNMConnections client setconnected =
setconnected True
| otherwise = noop
-{- Listens for Wicd connections (not currently disconnections). -}
+{- Listens for Wicd connections and disconnections.
+ -
+ - Connection example:
+ - ConnectResultsSent:
+ - Variant "success"
+ -
+ - Diconnection example:
+ - StatusChanged
+ - [Variant 0, Variant [Varient ""]]
+ -}
listenWicdConnections :: Client -> (Bool -> IO ()) -> IO ()
-listenWicdConnections client callback =
- listen client matcher $ \event ->
+listenWicdConnections client setconnected = do
+ listen client connmatcher $ \event ->
when (any (== wicd_success) (signalBody event)) $
- callback False >> callback True
+ setconnected True
+ listen client statusmatcher $ \event -> handle (signalBody event)
where
- matcher = matchAny
+ connmatcher = matchAny
{ matchInterface = Just "org.wicd.daemon"
, matchMember = Just "ConnectResultsSent"
}
+ statusmatcher = matchAny
+ { matchInterface = Just "org.wicd.daemon"
+ , matchMember = Just "StatusChanged"
+ }
wicd_success = toVariant ("success" :: String)
+ wicd_disconnected = toVariant [toVariant ("" :: String)]
+ handle status
+ | any (== wicd_disconnected) status = setconnected False
+ | otherwise = noop
#endif