ENH use bracket for request/release busname

This commit is contained in:
Nathan Dwarshuis 2022-12-31 22:47:36 -05:00
parent 8c20a4668d
commit 4951c2a35e
2 changed files with 17 additions and 7 deletions

View File

@ -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

View File

@ -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