summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Volume.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2015-03-11 00:52:49 +0100
committerjao <jao@gnu.org>2015-03-11 00:52:49 +0100
commit368556826d090b508a25111914b214a9fb0a69ba (patch)
tree3b2734f9a58015d3f391fb7e53410c40dec13565 /src/Plugins/Monitors/Volume.hs
parentf4172b310a861d5bf14af22f991bd2047a2deebf (diff)
downloadxmobar-368556826d090b508a25111914b214a9fb0a69ba.tar.gz
xmobar-368556826d090b508a25111914b214a9fb0a69ba.tar.bz2
Another attempt at better error handling in Volume
Diffstat (limited to 'src/Plugins/Monitors/Volume.hs')
-rw-r--r--src/Plugins/Monitors/Volume.hs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/Plugins/Monitors/Volume.hs b/src/Plugins/Monitors/Volume.hs
index 9f33b3e..338cf64 100644
--- a/src/Plugins/Monitors/Volume.hs
+++ b/src/Plugins/Monitors/Volume.hs
@@ -1,7 +1,7 @@
-----------------------------------------------------------------------------
-- |
-- Module : Plugins.Monitors.Volume
--- Copyright : (c) 2011, 2013 Thomas Tuegel
+-- Copyright : (c) 2011, 2013, 2015 Thomas Tuegel
-- License : BSD-style (see LICENSE)
--
-- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org>
@@ -122,13 +122,7 @@ formatDb opts dbi = do
runVolume :: String -> String -> [String] -> Monitor String
runVolume mixerName controlName argv = do
opts <- io $ parseOpts argv
- (lo, hi, val, db, sw) <- io $ withMixer mixerName $ \mixer -> do
- control <- getControlByName mixer controlName
- (lo, hi) <- liftMaybe $ getRange <$> volumeControl control
- val <- getVal $ volumeControl control
- db <- getDB $ volumeControl control
- sw <- getSw $ switchControl control
- return (lo, hi, val, db, sw)
+ (lo, hi, val, db, sw) <- io readMixer
p <- liftMonitor $ liftM3 formatVol lo hi val
b <- liftMonitor $ liftM3 formatVolBar lo hi val
v <- liftMonitor $ liftM3 formatVolVBar lo hi val
@@ -139,6 +133,16 @@ runVolume mixerName controlName argv = do
where
+ readMixer =
+ AE.catch (withMixer mixerName $ \mixer -> do
+ control <- getControlByName mixer controlName
+ (lo, hi) <- liftMaybe $ getRange <$> volumeControl control
+ val <- getVal $ volumeControl control
+ db <- getDB $ volumeControl control
+ sw <- getSw $ switchControl control
+ return (lo, hi, val, db, sw))
+ (const $ return (Nothing, Nothing, Nothing, Nothing, Nothing))
+
volumeControl :: Maybe Control -> Maybe Volume
volumeControl c = join $
(playback . volume <$> c) `mplus` (common . volume <$> c)