2018-03-25 16:46:03 +00:00
|
|
|
require "love.timer"
|
|
|
|
import thread, timer from love
|
|
|
|
|
|
|
|
http = require "socket.http"
|
|
|
|
|
2018-03-25 20:43:34 +00:00
|
|
|
check = (data) ->
|
2018-04-13 05:42:54 +00:00
|
|
|
send = thread.getChannel data.thread_channel or "itchy"
|
|
|
|
|
2018-03-25 16:46:03 +00:00
|
|
|
exponential_backoff = 1
|
|
|
|
while true
|
2018-03-25 20:43:34 +00:00
|
|
|
result = {}
|
2018-03-25 16:46:03 +00:00
|
|
|
if data.url
|
2018-03-25 20:43:34 +00:00
|
|
|
result.body, result.status = http.request data.url
|
2018-03-25 16:46:03 +00:00
|
|
|
elseif data.proxy
|
2018-03-25 20:43:34 +00:00
|
|
|
unless data.target
|
|
|
|
result.message = "'target' or 'url' must be defined!"
|
|
|
|
send\push result
|
|
|
|
return false
|
2018-05-25 21:14:21 +00:00
|
|
|
result.body, result.status = http.request "#{data.proxy}/get/https://api.itch.io/wharf/latest?target=#{data.target}&channel_name=#{data.channel}"
|
2018-03-25 16:46:03 +00:00
|
|
|
|
2018-03-25 20:43:34 +00:00
|
|
|
unless result.body
|
2018-03-25 20:47:39 +00:00
|
|
|
result.message = "socket.http.request error: #{result.status}"
|
2018-03-25 20:43:34 +00:00
|
|
|
send\push result
|
|
|
|
return false
|
|
|
|
|
|
|
|
result.version = result.body\match '%s*{%s*"latest"%s*:%s*"(.+)"%s*}%s*'
|
|
|
|
result.version = tonumber(result.version) or result.version
|
|
|
|
result.latest = if data.version
|
|
|
|
result.version == data.version
|
|
|
|
|
2018-03-25 20:47:39 +00:00
|
|
|
if result.status != 200 and (not result.version)
|
|
|
|
result.message = "unknown, error getting latest version: HTTP #{result.status}, trying again in #{exponential_backoff} seconds"
|
2018-03-25 20:43:34 +00:00
|
|
|
send\push result
|
2018-03-25 16:46:03 +00:00
|
|
|
timer.sleep exponential_backoff
|
2018-03-25 20:43:34 +00:00
|
|
|
exponential_backoff *= 2
|
2018-04-13 05:42:54 +00:00
|
|
|
exponential_backoff = 10 * 60 if exponential_backoff > 10 * 60 -- maximum backoff is 10 minutes
|
2018-03-25 20:43:34 +00:00
|
|
|
continue
|
2018-03-25 20:51:59 +00:00
|
|
|
elseif result.latest != nil
|
|
|
|
if result.latest
|
2018-03-25 20:43:34 +00:00
|
|
|
result.message = "#{result.version}, you have the latest version"
|
|
|
|
else
|
|
|
|
result.message = "#{result.version}, there is a newer version available!"
|
|
|
|
else
|
|
|
|
result.message = result.version
|
|
|
|
|
|
|
|
send\push result
|
|
|
|
return true
|
2018-03-25 16:46:03 +00:00
|
|
|
|
2018-04-13 05:42:54 +00:00
|
|
|
-- data should be a table of information
|
|
|
|
start = (data) ->
|
2018-03-26 08:04:47 +00:00
|
|
|
data.proxy = "http://45.55.113.149:16343" unless data.proxy or data.url
|
2018-03-25 16:46:03 +00:00
|
|
|
|
|
|
|
-- channel can be autodetected if not specified
|
|
|
|
unless data.channel
|
|
|
|
require "love.system"
|
|
|
|
os = love.system.getOS!
|
|
|
|
switch os
|
|
|
|
when "OS X"
|
|
|
|
data.channel = "osx"
|
|
|
|
when "Windows"
|
|
|
|
data.channel = "win32"
|
|
|
|
when "Linux"
|
|
|
|
data.channel = "linux"
|
|
|
|
when "Android"
|
|
|
|
data.channel = "android"
|
|
|
|
when "iOS"
|
|
|
|
data.channel = "ios"
|
|
|
|
else
|
|
|
|
data.channel = os
|
|
|
|
|
|
|
|
check data
|
|
|
|
|
|
|
|
-- if we should check again every x seconds, wait, and do so
|
|
|
|
if data.interval
|
|
|
|
while true
|
|
|
|
timer.sleep data.interval
|
2018-04-13 05:42:54 +00:00
|
|
|
check data
|
2018-03-25 16:46:03 +00:00
|
|
|
|
2018-04-13 05:42:54 +00:00
|
|
|
start(...)
|