From 6b8a1822c816c1d060f5d49228494b61503dfcd0 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 7 Aug 2020 19:29:45 -0400 Subject: removed default arg of channel', channel (Plugins.Monitors.Volume) Both functions had a default parameter for use in some error cases. Now each accepts only one parameter (a PerChannel), and return Nothing on an error. The definition of 'channel' confused me, so I simplified it. Hopefully it's now more clear that it just applies 'toInteger' to the 'IO (Maybe CLong)' that 'channel'' returns. --- src/Xmobar/Plugins/Monitors/Volume.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/Xmobar/Plugins/Monitors') diff --git a/src/Xmobar/Plugins/Monitors/Volume.hs b/src/Xmobar/Plugins/Monitors/Volume.hs index 9492201..c987f51 100644 --- a/src/Xmobar/Plugins/Monitors/Volume.hs +++ b/src/Xmobar/Plugins/Monitors/Volume.hs @@ -228,21 +228,23 @@ runVolumeWith opts mixerName controlName = do liftMonitor Nothing = unavailable liftMonitor (Just m) = m - channel' v r = AE.catch (getChannel FrontLeft v) (const $ return $ Just r) + channel' :: PerChannel a -> IO (Maybe a) + channel' v = AE.catch (getChannel FrontLeft v) (const (return Nothing)) - channel v r = channel' v r >>= \x -> return (x >>= Just . toInteger) + channel :: PerChannel CLong -> IO (Maybe Integer) + channel v = fmap (fmap toInteger) (channel' v) getDB :: Maybe Volume -> IO (Maybe Integer) getDB Nothing = return Nothing - getDB (Just v) = channel (dB v) 0 + getDB (Just v) = channel (dB v) getVal :: Maybe Volume -> IO (Maybe Integer) getVal Nothing = return Nothing - getVal (Just v) = channel (value v) 0 + getVal (Just v) = channel (value v) getSw :: Maybe Switch -> IO (Maybe Bool) getSw Nothing = return Nothing - getSw (Just s) = channel' s False + getSw (Just s) = channel' s getFormatDB :: VolumeOpts -> Maybe Integer -> Monitor String getFormatDB _ Nothing = unavailable -- cgit v1.2.3