Add api permissions

This commit is contained in:
boatbomber 2022-09-28 17:01:17 -04:00
parent 6284d83ed7
commit d7cee5c5be
6 changed files with 468 additions and 30 deletions

View file

@ -23,6 +23,7 @@ local Theme = require(script.Theme)
local Page = require(script.Page)
local Notifications = require(script.Notifications)
local PermissionPopup = require(script.PermissionPopup)
local StudioPluginAction = require(script.Components.Studio.StudioPluginAction)
local StudioToolbar = require(script.Components.Studio.StudioToolbar)
local StudioToggleButton = require(script.Components.Studio.StudioToggleButton)
@ -64,6 +65,7 @@ function App:init()
guiEnabled = false,
notifications = {},
toolbarIcon = Assets.Images.PluginButton,
popups = {},
})
end
@ -204,6 +206,39 @@ function App:releaseSyncLock()
Log.trace("Could not relase sync lock because it is owned by {}", lock.Value)
end
function App:requestPermission(source: string, name: string, apis: {string}, initialState: {[string]: boolean?}): {[string]: boolean}
local responseEvent = Instance.new("BindableEvent")
self:setState(function(state)
state.popups[source] = {
responseEvent = responseEvent,
initialState = initialState,
name = name,
apis = apis,
content = e(PermissionPopup, {
responseEvent = responseEvent,
initialState = initialState,
source = source,
name = name,
apis = apis,
apiDescriptions = self.headlessAPI._apiDescriptions,
transparency = Roact.createBinding(0),
}),
}
return state
end)
local response = responseEvent.Event:Wait()
responseEvent:Destroy()
self:setState(function(state)
state.popups[source] = nil
return state
end)
return response
end
function App:startSession(host: string?, port: string?)
local claimedLock, priorOwner = self:claimSyncLock()
if not claimedLock then
@ -364,10 +399,50 @@ function App:render()
return e(Page, props)
end
local popups = {}
for id, popup in self.state.popups do
popups["Rojo_"..id] = e(StudioPluginGui, {
id = id,
title = popup.name .. " Popup",
active = true,
initDockState = Enum.InitialDockState.Top,
initEnabled = true,
overridePreviousState = true,
floatingSize = Vector2.new(400, 300),
minimumSize = Vector2.new(390, 240),
zIndexBehavior = Enum.ZIndexBehavior.Sibling,
onClose = function()
popup.responseEvent:Fire(popup.initialState)
popup.responseEvent:Destroy()
self:setState(function(state)
state[id] = nil
return state
end)
end,
}, {
Content = popup.content,
Background = Theme.with(function(theme)
return e("Frame", {
Size = UDim2.new(1, 0, 1, 0),
BackgroundColor3 = theme.BackgroundColor,
ZIndex = 0,
BorderSizePixel = 0,
})
end),
})
end
return e(StudioPluginContext.Provider, {
value = self.props.plugin,
}, {
e(Theme.StudioProvider, nil, {
popups = Roact.createFragment(popups),
gui = e(StudioPluginGui, {
id = pluginName,
title = pluginName,