app.plugin - 插件信息查询
查询当前插件的元数据信息。
方法
app.plugin.id()
获取当前插件的唯一标识符。
返回值: string
local id = app.plugin.id()
-- "com.example.myplugin"
app.plugin.name()
获取当前插件的显示名称。
返回值: string
local name = app.plugin.name()
-- "My Plugin"
app.plugin.version()
获取当前插件的版本号。
返回值: string
local ver = app.plugin.version()
-- "1.2.3"
app.plugin.author()
获取当前插件的作者信息。
返回值: string
local author = app.plugin.author()
-- "ByteAge"
app.plugin.description()
获取当前插件的描述文本。
返回值: string
local desc = app.plugin.description()
-- "一个实用的文件处理插件"
app.plugin.installPath()
获取当前插件的安装目录路径。
返回值: string
local dir = app.plugin.installPath()
-- "/Users/alice/Library/Application Support/iRightMenu/Plugins/myplugin.rmx"
-- 读取插件内的资源文件
local icon = app.path.join(dir, "icon.png")
local content = app.file.read(app.path.join(dir, "data.json"))
app.plugin.metadata()
获取当前插件的完整元数据表。
返回值: table - 包含所有 plugin.json 字段
local meta = app.plugin.metadata()
-- {
-- id = "com.example.myplugin",
-- name = "My Plugin",
-- version = "1.2.3",
-- author = "ByteAge",
-- description = "...",
-- minAppVersion = "2.0.0",
-- permissions = {"file", "shell"},
-- ...
-- }
app.log.info("插件版本: " .. meta.version)
说明
- L0 安全模块,所有插件均可使用,无需额外权限
- 替代 Plugin 基类的
self:getName()等隐式方法 - 替代已废弃的
_PLUGIN_DIR、_PLUGIN_METADATA全局变量 app.plugin.installPath()返回的是.rmx包解压后的目录,可直接用于app.path.join拼接资源路径
示例
读取插件内置资源
function MyPlugin:onMenuItems(context)
local dir = app.plugin.installPath()
-- 读取插件内的配置模板
local templatePath = app.path.join(dir, "templates", "default.html")
local template = app.file.read(templatePath)
if not template then
app.log.error("模板文件不存在: " .. templatePath)
return
end
-- 打开 WebView 展示内容
app.webview.open({html = template, title = app.plugin.name()})
end
版本信息上报
function MyPlugin:onMenuItems(context)
local meta = app.plugin.metadata()
app.log.info(string.format(
"插件 %s v%s (作者: %s) 已触发",
meta.name, meta.version, meta.author
))
end