2018-03-25 16:46:03 +00:00
|
|
|
require("love.timer")
|
|
|
|
local thread, timer
|
|
|
|
do
|
|
|
|
local _obj_0 = love
|
|
|
|
thread, timer = _obj_0.thread, _obj_0.timer
|
|
|
|
end
|
|
|
|
local http = require("socket.http")
|
|
|
|
local check
|
2018-03-25 20:43:34 +00:00
|
|
|
check = function(data)
|
2018-04-13 05:42:54 +00:00
|
|
|
local send = thread.getChannel(data.thread_channel or "itchy")
|
2018-03-25 16:46:03 +00:00
|
|
|
local exponential_backoff = 1
|
|
|
|
while true do
|
2018-03-25 20:43:34 +00:00
|
|
|
local _continue_0 = false
|
|
|
|
repeat
|
|
|
|
do
|
|
|
|
local result = { }
|
|
|
|
if data.url then
|
|
|
|
result.body, result.status = http.request(data.url)
|
|
|
|
elseif data.proxy then
|
|
|
|
if not (data.target) then
|
|
|
|
result.message = "'target' or 'url' must be defined!"
|
|
|
|
send:push(result)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
result.body, result.status = http.request(tostring(data.proxy) .. "/get/https://itch.io/api/1/x/wharf/latest?target=" .. tostring(data.target) .. "&channel_name=" .. tostring(data.channel))
|
|
|
|
end
|
|
|
|
if not (result.body) then
|
2018-03-25 20:51:59 +00:00
|
|
|
result.message = "socket.http.request error: " .. tostring(result.status)
|
2018-03-25 20:43:34 +00:00
|
|
|
send:push(result)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
result.version = result.body:match('%s*{%s*"latest"%s*:%s*"(.+)"%s*}%s*')
|
|
|
|
result.version = tonumber(result.version) or result.version
|
|
|
|
if data.version then
|
|
|
|
result.latest = result.version == data.version
|
|
|
|
end
|
2018-03-25 20:51:59 +00:00
|
|
|
if result.status ~= 200 and (not result.version) then
|
|
|
|
result.message = "unknown, error getting latest version: HTTP " .. tostring(result.status) .. ", trying again in " .. tostring(exponential_backoff) .. " seconds"
|
2018-03-25 20:43:34 +00:00
|
|
|
send:push(result)
|
|
|
|
timer.sleep(exponential_backoff)
|
|
|
|
exponential_backoff = exponential_backoff * 2
|
2018-04-13 05:42:54 +00:00
|
|
|
if exponential_backoff > 10 * 60 then
|
|
|
|
exponential_backoff = 10 * 60
|
|
|
|
end
|
2018-03-25 20:43:34 +00:00
|
|
|
_continue_0 = true
|
|
|
|
break
|
2018-03-25 20:51:59 +00:00
|
|
|
elseif result.latest ~= nil then
|
|
|
|
if result.latest then
|
2018-03-25 20:43:34 +00:00
|
|
|
result.message = tostring(result.version) .. ", you have the latest version"
|
|
|
|
else
|
|
|
|
result.message = tostring(result.version) .. ", there is a newer version available!"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
result.message = result.version
|
|
|
|
end
|
|
|
|
send:push(result)
|
|
|
|
return true
|
2018-03-25 16:46:03 +00:00
|
|
|
end
|
2018-03-25 20:43:34 +00:00
|
|
|
_continue_0 = true
|
|
|
|
until true
|
|
|
|
if not _continue_0 then
|
|
|
|
break
|
2018-03-25 16:46:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local start
|
2018-04-13 05:42:54 +00:00
|
|
|
start = function(data)
|
2018-03-25 16:46:03 +00:00
|
|
|
if not (data.proxy or data.url) then
|
2018-03-26 08:04:47 +00:00
|
|
|
data.proxy = "http://45.55.113.149:16343"
|
2018-03-25 16:46:03 +00:00
|
|
|
end
|
|
|
|
if not (data.channel) then
|
|
|
|
require("love.system")
|
|
|
|
local os = love.system.getOS()
|
|
|
|
local _exp_0 = os
|
|
|
|
if "OS X" == _exp_0 then
|
|
|
|
data.channel = "osx"
|
|
|
|
elseif "Windows" == _exp_0 then
|
|
|
|
data.channel = "win32"
|
|
|
|
elseif "Linux" == _exp_0 then
|
|
|
|
data.channel = "linux"
|
|
|
|
elseif "Android" == _exp_0 then
|
|
|
|
data.channel = "android"
|
|
|
|
elseif "iOS" == _exp_0 then
|
|
|
|
data.channel = "ios"
|
|
|
|
else
|
|
|
|
data.channel = os
|
|
|
|
end
|
|
|
|
end
|
|
|
|
check(data)
|
|
|
|
if data.interval then
|
|
|
|
while true do
|
|
|
|
timer.sleep(data.interval)
|
2018-04-13 05:42:54 +00:00
|
|
|
check(data)
|
2018-03-25 16:46:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-13 05:42:54 +00:00
|
|
|
return start(...)
|