ENH use plugin name in xmobar loggers

This commit is contained in:
Nathan Dwarshuis 2023-01-01 22:29:29 -05:00
parent cc094bb071
commit 69ed4839da
8 changed files with 24 additions and 15 deletions

View File

@ -13,13 +13,14 @@ import Xmobar.Plugins.Common
startBacklight
:: (MonadUnliftIO m, RealFrac a)
=> ((Maybe a -> RIO SimpleApp ()) -> SesClient -> RIO SimpleApp ())
=> Utf8Builder
-> ((Maybe a -> RIO SimpleApp ()) -> SesClient -> RIO SimpleApp ())
-> (SesClient -> RIO SimpleApp (Maybe a))
-> T.Text
-> Callback
-> m ()
startBacklight matchSignal callGetBrightness icon cb = do
withDBusClientConnection cb $ \c -> do
startBacklight name matchSignal callGetBrightness icon cb = do
withDBusClientConnection cb name $ \c -> do
matchSignal dpy c
dpy =<< callGetBrightness c
where

View File

@ -65,7 +65,7 @@ data Bluetooth = Bluetooth Icons Colors deriving (Read, Show)
instance Exec Bluetooth where
alias (Bluetooth _ _) = T.unpack btAlias
start (Bluetooth icons colors) cb =
withDBusClientConnection cb $ startAdapter icons colors cb
withDBusClientConnection cb "bluetooth" $ startAdapter icons colors cb
startAdapter
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)

View File

@ -25,4 +25,4 @@ ckAlias = "clevokeyboard"
instance Exec ClevoKeyboard where
alias (ClevoKeyboard _) = T.unpack ckAlias
start (ClevoKeyboard icon) =
startBacklight matchSignalCK callGetBrightnessCK icon
startBacklight "clevo keyboard" matchSignalCK callGetBrightnessCK icon

View File

@ -70,6 +70,13 @@ displayMaybe' cb = maybe (liftIO $ cb $ T.unpack na)
withDBusClientConnection
:: (MonadUnliftIO m, SafeClient c)
=> Callback
-> Utf8Builder
-> (c -> RIO SimpleApp ())
-> m ()
withDBusClientConnection cb f = runSimpleApp $ displayMaybe' cb f =<< getDBusClient
withDBusClientConnection cb name f = do
logOpts <- setLogVerboseFormat True . setLogUseTime True . setLogFormat pre <$> logOptionsHandle stderr False
withLogFunc logOpts $ \lf -> do
env <- mkSimpleApp lf Nothing
runRIO env $ displayMaybe' cb f =<< getDBusClient
where
pre rest = "[" <> name <> " plugin] " <> rest

View File

@ -67,11 +67,12 @@ matchStatus = matchPropertyChanged nmDeviceInterface devSignal
instance Exec Device where
alias (Device (iface, _, _)) = T.unpack iface
start (Device (iface, text, colors)) cb = do
withDBusClientConnection cb $ \sys -> do
start (Device (iface, text, colors)) cb =
withDBusClientConnection cb logName $ \sys -> do
path <- getDevice sys iface
displayMaybe' cb (listener sys) path
where
logName = "device@" <> Utf8Builder (encodeUtf8Builder iface)
listener sys path = do
rule <- matchPropertyFull sys networkManagerBus (Just path)
-- TODO warn the user here rather than silently drop the listener

View File

@ -25,4 +25,4 @@ blAlias = "intelbacklight"
instance Exec IntelBacklight where
alias (IntelBacklight _) = T.unpack blAlias
start (IntelBacklight icon) =
startBacklight matchSignalIB callGetBrightnessIB icon
startBacklight "intel backlight" matchSignalIB callGetBrightnessIB icon

View File

@ -24,9 +24,9 @@ ssAlias = "screensaver"
instance Exec Screensaver where
alias (Screensaver _) = T.unpack ssAlias
start (Screensaver (text, colors)) cb = do
withDBusClientConnection cb $ \sys -> do
matchSignal display sys
display =<< callQuery sys
start (Screensaver (text, colors)) cb =
withDBusClientConnection cb "screensaver" $ \sys -> do
matchSignal dpy sys
dpy =<< callQuery sys
where
display = displayMaybe cb $ return . (\s -> colorText colors s text)
dpy = displayMaybe cb $ return . (\s -> colorText colors s text)

View File

@ -31,7 +31,7 @@ newtype VPN = VPN (T.Text, Colors) deriving (Read, Show)
instance Exec VPN where
alias (VPN _) = T.unpack vpnAlias
start (VPN (text, colors)) cb =
withDBusClientConnection cb $ \c -> do
withDBusClientConnection cb "VPN" $ \c -> do
state <- initState c
let dpy = displayMaybe cb iconFormatter . Just =<< readState state
let signalCallback' f = f state dpy