Add CreateApiContext and more caller info

This commit is contained in:
boatbomber 2022-09-27 01:59:48 -04:00
parent f3de0c35ef
commit 2a25193941
2 changed files with 59 additions and 7 deletions

View file

@ -49,7 +49,7 @@ function App:init()
self.host, self.setHost = Roact.createBinding(priorHost or "")
self.port, self.setPort = Roact.createBinding(priorPort or "")
self.headlessAPI, self.readOnlyHeadlessAPI = HeadlessAPI.new(self, Config, Settings)
self.headlessAPI, self.readOnlyHeadlessAPI = HeadlessAPI.new(self)
-- selene: allow(global_usage)
_G.Rojo = self.readOnlyHeadlessAPI -- Expose headless to other plugins and command bar

View file

@ -1,13 +1,20 @@
local Parent = script:FindFirstAncestor("Rojo")
local Plugin = Parent.Plugin
local Config = require(Plugin.Config)
local Settings = require(Plugin.Settings)
local ApiContext = require(Plugin.ApiContext)
local API = {}
function API.new(app, config, settings)
function API.new(app)
local Rojo = {}
Rojo.Connected = if app.serveSession then app.serveSession:getStatus() == "Connected" else false
Rojo.Address = nil
Rojo.ProjectName = nil
Rojo.Version = table.clone(config.version)
Rojo.ProtocolVersion = config.protocolVersion
Rojo.Version = table.clone(Config.version)
Rojo.ProtocolVersion = Config.protocolVersion
Rojo._notifRateLimit = {}
@ -15,6 +22,28 @@ function API.new(app, config, settings)
print("Rojo:Test called by", Rojo:_getCaller(), "with args", ...)
end
function Rojo:_getCallerFull()
local traceback = string.split(debug.traceback(), "\n")
local topLevel = traceback[#traceback - 1]
local debugPlugin = string.match(topLevel, "^(PluginDebugService%.user_.-)%.")
if debugPlugin then
return debugPlugin
end
local localPlugin = string.match(topLevel, "^(user_.-)%.")
if localPlugin then
return localPlugin
end
local cloudPlugin = string.match(topLevel, "(cloud_%d-%..-)%.")
if cloudPlugin then
return cloudPlugin
end
return "RobloxStudio.CommandBar"
end
function Rojo:_getCaller()
local traceback = string.split(debug.traceback(), "\n")
local topLevel = traceback[#traceback - 1]
@ -34,7 +63,26 @@ function API.new(app, config, settings)
return cloudPlugin
end
return "Command Bar"
return "CommandBar"
end
function Rojo:_getCallerType()
local traceback = string.split(debug.traceback(), "\n")
local topLevel = traceback[#traceback - 1]
if string.find(topLevel, "^PluginDebugService%.user_") then
return "Debug"
end
if string.find(topLevel, "^user_") then
return "Local"
end
if string.find(topLevel, "cloud_%d+%.") then
return "Cloud"
end
return "CommandBar"
end
function Rojo:ConnectAsync(host: string?, port: number?)
@ -46,11 +94,11 @@ function API.new(app, config, settings)
end
function Rojo:GetSetting(setting: string): any
return settings:get(setting)
return Settings:get(setting)
end
function Rojo:SetSetting(setting: string, value: any)
return settings:set(setting, value)
return Settings:set(setting, value)
end
function Rojo:Notify(msg: string, timeout: number?)
@ -75,6 +123,10 @@ function API.new(app, config, settings)
return app:getHostAndPort()
end
function Rojo:CreateApiContext(baseUrl: string)
return ApiContext.new(baseUrl)
end
local ReadOnly = setmetatable({}, {
__index = function(_, key)
if string.find(key, "^_") then