disable Turbo on Android to save precious mcode

This is a workaround to fix #1456.
pull/1461/head
chrox 9 years ago
parent a38d851a15
commit d3bb0d159a

@ -17,7 +17,7 @@ function HTTPClient:request(request, response_callback)
request.connect_timeout = 10 request.connect_timeout = 10
request.request_timeout = 20 request.request_timeout = 20
UIManager:initLooper() UIManager:initLooper()
UIManager:handleTask(function() UIManager.looper:add_callback(function()
-- avoid endless waiting for input -- avoid endless waiting for input
UIManager.INPUT_TIMEOUT = self.INPUT_TIMEOUT UIManager.INPUT_TIMEOUT = self.INPUT_TIMEOUT
self.input_timeouts = self.input_timeouts + 1 self.input_timeouts = self.input_timeouts + 1

@ -498,24 +498,14 @@ function UIManager:handleInput()
end end
end end
-- handle next input
self:handleTask(function() self:handleInput() end)
end
-- handle task(callback function) in Turbo I/O looper
-- or run task immediately if looper is not available
function UIManager:handleTask(task)
if self.looper then if self.looper then
DEBUG("handle task in turbo I/O looper") DEBUG("handle input in turbo I/O looper")
self.looper:add_callback(task) self.looper:add_callback(function() self:handleInput() end)
else
DEBUG("run task")
task()
end end
end end
function UIManager:initLooper() function UIManager:initLooper()
if not self.looper then if not self.looper and not Device.isAndroid() and ffi.os ~= "Windows" then
TURBO_SSL = true TURBO_SSL = true
local turbo = require("turbo") local turbo = require("turbo")
self.looper = turbo.ioloop.instance() self.looper = turbo.ioloop.instance()
@ -527,11 +517,15 @@ end
-- them to dialogs -- them to dialogs
function UIManager:run() function UIManager:run()
self._running = true self._running = true
if ffi.os == "Windows" then self:initLooper()
self:handleInput() -- currently there is no Turbo support for Android and Windows
-- use our own main loop
if not self.looper then
while self._running do
self:handleInput()
end
else else
self:initLooper() self.looper:add_callback(function() self:handleInput() end)
self:handleTask(function() self:handleInput() end)
self.looper:start() self.looper:start()
end end
end end

@ -25,13 +25,13 @@ function KOSyncClient:init()
req.headers['x-auth-user'] = args.username req.headers['x-auth-user'] = args.username
req.headers['x-auth-key'] = args.userkey req.headers['x-auth-key'] = args.userkey
end end
local HTTPClient = require("httpclient")
local async_http_client = HTTPClient:new()
package.loaded['Spore.Middleware.AsyncHTTP'] = {} package.loaded['Spore.Middleware.AsyncHTTP'] = {}
require('Spore.Middleware.AsyncHTTP').call = function(args, req) require('Spore.Middleware.AsyncHTTP').call = function(args, req)
-- disable async http if Turbo looper is missing
if not UIManager.looper then return end
req:finalize() req:finalize()
local result local result
async_http_client:request({ require("httpclient"):new():request({
url = req.url, url = req.url,
method = req.method, method = req.method,
body = req.env.spore.payload, body = req.env.spore.payload,
@ -47,8 +47,6 @@ function KOSyncClient:init()
-- Turbo HTTP client uses code instead of status -- Turbo HTTP client uses code instead of status
-- change to status so that Spore can understand -- change to status so that Spore can understand
result.status = res.code result.status = res.code
-- fallback to sync http request
if result.error then result = nil end
coroutine.resume(args.thread) coroutine.resume(args.thread)
end) end)
return coroutine.create(function() coroutine.yield(result) end) return coroutine.create(function() coroutine.yield(result) end)
@ -119,7 +117,7 @@ function KOSyncClient:update_progress(username, password,
end) end)
self.client:enable("AsyncHTTP", {thread = co}) self.client:enable("AsyncHTTP", {thread = co})
coroutine.resume(co) coroutine.resume(co)
UIManager.INPUT_TIMEOUT = 100 if UIManager.looper then UIManager.INPUT_TIMEOUT = 100 end
end end
function KOSyncClient:get_progress(username, password, function KOSyncClient:get_progress(username, password,
@ -146,7 +144,7 @@ function KOSyncClient:get_progress(username, password,
end) end)
self.client:enable("AsyncHTTP", {thread = co}) self.client:enable("AsyncHTTP", {thread = co})
coroutine.resume(co) coroutine.resume(co)
UIManager.INPUT_TIMEOUT = 100 if UIManager.looper then UIManager.INPUT_TIMEOUT = 100 end
end end
return KOSyncClient return KOSyncClient

Loading…
Cancel
Save