optimize booleans for Weather.lua

This commit is contained in:
petrucci4prez 2017-07-18 00:04:59 -04:00
parent 1a0c875477
commit 24cca22845
3 changed files with 20 additions and 22 deletions

View File

@ -152,20 +152,6 @@ end
__os_execute('set_conky_interface.sh 0') __os_execute('set_conky_interface.sh 0')
local current_interface = 0 local current_interface = 0
local check_interface = function()
local next_interface = util.read_file('/tmp/conky_interface', nil, '*n')
if next_interface ~= '' then
if next_interface == current_interface then return 1 end
current_interface = next_interface
return 0
else
__os_execute('set_conky_interface.sh 0')
current_interface = 0
return 0
end
end
function conky_main() function conky_main()
local _cw = conky_window local _cw = conky_window
if not _cw then return end if not _cw then return end
@ -186,7 +172,19 @@ function conky_main()
local log_is_changed = false local log_is_changed = false
if t2 == 0 then log_is_changed = check_if_log_changed() end if t2 == 0 then log_is_changed = check_if_log_changed() end
local interface_changed = check_interface()
local interface_is_changed = false
local next_interface = util.read_file('/tmp/conky_interface', nil, '*n')
if next_interface == '' then
__os_execute('set_conky_interface.sh 0')
current_interface = 0
interface_is_changed = true
elseif next_interface ~= current_interface then
current_interface = next_interface
interface_is_changed = true
end
Panel(cr) Panel(cr)
@ -204,7 +202,7 @@ function conky_main()
Memory(cr, current_interface) Memory(cr, current_interface)
--interface 1 --interface 1
Weather(cr, current_interface, interface_changed) Weather(cr, current_interface, interface_is_changed)
__cairo_surface_destroy(cs) __cairo_surface_destroy(cs)
__cairo_destroy(cr) __cairo_destroy(cr)

View File

@ -438,17 +438,17 @@ __os_execute('get_weather.sh')
local update_cycle = WEATHER_UPDATE_INTERVAL local update_cycle = WEATHER_UPDATE_INTERVAL
local draw = function(cr, interface, trigger) local draw = function(cr, interface, interface_is_changed)
if update_cycle == 0 then __os_execute('get_weather.sh') end if update_cycle == 0 then __os_execute('get_weather.sh') end
local recently_updated = util.read_file(RECENTLY_UPDATED_PATH, nil, '*n') local json_is_recently_updated = (util.read_file(RECENTLY_UPDATED_PATH, nil, '*l') == 'true')
if recently_updated == 1 then if json_is_recently_updated then
update_cycle = WEATHER_UPDATE_INTERVAL update_cycle = WEATHER_UPDATE_INTERVAL
util.write_file(RECENTLY_UPDATED_PATH, 0) util.write_file(RECENTLY_UPDATED_PATH, 'false')
end end
if recently_updated == 1 or trigger == 0 then update_interface(cr) end if json_is_recently_updated or interface_is_changed then update_interface(cr) end
update_cycle = update_cycle - 1 update_cycle = update_cycle - 1

View File

@ -62,4 +62,4 @@ id="client_id=TdJ5M1pUXWUUebhfRKSs2"
secret="client_secret=DmI2NHCO6BQ5hSH4yAECVJlgA8gYZ1C4BvNaGEuM" secret="client_secret=DmI2NHCO6BQ5hSH4yAECVJlgA8gYZ1C4BvNaGEuM"
curl -s "$weather_url$location_string?requests=$observations,$hourly,$daily&$id&$secret" > /tmp/weather.json && \ curl -s "$weather_url$location_string?requests=$observations,$hourly,$daily&$id&$secret" > /tmp/weather.json && \
echo 1 > /tmp/weather_recently_updated & echo true > /tmp/weather_recently_updated &