Permalink
Browse files

Always require http-conduit for weather (fixes #378)

  • Loading branch information...
jaor committed Feb 7, 2019
1 parent 75d0d5e commit 132c4c459763c81ddf60aeedf5b87b619bb5f1ce
Showing with 6 additions and 47 deletions.
  1. +3 −1 changelog.md
  2. +1 −5 readme.md
  3. +0 −31 src/Xmobar/Plugins/Monitors/Weather.hs
  4. +2 −10 xmobar.cabal
@@ -1,11 +1,13 @@
## Version 0.29.5 (January, 2019)
## Version 0.29.5 (February, 2019)

_Bug fixes_

- Honour command line flags when starting xmobar without any
configuration file (issue #375).
- `Alsa` plugin: restart `alsactl` if it quits, e.g. because of a
sleep/awake cycle (issue #376).
- `Weather` using the new HTTPS URL, which requires http-conduit as
a dependency (issue #378).

## Version 0.29.4 (December, 2018)

@@ -130,15 +130,11 @@ Otherwise, you'll need to install them yourself.
.xpm files in `<icon>`. Requires the [libXpm] C library.

- `with_uvmeter` Enables UVMeter plugin. The plugin shows UV data for
Australia. Requires `with_conduit` to connect to HTTPS URLs.
Australia.

- `with_weather` Support to display weather information. Enables
Weather plugin.

- `with_conduit` Use http-conduit for getting weather data enabling
support for http proxies. Requires [http-conduit] and [http-types].
Note that this flag has only an effect if `with_weather` is also set.

- `all_extensions` Enables all the extensions above.

# Running xmobar
@@ -19,14 +19,10 @@ import Xmobar.Plugins.Monitors.Common

import qualified Control.Exception as CE

#ifdef HTTP_CONDUIT
import Network.HTTP.Conduit
import Network.HTTP.Types.Status
import Network.HTTP.Types.Method
import qualified Data.ByteString.Lazy.Char8 as B
#else
import Network.HTTP
#endif

import Text.ParserCombinators.Parsec

@@ -189,7 +185,6 @@ stationUrl :: String -> String
stationUrl station = defUrl ++ station ++ ".TXT"

getData :: String -> IO String
#ifdef HTTP_CONDUIT
getData station = CE.catch (do
manager <- newManager tlsManagerSettings
request <- parseUrlThrow $ stationUrl station
@@ -198,13 +193,6 @@ getData station = CE.catch (do
) errHandler
where errHandler :: CE.SomeException -> IO String
errHandler _ = return "<Could not retrieve data>"
#else
getData station = do
let request = getRequest (stationUrl station)
CE.catch (simpleHTTP request >>= getResponseBody) errHandler
where errHandler :: CE.IOException -> IO String
errHandler _ = return "<Could not retrieve data>"
#endif

formatWeather :: [WeatherInfo] -> Monitor String
formatWeather [WI st ss y m d h (WindInfo wc wa wm wk wkh wms) v sk tC tF dC dF r p] =
@@ -220,7 +208,6 @@ runWeather str =
formatWeather i

weatherReady :: [String] -> Monitor Bool
#ifdef HTTP_CONDUIT
weatherReady str = do
initRequest <- parseUrlThrow $ stationUrl $ head str
let request = initRequest{method = methodHead}
@@ -234,21 +221,3 @@ weatherReady str = do
| statusIsServerError status = False
| statusIsClientError status = False
| otherwise = True
#else
weatherReady str = do
let station = head str
request = headRequest (stationUrl station)
io $ CE.catch (simpleHTTP request >>= checkResult) errHandler
where errHandler :: CE.IOException -> IO Bool
errHandler _ = return False
checkResult result =
case result of
Left _ -> return False
Right response ->
case rspCode response of
-- Permission or network errors are failures; anything
-- else is recoverable.
(4, _, _) -> return False
(5, _, _) -> return False
(_, _, _) -> return True
#endif
@@ -87,10 +87,6 @@ flag with_weather
description: Enable weather plugin.
default: True

flag with_conduit
description: Use http-conduits for weather data, used only if with_weather.
default: False

library
hs-source-dirs: src

@@ -251,15 +247,11 @@ library
cpp-options: -DXPM

if flag(with_weather) || flag(all_extensions)
build-depends: HTTP >= 4000.2.4
exposed-modules: Xmobar.Plugins.Monitors.Weather
cpp-options: -DWEATHER
if flag(with_conduit)
-- use http-conduit instead of simple-http
build-depends: http-conduit, http-types
cpp-options: -DHTTP_CONDUIT
build-depends: http-conduit, http-types

if flag(with_uvmeter) && flag(with_conduit)
if flag(with_uvmeter)
exposed-modules: Xmobar.Plugins.Monitors.UVMeter
build-depends: http-conduit, http-types
cpp-options: -DUVMETER

0 comments on commit 132c4c4

Please sign in to comment.