From dc670b15ba8b279e1119ac895dd681feab4e3939 Mon Sep 17 00:00:00 2001 From: Adam Vogt Date: Tue, 25 Feb 2014 01:27:03 -0500 Subject: have disabled plugins still accept input This change lets xmobar compiled without -fwith_inotify accept a config that mentions the Mail plugin with a warning (and display an Updating...). --- src/Plugins/DateZone.hs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/Plugins/DateZone.hs') diff --git a/src/Plugins/DateZone.hs b/src/Plugins/DateZone.hs index 79596c9..f1737fb 100644 --- a/src/Plugins/DateZone.hs +++ b/src/Plugins/DateZone.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DoAndIfThenElse #-} ----------------------------------------------------------------------------- -- | @@ -23,30 +24,37 @@ module Plugins.DateZone (DateZone(..)) where import Plugins -import Localize +#ifdef DATEZONE import Control.Concurrent.STM +import System.IO.Unsafe + +import Localize import Data.Time.LocalTime import Data.Time.Format import Data.Time.LocalTime.TimeZone.Olson import Data.Time.LocalTime.TimeZone.Series -import System.IO.Unsafe import System.Locale (TimeLocale) +#else +import System.IO +import Plugins.Date +#endif -{-# NOINLINE localeLock #-} --- ensures that only one plugin instance sets the locale -localeLock :: TMVar Bool -localeLock = unsafePerformIO (newTMVarIO False) - data DateZone = DateZone String String String String Int deriving (Read, Show) instance Exec DateZone where alias (DateZone _ _ _ a _) = a +#ifndef DATEZONE + start (DateZone f _ _ a r) cb = do + hPutStrLn stderr $ "Warning: DateZone plugin needs -fwith_datezone."++ + " Using Date plugin instead." + start (Date f a r) cb +#else start (DateZone f l z _ r) cb = do lock <- atomically $ takeTMVar localeLock setupTimeLocale l @@ -60,6 +68,11 @@ instance Exec DateZone where where go func = func >>= cb >> tenthSeconds r >> go func +{-# NOINLINE localeLock #-} +-- ensures that only one plugin instance sets the locale +localeLock :: TMVar Bool +localeLock = unsafePerformIO (newTMVarIO False) + date :: String -> TimeLocale -> IO String date format loc = getZonedTime >>= return . formatTime loc format @@ -67,3 +80,4 @@ dateZone :: String -> TimeLocale -> TimeZoneSeries -> IO String dateZone format loc timeZone = getZonedTime >>= return . formatTime loc format . utcToLocalTime' timeZone . zonedTimeToUTC -- zonedTime <- getZonedTime -- return $ formatTime loc format $ utcToLocalTime' timeZone $ zonedTimeToUTC zonedTime +#endif -- cgit v1.2.3