API 参考

插件通过 window.host 调用灵核内核能力,所有方法返回 Promise,需使用 await。未声明权限的 API 调用会被直接拦截。

插件管理

host.reload(id)

重载或打开指定插件窗口。

await window.host.reload('com.example.hello');
参数 类型 说明
id string 插件 id

host.listPlugins()

返回已安装插件列表(含 features、permissions、state)。

const plugins = await window.host.listPlugins();
console.log(plugins);

host.setEnabled(id, enabled)

启用或禁用插件。

await window.host.setEnabled('com.example.hello', true);
参数 类型 说明
id string 插件 id
enabled boolean true 启用,false 禁用

host.uninstall(id)

卸载插件。

await window.host.uninstall('com.example.hello');
参数 类型 说明
id string 插件 id

系统信息

host.status()

获取内核状态与版本信息。

const s = await window.host.status();
console.log(s.hostVersion);

返回对象包含:

  • hostVersion — 宿主版本号
  • platform — 操作系统平台
  • arch — CPU 架构

文件操作

host.revealPlugin(id)

在文件管理器中显示插件目录。

await window.host.revealPlugin('com.example.hello');
参数 类型 说明
id string 插件 id

host.exportPlugin(id)

导出插件为 .kpkg 分发包,返回保存路径。

const path = await window.host.exportPlugin('com.example.hello');
console.log('已导出到:', path);
参数 类型 说明
id string 插件 id

剪贴板

host.clipboardRead()

读取系统剪贴板文本内容。需声明 clipboard.read 权限。

const text = await window.host.clipboardRead();

host.clipboardWrite(text)

写入文本到剪贴板。需声明 clipboard.write 权限。

await window.host.clipboardWrite('Hello, Nucleon!');
参数 类型 说明
text string 要写入的文本

事件监听

插件通过 window.host.on 监听宿主事件:

// 监听功能入口触发
window.host.on('invoke', (feature) => {
  console.log('触发功能:', feature.code);
  // 根据 feature.code 执行对应逻辑
});
事件 参数 说明
invoke feature 用户在搜索框中选中插件功能时触发

提示: 所有异步 API 返回 Promise,需使用 await。未声明权限的 API 调用会抛出异常,建议用 try/catch 包裹。