plugin: Add setting for opening scripts externally

This commit is contained in:
Lucien Greathouse
2020-03-17 23:20:05 -07:00
parent a2356773dc
commit 0e4f6dea2b
4 changed files with 131 additions and 133 deletions

View File

@@ -107,12 +107,13 @@ function App:init()
end) end)
end end
function App:startSession(address, port) function App:startSession(address, port, sessionOptions)
Log.trace("Starting new session") Log.trace("Starting new session")
local baseUrl = ("http://%s:%s"):format(address, port) local baseUrl = ("http://%s:%s"):format(address, port)
self.serveSession = ServeSession.new({ self.serveSession = ServeSession.new({
apiContext = ApiContext.new(baseUrl), apiContext = ApiContext.new(baseUrl),
openScriptsExternally = sessionOptions.openScriptsExternally,
}) })
self.serveSession:onStatusChanged(function(status, details) self.serveSession:onStatusChanged(function(status, details)
@@ -153,8 +154,8 @@ function App:render()
if self.state.appStatus == AppStatus.NotStarted then if self.state.appStatus == AppStatus.NotStarted then
children = { children = {
ConnectPanel = e(ConnectPanel, { ConnectPanel = e(ConnectPanel, {
startSession = function(address, port) startSession = function(address, port, settings)
self:startSession(address, port) self:startSession(address, port, settings)
end, end,
openSettings = function() openSettings = function()
self:setState({ self:setState({

View File

@@ -11,6 +11,7 @@ local FitList = require(Plugin.Components.FitList)
local FitText = require(Plugin.Components.FitText) local FitText = require(Plugin.Components.FitText)
local FormButton = require(Plugin.Components.FormButton) local FormButton = require(Plugin.Components.FormButton)
local FormTextInput = require(Plugin.Components.FormTextInput) local FormTextInput = require(Plugin.Components.FormTextInput)
local PluginSettings = require(Plugin.Components.PluginSettings)
local e = Roact.createElement local e = Roact.createElement
@@ -28,6 +29,7 @@ function ConnectPanel:render()
local openSettings = self.props.openSettings local openSettings = self.props.openSettings
return Theme.with(function(theme) return Theme.with(function(theme)
return PluginSettings.with(function(settings)
return e(Panel, nil, { return e(Panel, nil, {
Layout = e("UIListLayout", { Layout = e("UIListLayout", {
SortOrder = Enum.SortOrder.LayoutOrder, SortOrder = Enum.SortOrder.LayoutOrder,
@@ -163,13 +165,18 @@ function ConnectPanel:render()
port = Config.defaultPort port = Config.defaultPort
end end
startSession(address, port) local sessionOptions = {
openScriptsExternally = settings:get("openScriptsExternally"),
}
startSession(address, port, sessionOptions)
end end
end, end,
}), }),
}), }),
}) })
end) end)
end)
end end
return ConnectPanel return ConnectPanel

View File

@@ -33,14 +33,6 @@ local VALUES = {
[Environment.Test] = false, [Environment.Test] = false,
}, },
}, },
UnstableOpenScriptsExternally = {
type = "BoolValue",
values = {
[Environment.User] = false,
[Environment.Dev] = false,
[Environment.Test] = false,
},
},
} }
local CONTAINER_NAME = "RojoDevSettings" .. Config.codename local CONTAINER_NAME = "RojoDevSettings" .. Config.codename
@@ -152,10 +144,6 @@ function DevSettings:twoWaySyncEnabled()
return getValue("UnstableTwoWaySync") return getValue("UnstableTwoWaySync")
end end
function DevSettings:alwaysOpenScriptsExternally()
return getValue("UnstableOpenScriptsExternally")
end
function _G.ROJO_DEV_CREATE() function _G.ROJO_DEV_CREATE()
DevSettings:createDevSettings() DevSettings:createDevSettings()
end end

View File

@@ -45,6 +45,7 @@ ServeSession.Status = Status
local validateServeOptions = t.strictInterface({ local validateServeOptions = t.strictInterface({
apiContext = t.table, apiContext = t.table,
openScriptsExternally = t.boolean,
}) })
function ServeSession.new(options) function ServeSession.new(options)
@@ -75,6 +76,7 @@ function ServeSession.new(options)
self = { self = {
__status = Status.NotStarted, __status = Status.NotStarted,
__apiContext = options.apiContext, __apiContext = options.apiContext,
__openScriptsExternally = options.openScriptsExternally,
__reconciler = reconciler, __reconciler = reconciler,
__instanceMap = instanceMap, __instanceMap = instanceMap,
__statusChangedCallback = nil, __statusChangedCallback = nil,
@@ -125,7 +127,7 @@ function ServeSession:stop()
end end
function ServeSession:__onActiveScriptChanged(activeScript) function ServeSession:__onActiveScriptChanged(activeScript)
if not DevSettings:alwaysOpenScriptsExternally() then if not self.__openScriptsExternally then
Log.trace("Not opening script {} because feature not enabled.", activeScript) Log.trace("Not opening script {} because feature not enabled.", activeScript)
return return