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

View File

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

View File

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

View File

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