宿主事件
Lite 插件 API 3.6.0。后台模块通过宿主注入的 BackgroundHost 上的 ctx.events 订阅事件。View 和 action 暂不提供此接口,通过后台消息 API 与 background 通信。
| 事件 | 参数类型 | 权限 |
|---|---|---|
file.opened |
FileOpenedEvent |
background.fileHistory: true 及宿主授权 |
file.opened 表示后台所属窗口、当前 Space 中的一次成功文件打开。读取内容、预览资源、View 重渲染和打开失败不产生此事件。事件仅提供元数据,不授予文件内容访问权。
交付与生命周期
Section titled “交付与生命周期”事件为实时通知,不提供初始快照、持久交付或历史回放。订阅不会启动后台,也不会弹出授权请求。需要随 Space 打开自动运行时,声明 background.autoStart 并由用户授权。
每次订阅可以独立取消。后台停止时所有订阅随之销毁,权限撤销后停止交付。关闭 View 不影响后台监听。一个监听器抛错不会阻止其他监听器执行。
订阅示例和最近打开插件的使用流程见后台指南。
使用指南: background. API 索引.
签名、参数及返回类型从 SDK 自动生成;可选成员不保证在每个宿主和上下文中存在。
FileOpenedEvent
Section titled “FileOpenedEvent”FileOpenedEvent.id
Section titled “FileOpenedEvent.id”支持宿主: Lite
宿主生成的事件标识,可用于去重。
readonly id: string;FileOpenedEvent.path
Section titled “FileOpenedEvent.path”支持宿主: Lite
相对当前 Space 的文件路径。
readonly path: string;FileOpenedEvent.timestamp
Section titled “FileOpenedEvent.timestamp”支持宿主: Lite
成功打开的时间,单位为 Unix 毫秒。
readonly timestamp: number;PluginEventMap
Section titled “PluginEventMap”PluginEventMap.“file.opened”
Section titled “PluginEventMap.“file.opened””支持宿主: Lite
成功打开文件的元数据,字段见 FileOpenedEvent。
"file.opened": FileOpenedEvent;关联类型: FileOpenedEvent.
PluginEvents
Section titled “PluginEvents”PluginEvents.on
Section titled “PluginEvents.on”支持宿主: Lite
事件名决定监听器参数类型。返回 Disposable,dispose() 可重复调用。未知事件名、非函数监听器和未声明的事件权限会同步抛错。
on<K extends keyof PluginEventMap>(type: K, listener: (event: PluginEventMap[K]) => void): Disposable;| 参数 | 类型 | 必填 |
|---|---|---|
type |
K |
是 |
listener |
(event: PluginEventMap[K]) => void |
是 |
返回值: Disposable.
关联类型: PluginEventMap, Disposable.