ENH use dbus bracket for xmobar

This commit is contained in:
Nathan Dwarshuis 2022-12-31 22:31:23 -05:00
parent a997cac7a3
commit 3b8c6b0f4f
2 changed files with 9 additions and 3 deletions

View File

@ -50,10 +50,8 @@ parse ["--test"] = void $ withCache . evalConfig =<< connectDBus
parse _ = usage
run :: IO ()
run = withCache $ do
db <- connectDBus
run = withCache $ withDBus_ $ \db -> do
c <- evalConfig db
disconnectDBus db
liftIO $ do
-- this is needed to see any printed messages
hFlush stdout

View File

@ -6,6 +6,8 @@
module XMonad.Internal.DBus.Control
( Client
, DBusState (..)
, withDBus
, withDBus_
, connectDBus
, connectDBusX
, disconnectDBus
@ -34,6 +36,12 @@ data DBusState = DBusState
, dbSysClient :: Maybe SysClient
}
withDBus_ :: MonadUnliftIO m => (DBusState -> m a) -> m ()
withDBus_ = void . withDBus
withDBus :: MonadUnliftIO m => (DBusState -> m a) -> m a
withDBus = bracket connectDBus disconnectDBus
-- | Connect to the DBus
connectDBus :: MonadUnliftIO m => m DBusState
connectDBus = do