From 7c998cc6a54aeafbad19f66e552980409784342e Mon Sep 17 00:00:00 2001 From: boatbomber Date: Tue, 5 Nov 2024 14:37:54 -0800 Subject: [PATCH 1/2] Make sync reminder more detailed --- plugin/src/App/init.lua | 116 ++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 64 deletions(-) diff --git a/plugin/src/App/init.lua b/plugin/src/App/init.lua index e3f98725e..df1bccacb 100644 --- a/plugin/src/App/init.lua +++ b/plugin/src/App/init.lua @@ -52,9 +52,9 @@ local App = Roact.Component:extend("App") function App:init() preloadAssets() - local priorHost, priorPort = self:getPriorEndpoint() - self.host, self.setHost = Roact.createBinding(priorHost or "") - self.port, self.setPort = Roact.createBinding(priorPort or "") + local priorSyncInfo = self:getPriorSyncInfo() + self.host, self.setHost = Roact.createBinding(priorSyncInfo.host or "") + self.port, self.setPort = Roact.createBinding(priorSyncInfo.port or "") self.confirmationBindable = Instance.new("BindableEvent") self.confirmationEvent = self.confirmationBindable.Event @@ -145,28 +145,38 @@ function App:init() if Settings:get("syncReminder") and self.serveSession == nil - and self:getLastSyncTimestamp() + and self:getPriorSyncInfo().timestamp ~= nil and (self:isSyncLockAvailable()) then - self:addNotification("You've previously synced this place. Would you like to reconnect?", 300, { - Connect = { - text = "Connect", - style = "Solid", - layoutOrder = 1, - onClick = function(notification) - notification:dismiss() - self:startSession() - end, - }, - Dismiss = { - text = "Dismiss", - style = "Bordered", - layoutOrder = 2, - onClick = function(notification) - notification:dismiss() - end, - }, - }) + local syncInfo = self:getPriorSyncInfo() + local timeSinceSync = timeUtil.elapsedToText(os.time() - syncInfo.timestamp) + local syncDetail = if syncInfo.projectName + then `project '{syncInfo.projectName}'` + else `{syncInfo.host or Config.defaultHost}:{syncInfo.port or Config.defaultPort}` + + self:addNotification( + `You synced {syncDetail} to this place {timeSinceSync}. Would you like to reconnect?`, + 300, + { + Connect = { + text = "Connect", + style = "Solid", + layoutOrder = 1, + onClick = function(notification) + notification:dismiss() + self:startSession() + end, + }, + Dismiss = { + text = "Dismiss", + style = "Bordered", + layoutOrder = 2, + onClick = function(notification) + notification:dismiss() + end, + }, + } + ) end end @@ -274,54 +284,32 @@ function App:checkForUpdates() ) end -function App:getPriorEndpoint() - local priorEndpoints = Settings:get("priorEndpoints") - if not priorEndpoints then - return +function App:getPriorSyncInfo(): { host: string?, port: string?, projectName: string?, timestamp: number? } + local priorSyncInfos = Settings:get("priorEndpoints") + if not priorSyncInfos then + return {} end local id = tostring(game.PlaceId) if ignorePlaceIds[id] then - return - end - - local place = priorEndpoints[id] - if not place then - return + return {} end - return place.host, place.port + return priorSyncInfos[id] or {} end -function App:getLastSyncTimestamp() - local priorEndpoints = Settings:get("priorEndpoints") - if not priorEndpoints then - return +function App:setPriorSyncInfo(host: string, port: string, projectName: string) + local priorSyncInfos = Settings:get("priorEndpoints") + if not priorSyncInfos then + priorSyncInfos = {} end - local id = tostring(game.PlaceId) - if ignorePlaceIds[id] then - return - end - - local place = priorEndpoints[id] - if not place then - return - end - - return place.timestamp -end - -function App:setPriorEndpoint(host: string, port: string) - local priorEndpoints = Settings:get("priorEndpoints") - if not priorEndpoints then - priorEndpoints = {} - end + local now = os.time() -- 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 + for placeId, syncInfo in priorSyncInfos do + if now - (syncInfo.timestamp or now) > 12_960_000 then + priorSyncInfos[placeId] = nil Log.trace("Cleared stale saved endpoint for {}", placeId) end end @@ -331,14 +319,15 @@ function App:setPriorEndpoint(host: string, port: string) return end - priorEndpoints[id] = { + priorSyncInfos[id] = { host = if host ~= Config.defaultHost then host else nil, port = if port ~= Config.defaultPort then port else nil, - timestamp = os.time(), + projectName = projectName, + timestamp = now, } Log.trace("Saved last used endpoint for {}", game.PlaceId) - Settings:set("priorEndpoints", priorEndpoints) + Settings:set("priorEndpoints", priorSyncInfos) end function App:getHostAndPort() @@ -533,8 +522,6 @@ function App:startSession() serveSession:onStatusChanged(function(status, details) if status == ServeSession.Status.Connecting then - self:setPriorEndpoint(host, port) - self:setState({ appStatus = AppStatus.Connecting, toolbarIcon = Assets.Images.PluginButton, @@ -542,6 +529,7 @@ function App:startSession() self:addNotification("Connecting to session...") elseif status == ServeSession.Status.Connected then self.knownProjects[details] = true + self:setPriorSyncInfo(host, port, details) self:setRunningConnectionInfo(baseUrl) local address = ("%s:%s"):format(host, port) From de3b25a813239a97a8c82393ea45963e9fc8c18e Mon Sep 17 00:00:00 2001 From: boatbomber Date: Tue, 5 Nov 2024 14:45:50 -0800 Subject: [PATCH 2/2] Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 621a8ae6c..fbc01f684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ * Added experimental setting for Auto Connect in playtests ([#840]) * Improved settings UI ([#886]) * `Open Scripts Externally` option can now be changed while syncing ([#911]) +* The sync reminder notification will now tell you what was last synced and when ([#987]) * Projects may now specify rules for syncing files as if they had a different file extension. ([#813]) This is specified via a new field on project files, `syncRules`: @@ -87,6 +88,7 @@ [#911]: https://github.com/rojo-rbx/rojo/pull/911 [#915]: https://github.com/rojo-rbx/rojo/pull/915 [#974]: https://github.com/rojo-rbx/rojo/pull/974 +[#987]: https://github.com/rojo-rbx/rojo/pull/987 ## [7.4.3] - August 6th, 2024 * Fixed issue with building binary files introduced in 7.4.2