2018-03-25 16:46:03 +00:00
|
|
|
require "love.timer"
|
|
|
|
import thread, timer from love
|
|
|
|
|
|
|
|
http = require "socket.http"
|
|
|
|
receive = thread.getChannel "send-itchy"
|
|
|
|
send = thread.getChannel "receive-itchy"
|
|
|
|
|
2018-03-25 20:43:34 +00:00
|
|
|
check = (data) ->
|
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
|
|
|
|
result.body, result.status = http.request "#{data.proxy}/get/https://itch.io/api/1/x/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
|
|
|
|
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
|
|
|
|
|
|
|
start = ->
|
|
|
|
-- data should be a table of information
|
|
|
|
data = receive\demand!
|
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
|
|
|
|
|
|
|
|
-- if we are sent new data, start over entirely
|
|
|
|
if receive\getCount! > 0
|
|
|
|
return start!
|
2018-03-25 20:43:34 +00:00
|
|
|
else
|
|
|
|
check data
|
2018-03-25 16:46:03 +00:00
|
|
|
|
|
|
|
start!
|