ENH use bracket for request/release busname
This commit is contained in:
parent
8c20a4668d
commit
4951c2a35e
|
@ -89,7 +89,7 @@ run = do
|
|||
uninstallSignalHandlers
|
||||
hSetBuffering stdout LineBuffering
|
||||
withCache $ do
|
||||
withDBusX $ \db -> do
|
||||
withDBusX_ $ \db -> do
|
||||
let sys = dbSysClient db
|
||||
let fs = features sys
|
||||
startDBusInterfaces db fs
|
||||
|
@ -204,12 +204,12 @@ startXmobar = do
|
|||
startChildDaemons :: FeatureSet -> FIO [Process () () ()]
|
||||
startChildDaemons fs = catMaybes <$> mapM executeSometimes (fsDaemons fs)
|
||||
|
||||
withDBusX :: (DBusState -> FIO a) -> FIO a
|
||||
withDBusX = bracket (io connectDBusX) cleanup
|
||||
where
|
||||
cleanup db = do
|
||||
logInfo "unregistering xmonad from DBus"
|
||||
io $ disconnectDBus db
|
||||
-- withDBusX :: (DBusState -> FIO a) -> FIO a
|
||||
-- withDBusX = bracket (io connectDBusX) cleanup
|
||||
-- where
|
||||
-- cleanup db = do
|
||||
-- logInfo "unregistering xmonad from DBus"
|
||||
-- io $ disconnectDBus db
|
||||
|
||||
withChildDaemons :: FeatureSet -> ([Process () () ()] -> FIO a) -> FIO a
|
||||
withChildDaemons fs = bracket (startChildDaemons fs) cleanup
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
module XMonad.Internal.DBus.Control
|
||||
( Client
|
||||
, DBusState (..)
|
||||
, withDBusX
|
||||
, withDBusX_
|
||||
, withDBus
|
||||
, withDBus_
|
||||
, connectDBus
|
||||
|
@ -36,6 +38,14 @@ data DBusState = DBusState
|
|||
, dbSysClient :: Maybe SysClient
|
||||
}
|
||||
|
||||
withDBusX_ :: MonadUnliftIO m => (DBusState -> m a) -> m ()
|
||||
withDBusX_ = void . withDBusX
|
||||
|
||||
withDBusX :: MonadUnliftIO m => (DBusState -> m a) -> m (Maybe a)
|
||||
withDBusX f = withDBus $ \db -> do
|
||||
forM (dbSesClient db) $ \ses -> do
|
||||
bracket_ (requestXMonadName ses) (releaseXMonadName ses) $ f db
|
||||
|
||||
withDBus_ :: MonadUnliftIO m => (DBusState -> m a) -> m ()
|
||||
withDBus_ = void . withDBus
|
||||
|
||||
|
|
Loading…
Reference in New Issue