summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-04-21 04:19:37 +0100
committerjao <jao@gnu.org>2020-04-21 04:19:37 +0100
commit2dec7b2ff2d064918b57c73879eb83a9ed93e4be (patch)
treed0b5a85a1d16827e3d29397f46e58ecceb40cc3c /src/Xmobar/Plugins
parentbcc680e0a0b48e86dc3ffc3affaaec61994495aa (diff)
downloadxmobar-2dec7b2ff2d064918b57c73879eb83a9ed93e4be.tar.gz
xmobar-2dec7b2ff2d064918b57c73879eb83a9ed93e4be.tar.bz2
MPD: catch errors earlier so that reconnections are allowed
Diffstat (limited to 'src/Xmobar/Plugins')
-rw-r--r--src/Xmobar/Plugins/Monitors/MPD.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/Xmobar/Plugins/Monitors/MPD.hs b/src/Xmobar/Plugins/Monitors/MPD.hs
index 3274c42..3bbae5d 100644
--- a/src/Xmobar/Plugins/Monitors/MPD.hs
+++ b/src/Xmobar/Plugins/Monitors/MPD.hs
@@ -20,14 +20,17 @@ import Xmobar.Plugins.Monitors.Common
import System.Console.GetOpt
import qualified Network.MPD as M
import Control.Concurrent (threadDelay)
+import Control.Monad.Except (catchError)
+
+templateVars :: [String]
+templateVars = [ "bar", "vbar", "ipat", "state", "statei", "volume", "length"
+ , "lapsed", "remaining", "plength", "ppos", "flags", "file"
+ , "name", "artist", "composer", "performer"
+ , "album", "title", "track", "genre", "date"
+ ]
mpdConfig :: IO MConfig
-mpdConfig = mkMConfig "MPD: <state>"
- [ "bar", "vbar", "ipat", "state", "statei", "volume", "length"
- , "lapsed", "remaining", "plength", "ppos", "flags", "file"
- , "name", "artist", "composer", "performer"
- , "album", "title", "track", "genre", "date"
- ]
+mpdConfig = mkMConfig "MPD: <state>" templateVars
data MOpts = MOpts
{ mPlaying :: String
@@ -60,7 +63,8 @@ options =
]
withMPD :: MOpts -> M.MPD a -> IO (M.Response a)
-withMPD opts = M.withMPD_ (mHost opts) (mPort opts)
+withMPD opts a =
+ M.withMPD_ (mHost opts) (mPort opts) a `catchError` (\_ -> return (Left M.NoMPD))
runMPD :: [String] -> Monitor String
runMPD args = do
@@ -74,7 +78,7 @@ mpdWait :: IO ()
mpdWait = do
status <- M.withMPD $ M.idle [M.PlayerS, M.MixerS, M.OptionsS]
case status of
- Left _ -> threadDelay 10000000
+ Left _ -> threadDelay 5000
_ -> return ()
mpdReady :: [String] -> Monitor Bool
@@ -91,7 +95,7 @@ mpdReady args = do
parseMPD :: M.Response M.Status -> M.Response (Maybe M.Song) -> MOpts
-> Monitor [String]
-parseMPD (Left e) _ _ = return $ show e:replicate 19 ""
+parseMPD (Left _) _ _ = return $ "N/A": repeat ""
parseMPD (Right st) song opts = do
songData <- parseSong song
bar <- showPercentBar (100 * b) b