From 59ce0053ac15f862e9571034cac28fd1063bef0e Mon Sep 17 00:00:00 2001 From: Aurélien LAJOIE Date: Wed, 18 Sep 2019 01:27:22 +0200 Subject: Catch error is the answer is not a valid json string This was triggered by a public wifi pushing an html file to all request --- weather-widget/weather.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index b0aa070..09eeeec 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -142,6 +142,15 @@ local function worker(args) return s end + local function error_display(resp_json) + local err_resp = json.decode(resp_json) + naughty.notify{ + title = 'Weather Widget Error', + text = err_resp.message, + preset = naughty.config.presets.critical, + } + end + weather_timer:connect_signal("timeout", function () local resp_json = {} local res, status = http.request{ @@ -164,12 +173,13 @@ local function worker(args) end if (status ~= 200 and resp_json ~= nil and resp_json ~= '') then - local err_resp = json.decode(resp_json) - naughty.notify{ - title = 'Weather Widget Error', - text = err_resp.message, - preset = naughty.config.presets.critical, - } + if (not pcall(error_display, resp_json)) then + naughty.notify{ + title = 'Weather Widget Error', + text = 'Cannot parse answer', + preset = naughty.config.presets.critical, + } + end elseif (resp_json ~= nil and resp_json ~= '') then resp = json.decode(resp_json) icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon] -- cgit v1.2.3 From e154daa8b67b0e10b9615ef68852fab1f8ec29bb Mon Sep 17 00:00:00 2001 From: Aurélien LAJOIE Date: Wed, 18 Sep 2019 01:31:26 +0200 Subject: [Weather] Add option to set the position of the notification --- weather-widget/README.md | 2 ++ weather-widget/weather.lua | 2 ++ 2 files changed, 4 insertions(+) diff --git a/weather-widget/README.md b/weather-widget/README.md index 6464fcc..730c1f5 100644 --- a/weather-widget/README.md +++ b/weather-widget/README.md @@ -16,6 +16,8 @@ It is possible to customize widget by providing a table with all or some of the | `units` | `metric` | `metric` for celsius, `imperial` for fahrenheit | | `both_units_widget` | `false` | show temperature in both units (15°C (59°F)) or in one (15°C) | | `both_units_popup` | `false` | same as above but for popup | +| `notification_position` | `top_right` | The notification position | + ### Example: diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index 09eeeec..9befd6b 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -28,6 +28,7 @@ local function worker(args) local units = args.units or 'metric' local both_units_widget = args.both_units_widget or false local both_units_popup = args.both_units_popup or false + local position = args.notification_position or "top_right" local weather_api_url = ( 'https://api.openweathermap.org/data/2.5/weather' @@ -204,6 +205,7 @@ local function worker(args) 'Clouds: ' .. resp.clouds.all .. '%
' .. 'Wind: ' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')', timeout = 5, hover_timeout = 10, + position = position, width = (both_units_popup == true and 210 or 200) } end) -- cgit v1.2.3