From 14480f667cf129808d7732e36cdeee0a27c95624 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Wed, 5 Feb 2014 01:55:30 +0100 Subject: Fix for infinite loops when MPD is not running Should address #76 and #111. --- src/Plugins/Monitors/MPD.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Plugins/Monitors/MPD.hs b/src/Plugins/Monitors/MPD.hs index 96a8f1d..b57924c 100644 --- a/src/Plugins/Monitors/MPD.hs +++ b/src/Plugins/Monitors/MPD.hs @@ -18,6 +18,7 @@ import Data.List import Plugins.Monitors.Common import System.Console.GetOpt import qualified Network.MPD as M +import Control.Concurrent (threadDelay) mpdConfig :: IO MConfig mpdConfig = mkMConfig "MPD: " @@ -57,7 +58,11 @@ runMPD args = do parseTemplate s mpdWait :: IO () -mpdWait = M.withMPD idle >> return () +mpdWait = do + status <- M.withMPD M.status + case status of + Left _ -> threadDelay 10000000 + _ -> M.withMPD idle >> return () where idle = M.idle [M.PlayerS, M.MixerS] mopts :: [String] -> IO MOpts @@ -68,7 +73,7 @@ mopts argv = parseMPD :: M.Response M.Status -> M.Response (Maybe M.Song) -> MOpts -> Monitor [String] -parseMPD (Left e) _ _ = return $ show e:repeat "" +parseMPD (Left e) _ _ = return $ show e:replicate 18 "" parseMPD (Right st) song opts = do songData <- parseSong song bar <- showPercentBar (100 * b) b -- cgit v1.2.3