mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-21 20:21:38 +00:00
Stylua formatting
This commit is contained in:
parent
1042b36046
commit
b8e5fda482
8 changed files with 131 additions and 74 deletions
|
|
@ -85,7 +85,10 @@ function Toggle:render()
|
|||
Size = self.containerSize:map(function(value)
|
||||
local offset = self.props.options ~= nil and 120 or 40
|
||||
local textBounds = getTextBounds(
|
||||
self.props.description, 14, Enum.Font.Gotham, 1.2,
|
||||
self.props.description,
|
||||
14,
|
||||
Enum.Font.Gotham,
|
||||
1.2,
|
||||
Vector2.new(value.X - offset, math.huge)
|
||||
)
|
||||
return UDim2.new(1, -offset, 0, textBounds.Y)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,11 @@ function ConflictAPIPopup:render()
|
|||
BackgroundTransparency = 1,
|
||||
Size = UDim2.new(1, 0, 0, 0),
|
||||
AutomaticSize = Enum.AutomaticSize.Y,
|
||||
Text = string.format("Existing: Version %s, Protocol %d", Version.display(self.props.existingAPI.Version), self.props.existingAPI.ProtocolVersion),
|
||||
Text = string.format(
|
||||
"Existing: Version %s, Protocol %d",
|
||||
Version.display(self.props.existingAPI.Version),
|
||||
self.props.existingAPI.ProtocolVersion
|
||||
),
|
||||
Font = Enum.Font.Gotham,
|
||||
TextSize = 15,
|
||||
TextColor3 = theme.Setting.DescriptionColor,
|
||||
|
|
@ -71,7 +75,11 @@ function ConflictAPIPopup:render()
|
|||
BackgroundTransparency = 1,
|
||||
Size = UDim2.new(1, 0, 0, 0),
|
||||
AutomaticSize = Enum.AutomaticSize.Y,
|
||||
Text = string.format("Incoming: Version %s, Protocol %d", Version.display(Config.version), Config.protocolVersion),
|
||||
Text = string.format(
|
||||
"Incoming: Version %s, Protocol %d",
|
||||
Version.display(Config.version),
|
||||
Config.protocolVersion
|
||||
),
|
||||
Font = Enum.Font.Gotham,
|
||||
TextSize = 15,
|
||||
TextColor3 = theme.Setting.DescriptionColor,
|
||||
|
|
|
|||
|
|
@ -121,17 +121,11 @@ function Notification:render()
|
|||
|
||||
local paddingX, paddingY, logoSize = 24, 20, 32
|
||||
local sourceY = if self.props.source then logoSize + 5 else 0
|
||||
local sourceX = if self.props.source then TextService:GetTextSize(
|
||||
self.props.source,
|
||||
15,
|
||||
Enum.Font.GothamMedium,
|
||||
Vector2.new(350, 15)
|
||||
).X + logoSize + 5 else 0
|
||||
local sourceX = if self.props.source
|
||||
then TextService:GetTextSize(self.props.source, 15, Enum.Font.GothamMedium, Vector2.new(350, 15)).X + logoSize + 5
|
||||
else 0
|
||||
local actionsY = if self.props.actions then 35 else 0
|
||||
local contentX =
|
||||
math.max(textBounds.X, buttonsX, sourceX)
|
||||
+ (if self.props.thirdParty then 0 else logoSize + 3)
|
||||
+ 2
|
||||
local contentX = math.max(textBounds.X, buttonsX, sourceX) + (if self.props.thirdParty then 0 else logoSize + 3) + 2
|
||||
|
||||
local size = self.binding:map(function(value)
|
||||
return UDim2.fromOffset(
|
||||
|
|
@ -163,25 +157,29 @@ function Notification:render()
|
|||
}, {
|
||||
Logo = e("ImageLabel", {
|
||||
ImageTransparency = transparency,
|
||||
Image = if self.props.thirdParty then Assets.Images.ThirdPartyPlugin else Assets.Images.PluginButton,
|
||||
Image = if self.props.thirdParty
|
||||
then Assets.Images.ThirdPartyPlugin
|
||||
else Assets.Images.PluginButton,
|
||||
BackgroundTransparency = 1,
|
||||
Size = UDim2.new(0, logoSize, 0, logoSize),
|
||||
Position = UDim2.new(0, 0, 0, 0),
|
||||
AnchorPoint = Vector2.new(0, 0),
|
||||
}),
|
||||
Source = if self.props.source then e("TextLabel", {
|
||||
Text = self.props.source,
|
||||
Font = Enum.Font.GothamMedium,
|
||||
TextSize = 15,
|
||||
TextColor3 = theme.Notification.InfoColor,
|
||||
TextTransparency = transparency,
|
||||
TextXAlignment = Enum.TextXAlignment.Left,
|
||||
TextTruncate = Enum.TextTruncate.AtEnd,
|
||||
Source = if self.props.source
|
||||
then e("TextLabel", {
|
||||
Text = self.props.source,
|
||||
Font = Enum.Font.GothamMedium,
|
||||
TextSize = 15,
|
||||
TextColor3 = theme.Notification.InfoColor,
|
||||
TextTransparency = transparency,
|
||||
TextXAlignment = Enum.TextXAlignment.Left,
|
||||
TextTruncate = Enum.TextTruncate.AtEnd,
|
||||
|
||||
Size = UDim2.new(1, -logoSize - 5, 0, logoSize),
|
||||
Position = UDim2.fromOffset(logoSize + 5, 0),
|
||||
BackgroundTransparency = 1,
|
||||
}) else nil,
|
||||
Size = UDim2.new(1, -logoSize - 5, 0, logoSize),
|
||||
Position = UDim2.fromOffset(logoSize + 5, 0),
|
||||
BackgroundTransparency = 1,
|
||||
})
|
||||
else nil,
|
||||
Message = e("TextLabel", {
|
||||
Text = self.props.text,
|
||||
Font = Enum.Font.GothamMedium,
|
||||
|
|
@ -192,7 +190,9 @@ function Notification:render()
|
|||
TextWrapped = true,
|
||||
|
||||
Size = UDim2.new(0, textBounds.X, 0, textBounds.Y),
|
||||
Position = if self.props.thirdParty then UDim2.fromOffset(0, logoSize + 5) else UDim2.fromOffset(logoSize + 3, 0),
|
||||
Position = if self.props.thirdParty
|
||||
then UDim2.fromOffset(0, logoSize + 5)
|
||||
else UDim2.fromOffset(logoSize + 3, 0),
|
||||
BackgroundTransparency = 1,
|
||||
}),
|
||||
Actions = if self.props.actions
|
||||
|
|
|
|||
|
|
@ -71,7 +71,10 @@ function PermissionPopup:render()
|
|||
BackgroundTransparency = 1,
|
||||
Size = UDim2.new(1, 0, 0, 0),
|
||||
AutomaticSize = Enum.AutomaticSize.Y,
|
||||
Text = string.format("A third-party plugin, %s, is asking to use the following parts of the Rojo API. Please grant/deny access.", self.props.name or "[Unknown]"),
|
||||
Text = string.format(
|
||||
"A third-party plugin, %s, is asking to use the following parts of the Rojo API. Please grant/deny access.",
|
||||
self.props.name or "[Unknown]"
|
||||
),
|
||||
Font = Enum.Font.GothamMedium,
|
||||
TextSize = 17,
|
||||
TextColor3 = theme.Setting.NameColor,
|
||||
|
|
@ -97,7 +100,7 @@ function PermissionPopup:render()
|
|||
|
||||
ScrollingFrame = e(ScrollingFrame, {
|
||||
size = self.infoSize:map(function(infoSize)
|
||||
return UDim2.new(1, 0, 1, -infoSize.Y-44)
|
||||
return UDim2.new(1, 0, 1, -infoSize.Y - 44)
|
||||
end),
|
||||
layoutOrder = 2,
|
||||
contentSize = self.contentSize,
|
||||
|
|
|
|||
|
|
@ -110,10 +110,13 @@ function Listing:render()
|
|||
|
||||
Size = self.containerSize:map(function(value)
|
||||
local textBounds = getTextBounds(
|
||||
self.props.description, 14, Enum.Font.Gotham, 1.2,
|
||||
self.props.description,
|
||||
14,
|
||||
Enum.Font.Gotham,
|
||||
1.2,
|
||||
Vector2.new(value.X - 40, math.huge)
|
||||
)
|
||||
return UDim2.new(1, - 40, 0, textBounds.Y)
|
||||
return UDim2.new(1, -40, 0, textBounds.Y)
|
||||
end),
|
||||
|
||||
LayoutOrder = 2,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ local function Navbar(props)
|
|||
onClick = props.onBack,
|
||||
}, {
|
||||
Tip = e(Tooltip.Trigger, {
|
||||
text = "Back"
|
||||
text = "Back",
|
||||
}),
|
||||
}),
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ local function Navbar(props)
|
|||
Size = UDim2.new(1, 0, 1, 0),
|
||||
|
||||
BackgroundTransparency = 1,
|
||||
})
|
||||
}),
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
|
@ -118,7 +118,12 @@ function PermissionsPage:render()
|
|||
),
|
||||
|
||||
onClick = function()
|
||||
self.props.onEdit(self.props.headlessAPI._sourceToPlugin[source], source, meta, self.props.headlessAPI._permissions[source] or {})
|
||||
self.props.onEdit(
|
||||
self.props.headlessAPI._sourceToPlugin[source],
|
||||
source,
|
||||
meta,
|
||||
self.props.headlessAPI._permissions[source] or {}
|
||||
)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -249,7 +249,14 @@ function App:addNotification(
|
|||
end
|
||||
end
|
||||
|
||||
function App:addThirdPartyNotification(source: string, text: string, timeout: number?, actions: { [string]: {text: string, style: string, layoutOrder: number, onClick: (any) -> ()} }?)
|
||||
function App:addThirdPartyNotification(
|
||||
source: string,
|
||||
text: string,
|
||||
timeout: number?,
|
||||
actions: {
|
||||
[string]: { text: string, style: string, layoutOrder: number, onClick: (any) -> () },
|
||||
}?
|
||||
)
|
||||
if not Settings:get("showNotifications") then
|
||||
return
|
||||
end
|
||||
|
|
@ -409,18 +416,29 @@ function App:releaseSyncLock()
|
|||
Log.trace("Could not release sync lock because it is owned by {}", lock.Value)
|
||||
end
|
||||
|
||||
function App:requestPermission(plugin: Plugin, source: string, name: string, apis: {string}, initialState: {[string]: boolean?}): {[string]: boolean}
|
||||
function App:requestPermission(
|
||||
plugin: Plugin,
|
||||
source: string,
|
||||
name: string,
|
||||
apis: { string },
|
||||
initialState: { [string]: boolean? }
|
||||
): { [string]: boolean }
|
||||
local responseEvent = Instance.new("BindableEvent")
|
||||
|
||||
Log.info("The third-party plugin '{}' is requesting permission to use the API!", name)
|
||||
|
||||
local unloadProtection = if plugin then plugin.Unloading:Connect(function()
|
||||
Log.warn("Cancelling API permission request for '{}' because the third-party plugin has been removed.", name)
|
||||
responseEvent:Fire(initialState)
|
||||
end) else nil
|
||||
local unloadProtection = if plugin
|
||||
then plugin.Unloading:Connect(function()
|
||||
Log.warn(
|
||||
"Cancelling API permission request for '{}' because the third-party plugin has been removed.",
|
||||
name
|
||||
)
|
||||
responseEvent:Fire(initialState)
|
||||
end)
|
||||
else nil
|
||||
|
||||
self:setState(function(state)
|
||||
state.popups[source .. " Permissions"] = {
|
||||
state.popups[source .. " Permissions"] = {
|
||||
name = name,
|
||||
content = e(PermissionPopup, {
|
||||
responseEvent = responseEvent,
|
||||
|
|
@ -445,7 +463,7 @@ function App:requestPermission(plugin: Plugin, source: string, name: string, api
|
|||
end
|
||||
|
||||
self:setState(function(state)
|
||||
state.popups[source .. " Permissions"] = nil
|
||||
state.popups[source .. " Permissions"] = nil
|
||||
return state
|
||||
end)
|
||||
|
||||
|
|
@ -716,7 +734,7 @@ function App:render()
|
|||
|
||||
local popups = {}
|
||||
for id, popup in self.state.popups do
|
||||
popups["Rojo_"..id] = e(StudioPluginGui, {
|
||||
popups["Rojo_" .. id] = e(StudioPluginGui, {
|
||||
id = id,
|
||||
title = popup.name,
|
||||
active = true,
|
||||
|
|
@ -854,13 +872,7 @@ function App:render()
|
|||
for api in apiMap do
|
||||
table.insert(apiList, api)
|
||||
end
|
||||
local response = self:requestPermission(
|
||||
plugin,
|
||||
source,
|
||||
name,
|
||||
apiList,
|
||||
apiMap
|
||||
)
|
||||
local response = self:requestPermission(plugin, source, name, apiList, apiMap)
|
||||
self.headlessAPI:_setPermissions(source, name, response)
|
||||
end,
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ local apiPermissionAllowlist = {
|
|||
RequestAccess = true,
|
||||
}
|
||||
|
||||
local API = {}
|
||||
local API = {}
|
||||
|
||||
function API.new(app)
|
||||
local Rojo = {}
|
||||
|
|
@ -85,7 +85,8 @@ function API.new(app)
|
|||
if info then
|
||||
return info.Name .. " by " .. info.Creator.Name
|
||||
else
|
||||
local success, newInfo = pcall(MarketplaceService.GetProductInfo, MarketplaceService, tonumber(cloudId), Enum.InfoType.Asset)
|
||||
local success, newInfo =
|
||||
pcall(MarketplaceService.GetProductInfo, MarketplaceService, tonumber(cloudId), Enum.InfoType.Asset)
|
||||
if success then
|
||||
cloudIdInfoCache[cloudId] = newInfo
|
||||
return newInfo.Name .. " by " .. newInfo.Creator.Name
|
||||
|
|
@ -119,7 +120,8 @@ function API.new(app)
|
|||
Creator = info.Creator.Name,
|
||||
}
|
||||
else
|
||||
local success, newInfo = pcall(MarketplaceService.GetProductInfo, MarketplaceService, tonumber(cloudId), Enum.InfoType.Asset)
|
||||
local success, newInfo =
|
||||
pcall(MarketplaceService.GetProductInfo, MarketplaceService, tonumber(cloudId), Enum.InfoType.Asset)
|
||||
if success then
|
||||
cloudIdInfoCache[cloudId] = newInfo
|
||||
return {
|
||||
|
|
@ -160,14 +162,11 @@ function API.new(app)
|
|||
Rojo._rateLimit[source] = {
|
||||
[api] = 0,
|
||||
}
|
||||
|
||||
elseif Rojo._rateLimit[source][api] == nil then
|
||||
Rojo._rateLimit[source][api] = 0
|
||||
|
||||
elseif Rojo._rateLimit[source][api] >= LIMIT then
|
||||
-- No more than LIMIT requests per BUCKET seconds
|
||||
return true
|
||||
|
||||
end
|
||||
|
||||
Rojo._rateLimit[source][api] += 1
|
||||
|
|
@ -182,7 +181,9 @@ function API.new(app)
|
|||
Rojo._permissionsChanged = Rojo._permissionsChangedEvent.Event
|
||||
|
||||
function Rojo:_permissionCheck(key: string): boolean
|
||||
if apiPermissionAllowlist[key] then return true end
|
||||
if apiPermissionAllowlist[key] then
|
||||
return true
|
||||
end
|
||||
|
||||
local source = Rojo:_getCallerSource()
|
||||
if Rojo._permissions[source] == nil then
|
||||
|
|
@ -200,10 +201,14 @@ function API.new(app)
|
|||
|
||||
-- Set permissions
|
||||
for api, granted in permissions do
|
||||
Log.warn(string.format(
|
||||
"%s Rojo.%s for '%s'",
|
||||
granted and "Granting permission to" or "Denying permission to", api, name
|
||||
))
|
||||
Log.warn(
|
||||
string.format(
|
||||
"%s Rojo.%s for '%s'",
|
||||
granted and "Granting permission to" or "Denying permission to",
|
||||
api,
|
||||
name
|
||||
)
|
||||
)
|
||||
Rojo._permissions[source][api] = granted
|
||||
end
|
||||
|
||||
|
|
@ -227,9 +232,12 @@ function API.new(app)
|
|||
end
|
||||
|
||||
Rojo._apiDescriptions.RequestAccess = "Used to gain access to Rojo API members"
|
||||
function Rojo:RequestAccess(plugin: Plugin, apis: {string}): {[string]: boolean}
|
||||
function Rojo:RequestAccess(plugin: Plugin, apis: { string }): { [string]: boolean }
|
||||
assert(type(apis) == "table", "Rojo:RequestAccess expects an array of valid API names as the second argument")
|
||||
assert(typeof(plugin) == "Instance" and plugin:IsA("Plugin"), "Rojo:RequestAccess expects a Plugin as the first argument")
|
||||
assert(
|
||||
typeof(plugin) == "Instance" and plugin:IsA("Plugin"),
|
||||
"Rojo:RequestAccess expects a Plugin as the first argument"
|
||||
)
|
||||
|
||||
local source, name = Rojo:_getCallerSource(), Rojo:_getCallerName()
|
||||
Rojo._sourceToPlugin[source] = plugin
|
||||
|
|
@ -291,7 +299,7 @@ function API.new(app)
|
|||
Rojo._apiDescriptions.Test = "Prints the given arguments to the console"
|
||||
function Rojo:Test(...)
|
||||
local args = table.pack(...)
|
||||
for i=1, args.n do
|
||||
for i = 1, args.n do
|
||||
local v = args[i]
|
||||
local t = type(v)
|
||||
if t == "string" then
|
||||
|
|
@ -301,10 +309,14 @@ function API.new(app)
|
|||
end
|
||||
end
|
||||
|
||||
print(string.format(
|
||||
"Rojo:Test(%s) called from '%s' (%s)",
|
||||
table.concat(args, ", "), Rojo:_getCallerName(), Rojo:_getCallerSource()
|
||||
))
|
||||
print(
|
||||
string.format(
|
||||
"Rojo:Test(%s) called from '%s' (%s)",
|
||||
table.concat(args, ", "),
|
||||
Rojo:_getCallerName(),
|
||||
Rojo:_getCallerSource()
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
Rojo._apiDescriptions.ConnectAsync = "Connects to a Rojo server"
|
||||
|
|
@ -347,7 +359,11 @@ function API.new(app)
|
|||
end
|
||||
|
||||
Rojo._apiDescriptions.Notify = "Shows a notification in the Rojo UI"
|
||||
function Rojo:Notify(msg: string, timeout: number?, actions: { [string]: {text: string, style: string, layoutOrder: number, onClick: (any) -> ()} }?): () -> ()
|
||||
function Rojo:Notify(
|
||||
msg: string,
|
||||
timeout: number?,
|
||||
actions: { [string]: { text: string, style: string, layoutOrder: number, onClick: (any) -> () } }?
|
||||
): () -> ()
|
||||
assert(type(msg) == "string", "Message must be type `string`")
|
||||
assert(type(timeout) == "number" or timeout == nil, "Timeout must be type `number?`")
|
||||
assert((actions == nil) or (type(actions) == "table"), "Actions must be table or nil")
|
||||
|
|
@ -365,7 +381,10 @@ function API.new(app)
|
|||
assert(type(action) == "table", actionId .. " must be table")
|
||||
assert(type(action.text) == "string", actionId .. ".text must be string")
|
||||
assert(type(action.style) == "string", actionId .. ".style must be string")
|
||||
assert(action.style == "Solid" or action.style == "Bordered", actionId .. ".style must be 'Solid' or 'Bordered'")
|
||||
assert(
|
||||
action.style == "Solid" or action.style == "Bordered",
|
||||
actionId .. ".style must be 'Solid' or 'Bordered'"
|
||||
)
|
||||
assert(type(action.layoutOrder) == "number", actionId .. ".layoutOrder must be number")
|
||||
assert(type(action.onClick) == "function", actionId .. ".onClick must be function")
|
||||
|
||||
|
|
@ -409,10 +428,14 @@ function API.new(app)
|
|||
-- Permissions check
|
||||
local granted = Rojo:_permissionCheck(key)
|
||||
if not granted then
|
||||
error(string.format(
|
||||
"Attempted to read Rojo.%s, but the plugin does not have permission to do so.\nPlease first use Rojo:RequestAccess({ \"%s\" }) to gain access to this API.",
|
||||
key, key
|
||||
), 2)
|
||||
error(
|
||||
string.format(
|
||||
'Attempted to read Rojo.%s, but the plugin does not have permission to do so.\nPlease first use Rojo:RequestAccess({ "%s" }) to gain access to this API.',
|
||||
key,
|
||||
key
|
||||
),
|
||||
2
|
||||
)
|
||||
end
|
||||
|
||||
return Rojo[key]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue