summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors/UVMeter.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-01-27 00:56:51 +0000
committerjao <jao@gnu.org>2020-01-27 00:56:51 +0000
commiteb878f652ac52348dffdc13d36c1ca44775a7109 (patch)
tree2b318a7438ce74ae5b8013ecfe94e611fc5aa070 /src/Xmobar/Plugins/Monitors/UVMeter.hs
parent5a7a0298a3e94f49321f7922f987a1a0396850a8 (diff)
downloadxmobar-eb878f652ac52348dffdc13d36c1ca44775a7109.tar.gz
xmobar-eb878f652ac52348dffdc13d36c1ca44775a7109.tar.bz2
Revert "Use a single Manager across the whole application"
This reverts commit 1f1f0bd8b811740c84215f9ed4fa5ebd8309a990.
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/UVMeter.hs')
-rw-r--r--src/Xmobar/Plugins/Monitors/UVMeter.hs30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/Xmobar/Plugins/Monitors/UVMeter.hs b/src/Xmobar/Plugins/Monitors/UVMeter.hs
index 3756856..079177f 100644
--- a/src/Xmobar/Plugins/Monitors/UVMeter.hs
+++ b/src/Xmobar/Plugins/Monitors/UVMeter.hs
@@ -18,14 +18,14 @@ module Xmobar.Plugins.Monitors.UVMeter where
import Xmobar.Plugins.Monitors.Common
import qualified Control.Exception as CE
-import Network.HTTP.Conduit (httpLbs, parseRequest, responseBody)
+import Network.HTTP.Conduit
+ (parseRequest, newManager, tlsManagerSettings, httpLbs,
+ responseBody)
import Data.ByteString.Lazy.Char8 as B
import Text.Read (readMaybe)
import Text.Parsec
import Text.Parsec.String
import Control.Monad (void)
-import Control.Monad.Reader (asks)
-import Data.IORef (readIORef)
uvConfig :: IO MConfig
@@ -40,18 +40,16 @@ newtype UvInfo = UV { index :: String }
uvURL :: String
uvURL = "https://uvdata.arpansa.gov.au/xml/uvvalues.xml"
--- | Get the UV data from the given url.
-getData :: Monitor String
-getData = do
- man <- io =<< readIORef <$> asks manager
- io $ CE.catch
- (do request <- parseRequest uvURL
- res <- httpLbs request man
- return $ B.unpack $ responseBody res)
- errHandler
- where
- errHandler :: CE.SomeException -> IO String
- errHandler _ = return "<Could not retrieve data>"
+getData :: IO String
+getData =
+ CE.catch (do request <- parseRequest uvURL
+ manager <- newManager tlsManagerSettings
+ res <- httpLbs request manager
+ return $ B.unpack $ responseBody res)
+ errHandler
+ where errHandler
+ :: CE.SomeException -> IO String
+ errHandler _ = return "<Could not retrieve data>"
textToXMLDocument :: String -> Either ParseError [XML]
textToXMLDocument = parse document ""
@@ -75,7 +73,7 @@ getUVRating _ [] = Nothing
runUVMeter :: [String] -> Monitor String
runUVMeter [] = return "N.A."
runUVMeter (s:_) = do
- resp <- getData
+ resp <- io getData
case textToXMLDocument resp of
Right doc -> formatUVRating (getUVRating s doc)
Left _ -> getConfigValue naString