mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Save host and port by placeId (#613)
* Save host and port by placeId * Bump to 5 months before clearing * Fix indentation
This commit is contained in:
@@ -44,8 +44,10 @@ local App = Roact.Component:extend("App")
|
|||||||
function App:init()
|
function App:init()
|
||||||
preloadAssets()
|
preloadAssets()
|
||||||
|
|
||||||
self.host, self.setHost = Roact.createBinding("")
|
local priorHost, priorPort = self:getPriorEndpoint()
|
||||||
self.port, self.setPort = Roact.createBinding("")
|
self.host, self.setHost = Roact.createBinding(priorHost or "")
|
||||||
|
self.port, self.setPort = Roact.createBinding(priorPort or "")
|
||||||
|
|
||||||
self.patchInfo, self.setPatchInfo = Roact.createBinding({
|
self.patchInfo, self.setPatchInfo = Roact.createBinding({
|
||||||
changes = 0,
|
changes = 0,
|
||||||
timestamp = os.time(),
|
timestamp = os.time(),
|
||||||
@@ -85,6 +87,45 @@ function App:closeNotification(index: number)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function App:getPriorEndpoint()
|
||||||
|
local priorEndpoints = Settings:get("priorEndpoints")
|
||||||
|
if not priorEndpoints then return end
|
||||||
|
|
||||||
|
local place = priorEndpoints[tostring(game.PlaceId)]
|
||||||
|
if not place then return end
|
||||||
|
|
||||||
|
return place.host, place.port
|
||||||
|
end
|
||||||
|
|
||||||
|
function App:setPriorEndpoint(host: string, port: string)
|
||||||
|
local priorEndpoints = Settings:get("priorEndpoints")
|
||||||
|
if not priorEndpoints then
|
||||||
|
priorEndpoints = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clear any stale saves to avoid disc bloat
|
||||||
|
for placeId, endpoint in priorEndpoints do
|
||||||
|
if os.time() - endpoint.timestamp > 12_960_000 then
|
||||||
|
priorEndpoints[placeId] = nil
|
||||||
|
Log.trace("Cleared stale saved endpoint for {}", placeId)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if host == Config.defaultHost and port == Config.defaultPort then
|
||||||
|
-- Don't save default
|
||||||
|
priorEndpoints[tostring(game.PlaceId)] = nil
|
||||||
|
else
|
||||||
|
priorEndpoints[tostring(game.PlaceId)] = {
|
||||||
|
host = host ~= Config.defaultHost and host or nil,
|
||||||
|
port = port ~= Config.defaultPort and port or nil,
|
||||||
|
timestamp = os.time(),
|
||||||
|
}
|
||||||
|
Log.trace("Saved last used endpoint for {}", game.PlaceId)
|
||||||
|
end
|
||||||
|
|
||||||
|
Settings:set("priorEndpoints", priorEndpoints)
|
||||||
|
end
|
||||||
|
|
||||||
function App:getHostAndPort()
|
function App:getHostAndPort()
|
||||||
local host = self.host:getValue()
|
local host = self.host:getValue()
|
||||||
local port = self.port:getValue()
|
local port = self.port:getValue()
|
||||||
@@ -200,6 +241,8 @@ function App:startSession()
|
|||||||
|
|
||||||
serveSession:onStatusChanged(function(status, details)
|
serveSession:onStatusChanged(function(status, details)
|
||||||
if status == ServeSession.Status.Connecting then
|
if status == ServeSession.Status.Connecting then
|
||||||
|
self:setPriorEndpoint(host, port)
|
||||||
|
|
||||||
self:setState({
|
self:setState({
|
||||||
appStatus = AppStatus.Connecting,
|
appStatus = AppStatus.Connecting,
|
||||||
toolbarIcon = Assets.Images.PluginButton,
|
toolbarIcon = Assets.Images.PluginButton,
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ return strict("Config", {
|
|||||||
expectedServerVersionString = "7.2 or newer",
|
expectedServerVersionString = "7.2 or newer",
|
||||||
protocolVersion = 4,
|
protocolVersion = 4,
|
||||||
defaultHost = "localhost",
|
defaultHost = "localhost",
|
||||||
defaultPort = 34872,
|
defaultPort = "34872",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ local defaultSettings = {
|
|||||||
playSounds = true,
|
playSounds = true,
|
||||||
typecheckingEnabled = false,
|
typecheckingEnabled = false,
|
||||||
logLevel = "Info",
|
logLevel = "Info",
|
||||||
|
priorEndpoints = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
local Settings = {}
|
local Settings = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user