mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-26 07:36:19 +00:00
Improve plugin API robustness
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Current master
|
## Current master
|
||||||
* Fixed obscure error when syncing into an invalid service
|
* Fixed obscure error when syncing into an invalid service
|
||||||
|
* Fixed multiple sync processes occurring when a server ID mismatch is detected
|
||||||
|
|
||||||
## 0.4.9 (May 26, 2018)
|
## 0.4.9 (May 26, 2018)
|
||||||
* Fixed warning when renaming or removing files that would sometimes corrupt the instance cache ([#72](https://github.com/LPGhatguy/rojo/pull/72))
|
* Fixed warning when renaming or removing files that would sometimes corrupt the instance cache ([#72](https://github.com/LPGhatguy/rojo/pull/72))
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ function Api.connect(http)
|
|||||||
setmetatable(context, Api)
|
setmetatable(context, Api)
|
||||||
|
|
||||||
return context:_start()
|
return context:_start()
|
||||||
|
:andThen(function()
|
||||||
|
return context
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Api:_start()
|
function Api:_start()
|
||||||
@@ -60,8 +63,6 @@ function Api:_start()
|
|||||||
|
|
||||||
self.serverId = response.serverId
|
self.serverId = response.serverId
|
||||||
self.currentTime = response.currentTime
|
self.currentTime = response.currentTime
|
||||||
|
|
||||||
return self
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ local Api = require(script.Parent.Api)
|
|||||||
local Reconciler = require(script.Parent.Reconciler)
|
local Reconciler = require(script.Parent.Reconciler)
|
||||||
local Version = require(script.Parent.Version)
|
local Version = require(script.Parent.Version)
|
||||||
|
|
||||||
|
local MESSAGE_SERVER_CHANGED = "Rojo: The server has changed since the last request, reloading plugin..."
|
||||||
|
local MESSAGE_PLUGIN_CHANGED = "Rojo: Another instance of Rojo came online, unloading..."
|
||||||
|
|
||||||
local function collectMatch(source, pattern)
|
local function collectMatch(source, pattern)
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
@@ -80,6 +83,7 @@ function Plugin.new()
|
|||||||
-- object.
|
-- object.
|
||||||
screenGui.AncestryChanged:Connect(function(_, parent)
|
screenGui.AncestryChanged:Connect(function(_, parent)
|
||||||
if parent == nil then
|
if parent == nil then
|
||||||
|
warn(MESSAGE_PLUGIN_CHANGED)
|
||||||
self:restart()
|
self:restart()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -93,8 +97,6 @@ end
|
|||||||
restarted.
|
restarted.
|
||||||
]]
|
]]
|
||||||
function Plugin:restart()
|
function Plugin:restart()
|
||||||
warn("Rojo: The server has changed since the last request, reloading plugin...")
|
|
||||||
|
|
||||||
self:stopPolling()
|
self:stopPolling()
|
||||||
|
|
||||||
self._reconciler:destruct()
|
self._reconciler:destruct()
|
||||||
@@ -105,22 +107,25 @@ function Plugin:restart()
|
|||||||
self._syncInProgress = false
|
self._syncInProgress = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Plugin:api()
|
function Plugin:getApi()
|
||||||
if not self._api then
|
if self._api == nil then
|
||||||
self._api = Api.connect(self._http)
|
return Api.connect(self._http)
|
||||||
:catch(function(err)
|
:andThen(function(api)
|
||||||
self._api = nil
|
self._api = api
|
||||||
|
|
||||||
|
return api
|
||||||
|
end, function(err)
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self._api
|
return Promise.resolve(self._api)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Plugin:connect()
|
function Plugin:connect()
|
||||||
print("Rojo: Testing connection...")
|
print("Rojo: Testing connection...")
|
||||||
|
|
||||||
return self:api()
|
return self:getApi()
|
||||||
:andThen(function(api)
|
:andThen(function(api)
|
||||||
local ok, info = api:getInfo():await()
|
local ok, info = api:getInfo():await()
|
||||||
|
|
||||||
@@ -134,6 +139,7 @@ function Plugin:connect()
|
|||||||
end)
|
end)
|
||||||
:catch(function(err)
|
:catch(function(err)
|
||||||
if err == Api.Error.ServerIdMismatch then
|
if err == Api.Error.ServerIdMismatch then
|
||||||
|
warn(MESSAGE_SERVER_CHANGED)
|
||||||
self:restart()
|
self:restart()
|
||||||
return self:connect()
|
return self:connect()
|
||||||
else
|
else
|
||||||
@@ -204,25 +210,25 @@ function Plugin:startPolling()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Rojo: Polling server for changes...")
|
print("Rojo: Starting to poll server for changes...")
|
||||||
|
|
||||||
self._polling = true
|
self._polling = true
|
||||||
self._label.Enabled = true
|
self._label.Enabled = true
|
||||||
|
|
||||||
return self:api()
|
return self:getApi()
|
||||||
:andThen(function(api)
|
:andThen(function(api)
|
||||||
local syncOk, result = self:syncIn():await()
|
|
||||||
|
|
||||||
if not syncOk then
|
|
||||||
return Promise.reject(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
local infoOk, info = api:getInfo():await()
|
local infoOk, info = api:getInfo():await()
|
||||||
|
|
||||||
if not infoOk then
|
if not infoOk then
|
||||||
return Promise.reject(info)
|
return Promise.reject(info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local syncOk, result = self:syncIn():await()
|
||||||
|
|
||||||
|
if not syncOk then
|
||||||
|
return Promise.reject(result)
|
||||||
|
end
|
||||||
|
|
||||||
while self._polling do
|
while self._polling do
|
||||||
local changesOk, changes = api:getChanges():await()
|
local changesOk, changes = api:getChanges():await()
|
||||||
|
|
||||||
@@ -248,12 +254,12 @@ function Plugin:startPolling()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
:catch(function(err)
|
:catch(function(err)
|
||||||
self:stopPolling()
|
|
||||||
|
|
||||||
if err == Api.Error.ServerIdMismatch then
|
if err == Api.Error.ServerIdMismatch then
|
||||||
|
warn(MESSAGE_SERVER_CHANGED)
|
||||||
self:restart()
|
self:restart()
|
||||||
return self:startPolling()
|
return self:startPolling()
|
||||||
else
|
else
|
||||||
|
self:stopPolling()
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -269,7 +275,7 @@ function Plugin:syncIn()
|
|||||||
self._syncInProgress = true
|
self._syncInProgress = true
|
||||||
print("Rojo: Syncing from server...")
|
print("Rojo: Syncing from server...")
|
||||||
|
|
||||||
return self:api()
|
return self:getApi()
|
||||||
:andThen(function(api)
|
:andThen(function(api)
|
||||||
local ok, info = api:getInfo():await()
|
local ok, info = api:getInfo():await()
|
||||||
|
|
||||||
@@ -292,6 +298,7 @@ function Plugin:syncIn()
|
|||||||
self._syncInProgress = false
|
self._syncInProgress = false
|
||||||
|
|
||||||
if err == Api.Error.ServerIdMismatch then
|
if err == Api.Error.ServerIdMismatch then
|
||||||
|
warn(MESSAGE_SERVER_CHANGED)
|
||||||
self:restart()
|
self:restart()
|
||||||
return self:syncIn()
|
return self:syncIn()
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user