From 2a46df111092817d044f8929c407042d11e22fdb Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 18 Mar 2020 10:39:40 -0700 Subject: [PATCH] Expose two-way sync. - Convert plugin DevSettings flag to settings panel feature - Remove server feature, always enable write API --- Cargo.toml | 3 -- plugin/src/Components/App.lua | 1 + plugin/src/Components/ConnectPanel.lua | 1 + plugin/src/Components/PluginSettings.lua | 1 + plugin/src/Components/SettingsPanel.lua | 44 ++++++++++++++++++++++-- plugin/src/DevSettings.lua | 12 ------- plugin/src/ServeSession.lua | 4 ++- src/web/api.rs | 4 +-- 8 files changed, 48 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4555ef1e..d4eae073 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,9 +27,6 @@ default = [] # Turn on support for specifying glob ignore path rules in the project format. unstable_glob_ignore_paths = [] -# Turn on the server half of Rojo's unstable two-way sync feature. -unstable_two_way_sync = [] - # Enable this feature to live-reload assets from the web UI. dev_live_assets = [] diff --git a/plugin/src/Components/App.lua b/plugin/src/Components/App.lua index c18abf40..8a195235 100644 --- a/plugin/src/Components/App.lua +++ b/plugin/src/Components/App.lua @@ -114,6 +114,7 @@ function App:startSession(address, port, sessionOptions) self.serveSession = ServeSession.new({ apiContext = ApiContext.new(baseUrl), openScriptsExternally = sessionOptions.openScriptsExternally, + twoWaySync = sessionOptions.twoWaySync, }) self.serveSession:onStatusChanged(function(status, details) diff --git a/plugin/src/Components/ConnectPanel.lua b/plugin/src/Components/ConnectPanel.lua index 032d66a6..bebd67a6 100644 --- a/plugin/src/Components/ConnectPanel.lua +++ b/plugin/src/Components/ConnectPanel.lua @@ -167,6 +167,7 @@ function ConnectPanel:render() local sessionOptions = { openScriptsExternally = settings:get("openScriptsExternally"), + twoWaySync = settings:get("twoWaySync"), } startSession(address, port, sessionOptions) diff --git a/plugin/src/Components/PluginSettings.lua b/plugin/src/Components/PluginSettings.lua index 260b2912..1c5b4e37 100644 --- a/plugin/src/Components/PluginSettings.lua +++ b/plugin/src/Components/PluginSettings.lua @@ -8,6 +8,7 @@ local Roact = require(Rojo.Roact) local defaultSettings = { openScriptsExternally = false, + twoWaySync = false, } local Settings = {} diff --git a/plugin/src/Components/SettingsPanel.lua b/plugin/src/Components/SettingsPanel.lua index 0bb99dc9..d385d05b 100644 --- a/plugin/src/Components/SettingsPanel.lua +++ b/plugin/src/Components/SettingsPanel.lua @@ -24,10 +24,10 @@ function SettingsPanel:render() HorizontalAlignment = Enum.HorizontalAlignment.Center, VerticalAlignment = Enum.VerticalAlignment.Center, SortOrder = Enum.SortOrder.LayoutOrder, - Padding = UDim.new(0, 8), + Padding = UDim.new(0, 16), }), - Address = e(FitList, { + OpenScriptsExternally = e(FitList, { containerProps = { LayoutOrder = 1, BackgroundTransparency = 1, @@ -65,8 +65,46 @@ function SettingsPanel:render() }), }), + TwoWaySync = e(FitList, { + containerProps = { + LayoutOrder = 2, + BackgroundTransparency = 1, + }, + layoutProps = { + Padding = UDim.new(0, 4), + FillDirection = Enum.FillDirection.Horizontal, + HorizontalAlignment = Enum.HorizontalAlignment.Left, + VerticalAlignment = Enum.VerticalAlignment.Center, + }, + }, { + Label = e(FitText, { + Kind = "TextLabel", + LayoutOrder = 1, + BackgroundTransparency = 1, + TextXAlignment = Enum.TextXAlignment.Left, + Font = theme.MainFont, + TextSize = 16, + Text = "Two-Way Sync (Experimental!)", + TextColor3 = theme.Text1, + }), + + Padding = e("Frame", { + Size = UDim2.new(0, 8, 0, 0), + BackgroundTransparency = 1, + LayoutOrder = 2, + }), + + Input = e(Checkbox, { + layoutOrder = 3, + checked = settings:get("twoWaySync"), + onChange = function(newValue) + settings:set("twoWaySync", not settings:get("twoWaySync")) + end, + }), + }), + BackButton = e(FormButton, { - layoutOrder = 2, + layoutOrder = 4, text = "Okay", secondary = true, onClick = function() diff --git a/plugin/src/DevSettings.lua b/plugin/src/DevSettings.lua index c859f8f0..f1458c00 100644 --- a/plugin/src/DevSettings.lua +++ b/plugin/src/DevSettings.lua @@ -25,14 +25,6 @@ local VALUES = { [Environment.Test] = true, }, }, - UnstableTwoWaySync = { - type = "BoolValue", - values = { - [Environment.User] = false, - [Environment.Dev] = false, - [Environment.Test] = false, - }, - }, } local CONTAINER_NAME = "RojoDevSettings" .. Config.codename @@ -140,10 +132,6 @@ function DevSettings:shouldTypecheck() return getValue("TypecheckingEnabled") end -function DevSettings:twoWaySyncEnabled() - return getValue("UnstableTwoWaySync") -end - function _G.ROJO_DEV_CREATE() DevSettings:createDevSettings() end diff --git a/plugin/src/ServeSession.lua b/plugin/src/ServeSession.lua index c683a839..bf6e9194 100644 --- a/plugin/src/ServeSession.lua +++ b/plugin/src/ServeSession.lua @@ -46,6 +46,7 @@ ServeSession.Status = Status local validateServeOptions = t.strictInterface({ apiContext = t.table, openScriptsExternally = t.boolean, + twoWaySync = t.boolean, }) function ServeSession.new(options) @@ -77,6 +78,7 @@ function ServeSession.new(options) __status = Status.NotStarted, __apiContext = options.apiContext, __openScriptsExternally = options.openScriptsExternally, + __twoWaySync = options.twoWaySync, __reconciler = reconciler, __instanceMap = instanceMap, __statusChangedCallback = nil, @@ -158,7 +160,7 @@ function ServeSession:__onActiveScriptChanged(activeScript) end function ServeSession:__onInstanceChanged(instance, propertyName) - if not DevSettings:twoWaySyncEnabled() then + if not self.__twoWaySync then return end diff --git a/src/web/api.rs b/src/web/api.rs index b1e683fa..580bd055 100644 --- a/src/web/api.rs +++ b/src/web/api.rs @@ -43,9 +43,7 @@ impl Service for ApiService { self.handle_api_open(request) } - (&Method::POST, "/api/write") if cfg!(feature = "unstable_two_way_sync") => { - self.handle_api_write(request) - } + (&Method::POST, "/api/write") => self.handle_api_write(request), (_method, path) => json( ErrorResponse::not_found(format!("Route not found: {}", path)),