逐项查 PluginContext 方法与参数
适用版本为 CLI / SDK 3.0.0。输入方法名或命名空间,例如 queue.replace、storage、onIdle。展开方法可查看签名、参数是否可省略及返回值。只读字段 ctx.plugin、ctx.host 和共享纯函数 ctx.utils.lodash 可在完整类型查到。Vue、Provider、Guest 和视图桥接分别有自己的上下文。
先读一次签名
以 ctx.storage.get<number>('clicks') 为例,key 是必填参数,缺失的本地键返回 null。调用返回 Promise,要 await 后才能比较值。对自有 JSON 键的读取没有额外的用户授权;跨插件读取仍受键的共享策略限制。完整读写练习见保存计数。
? 表示参数可省略。T | undefined 出现在必填位置时仍要传这个位置,例如 ctx.player.play(undefined, call)。例如在 player.seek 中展开 call 的对象字段,可以看到 operation 和 permissionKey 都必填。字段表保留 SDK 声明中的备注。联合类型、泛型、数组元素以及下一层对象到完整声明按类型名查询。类型声明没有记录的默认值不作推断。方法返回 () => void 时,用它解绑;返回句柄时还需按该句柄的类型关闭连接或服务。
查找方法
ctx.account
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.account.getSession
account.getSession(call: ServiceCall): Promise<AccountSession>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<AccountSession>
权限与范围:account.profile。
ctx.account.getProfile
account.getProfile(call: ServiceCall): Promise<AccountProfile | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<AccountProfile | null>
权限与范围:account.profile。
ctx.account.openLogin
account.openLogin(operation: OperationContext): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
operation | OperationContext | 是 | — | 沿用宿主传入的本次操作,传递取消与截止时间。 |
operation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
deadlineAt | number | 是 | — |
signal | AbortSignal | 是 | — |
connectionId | string | undefined | 可省略 | — |
userIntent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
Opens the application's own account page. Plugins do not implement login or receive its token.
ctx.accounts
由用户选择账号;每次使用当前连接与授权来源,不在界面传递凭据。 相关教程
ctx.accounts.current
accounts.current(accountId: string): Promise<{ connectionId: string; expired: boolean; } | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
accountId | string | 是 | — | 清单声明的账号扩展 ID。 |
返回 Promise<{ connectionId: string; expired: boolean; } | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.accounts.reportExpired
accounts.reportExpired(accountId: string, connectionId: string, credential: CredentialRef): Promise<boolean>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
accountId | string | 是 | — | 清单声明的账号扩展 ID。 |
connectionId | string | 是 | — | 宿主管理的账号连接标识。 |
credential | CredentialRef | 是 | — | 与当前账号和来源关联的凭据引用。 |
credential 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
kind | "credential" | 是 | — |
id | string | 是 | — |
返回 Promise<boolean>
权限与范围:credentials.use。
ctx.accounts.register
accounts.register(id: string, implementation: AccountImplementation): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
implementation | AccountImplementation | 是 | — | 该扩展点的实现对象;成员决定宿主可以调用哪些回调。 |
implementation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
likes | (AccountCollection<MusicTrack> & { set?(account: AccountConnection, change: { ref: ResourceRef; liked: boolean; }, operation: OperationContext): Promise<void>; }) | undefined | 可省略 | — |
playlists | AccountCollection<MusicPlaylist> | undefined | 可省略 | — |
history | AccountCollection<MusicTrack> | undefined | 可省略 | — |
recommend | AccountCollection<MusicTrack> | undefined | 可省略 | — |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.actions
核对清单 ID 和 Logic 注册;UI 快照仅传视图显示所需的数据。 相关教程
ctx.actions.register
actions.register<TInput extends JsonValue = JsonValue, TResult extends JsonValue | void = void | JsonValue>(id: string, handler: (input: TInput, operation: OperationContext) => MaybePromise<TResult>): Disposable
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
handler | (input: TInput, operation: OperationContext) => MaybePromise<TResult> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.ai
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.ai.generate
ai.generate(request: { prompt: string; maxOutputChars?: number; }, call: ServiceCall): Promise<{ text: string; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { prompt: string; maxOutputChars?: number; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
prompt | string | 是 | — |
maxOutputChars | number | undefined | 可省略 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<{ text: string; }>
权限与范围:ai.use。
ctx.app
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.app.operations.list
app.operations.list(): Promise<OperationTool[]>
无参数。
返回 Promise<OperationTool[]>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.app.call
app.call<Name extends CallableOperation>(name: Name, input: OperationInputs[Name], call: ServiceCall): Promise<OperationToolResult<Name>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
name | Name | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
input | OperationInputs[Name] | 是 | — | 本次动作的数据,结构由对应操作决定。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<OperationToolResult<Name>>
权限与范围:依当前操作或资源范围决定,见对应任务指南。
ctx.app.getInfo
app.getInfo(): Promise<AppInfo>
无参数。
返回 Promise<AppInfo>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.app.openSettings
app.openSettings(section?: string): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
section | string | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.app.openExternal
app.openExternal(url: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
url | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:external.open。
ctx.assets
只使用宿主公开或插件声明的资源和内置模块。 相关教程
ctx.assets.list
assets.list(): readonly HostAssetName[]
无参数。
返回 readonly ("app.logo" | "placeholder.cover" | "placeholder.avatar")[]
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.assets.url
assets.url(name: HostAssetName | AssetHandle): Promise<string>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
name | AssetHandle | "app.logo" | "placeholder.cover" | "placeholder.avatar" | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<string>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.capabilities
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.capabilities.list
capabilities.list(): Promise<ServiceAvailability[]>
无参数。
返回 Promise<ServiceAvailability[]>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.capabilities.get
capabilities.get(service: string): Promise<ServiceAvailability>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
service | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<ServiceAvailability>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.clipboard
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.clipboard.readText
clipboard.readText(call: ServiceCall): Promise<string>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<string>
权限与范围:clipboard.read。
ctx.clipboard.writeText
clipboard.writeText(text: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
text | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:clipboard.write。
ctx.config
读写当前插件的数据前,先处理缺失键和旧数据;需要授权的操作使用本次用户意图。 相关教程
ctx.config.get
config.get<T = JsonObject>(): Promise<Readonly<T>>
无参数。
返回 Promise<Readonly<T>>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.credentials
由用户选择账号;每次使用当前连接与授权来源,不在界面传递凭据。 相关教程
ctx.credentials.get
credentials.get(connectionId: string): Promise<CredentialRef | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
connectionId | string | 是 | — | 宿主管理的账号连接标识。 |
返回 Promise<CredentialRef | null>
权限与范围:credentials.use。
ctx.crypto
仅在能力已获准且资源已声明时启动,停止时释放监听和流。 相关教程
ctx.crypto.createCipher
crypto.createCipher(algorithm: StreamAlgorithm, key: string | Uint8Array, iv: string | Uint8Array, options?: CryptoStreamOptions): TransformStream<Uint8Array, Uint8Array>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
algorithm | StreamAlgorithm | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
key | string | Uint8Array<ArrayBufferLike> | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
iv | string | Uint8Array<ArrayBufferLike> | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
options | CryptoStreamOptions | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
options 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
encoding | "hex" | "base64" | undefined | 可省略 | String keys and IVs are hexadecimal unless base64 is specified. |
signal | AbortSignal | undefined | 可省略 | — |
返回 TransformStream<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.crypto.createDecipher
crypto.createDecipher(algorithm: StreamAlgorithm, key: string | Uint8Array, iv: string | Uint8Array, options?: CryptoStreamOptions): TransformStream<Uint8Array, Uint8Array>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
algorithm | StreamAlgorithm | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
key | string | Uint8Array<ArrayBufferLike> | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
iv | string | Uint8Array<ArrayBufferLike> | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
options | CryptoStreamOptions | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
options 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
encoding | "hex" | "base64" | undefined | 可省略 | String keys and IVs are hexadecimal unless base64 is specified. |
signal | AbortSignal | undefined | 可省略 | — |
返回 TransformStream<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.devices
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.devices.list
devices.list(call: ServiceCall): Promise<AudioDevice[]>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<AudioDevice[]>
权限与范围:devices.control。
ctx.devices.select
devices.select(id: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:devices.control。
ctx.downloads
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.downloads.list
downloads.list(call: ServiceCall): Promise<DownloadTask[]>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<DownloadTask[]>
权限与范围:downloads.manage。
ctx.downloads.create
downloads.create(request: { tracks: ResourceRef[]; quality?: string; directory?: DirectoryHandle; }, call: ServiceCall): Promise<DownloadTask[]>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { tracks: ResourceRef[]; quality?: string; directory?: DirectoryHandle; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
tracks | ResourceRef[] | 是 | — |
quality | string | undefined | 可省略 | — |
directory | DirectoryHandle | undefined | 可省略 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<DownloadTask[]>
权限与范围:downloads.create。
ctx.downloads.pause
downloads.pause(ids: string[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ids | string[] | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:downloads.manage。
ctx.downloads.resume
downloads.resume(ids: string[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ids | string[] | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:downloads.manage。
ctx.downloads.cancel
downloads.cancel(ids: string[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ids | string[] | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:downloads.manage。
ctx.downloads.retry
downloads.retry(ids: string[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ids | string[] | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:downloads.manage。
ctx.downloads.reveal
downloads.reveal(id: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:downloads.manage。
ctx.effects
在逻辑实例中登记,停用或卸载时处理自己持有的资源。 相关教程
ctx.effects.add
effects.add(dispose: Disposable): void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
dispose | Disposable | 是 | — | 交给宿主在释放资源时调用的清理函数。 |
返回 void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.entries
核对清单 ID 和 Logic 注册;UI 快照仅传视图显示所需的数据。 相关教程
ctx.entries.invalidate
entries.invalidate(): Promise<void>
无参数。
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.entries.selection
entries.selection(): Promise<SourceSelection>
无参数。
返回 Promise<SourceSelection>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.events
在 Logic 中注册;按操作名核对拦截、观察权限和时限。 相关教程
ctx.events.on
events.on<K extends OperationEventName>(event: K, listener: (value: OperationEvent<K>) => void | Promise<void>): Disposable
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
event | K | 是 | — | 要订阅的事件名,取值由该命名空间的事件类型决定。 |
listener | (value: OperationEvent<K>) => void | Promise<void> | 是 | — | 接收本次订阅通知的函数。 |
返回 Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.events.on
events.on<K extends keyof HostServiceEvents>(event: K, listener: (value: HostServiceEvents[K]) => void, call?: ServiceCall): Disposable
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
event | K | 是 | — | 要订阅的事件名,取值由该命名空间的事件类型决定。 |
listener | (value: HostServiceEvents[K]) => void | 是 | — | 接收本次订阅通知的函数。 |
call | ServiceCall | undefined | 可省略 | 见类型及教程 | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.favorites
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.favorites.contains
favorites.contains(refs: ResourceRef[], call: ServiceCall): Promise<boolean[]>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
refs | ResourceRef[] | 是 | — | 一组原始资源引用,保留顺序与归属。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<boolean[]>
权限与范围:library.read。
ctx.favorites.add
favorites.add(refs: ResourceRef[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
refs | ResourceRef[] | 是 | — | 一组原始资源引用,保留顺序与归属。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:library.write。
ctx.favorites.remove
favorites.remove(refs: ResourceRef[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
refs | ResourceRef[] | 是 | — | 一组原始资源引用,保留顺序与归属。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:library.write。
ctx.files
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.files.pick
files.pick(request: { title?: string; extensions?: string[]; multiple?: boolean; }, operation: OperationContext): Promise<FileHandle[]>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { title?: string; extensions?: string[]; multiple?: boolean; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
operation | OperationContext | 是 | — | 沿用宿主传入的本次操作,传递取消与截止时间。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
title | string | undefined | 可省略 | — |
extensions | string[] | undefined | 可省略 | — |
multiple | boolean | undefined | 可省略 | — |
operation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
deadlineAt | number | 是 | — |
signal | AbortSignal | 是 | — |
connectionId | string | undefined | 可省略 | — |
userIntent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<FileHandle[]>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.files.pickDirectory
files.pickDirectory(operation: OperationContext): Promise<DirectoryHandle | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
operation | OperationContext | 是 | — | 沿用宿主传入的本次操作,传递取消与截止时间。 |
operation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
deadlineAt | number | 是 | — |
signal | AbortSignal | 是 | — |
connectionId | string | undefined | 可省略 | — |
userIntent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<DirectoryHandle | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.files.readText
files.readText(file: FileHandle, call: ServiceCall): Promise<string>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
file | FileHandle | 是 | — | 使用签名要求的文件或句柄。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
file 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
kind | "file" | 是 | — |
id | string | 是 | — |
name | string | 是 | — |
size | number | undefined | 可省略 | — |
mime | string | undefined | 可省略 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<string>
权限与范围:files.read。
ctx.files.readBase64
files.readBase64(file: FileHandle, call: ServiceCall): Promise<string>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
file | FileHandle | 是 | — | 使用签名要求的文件或句柄。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
file 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
kind | "file" | 是 | — |
id | string | 是 | — |
name | string | 是 | — |
size | number | undefined | 可省略 | — |
mime | string | undefined | 可省略 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<string>
权限与范围:files.read。
ctx.files.saveText
files.saveText(request: { suggestedName: string; text: string; }, operation: OperationContext): Promise<FileHandle | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { suggestedName: string; text: string; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
operation | OperationContext | 是 | — | 沿用宿主传入的本次操作,传递取消与截止时间。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
suggestedName | string | 是 | — |
text | string | 是 | — |
operation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
deadlineAt | number | 是 | — |
signal | AbortSignal | 是 | — |
connectionId | string | undefined | 可省略 | — |
userIntent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<FileHandle | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.files.writeText
files.writeText(file: FileHandle, text: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
file | FileHandle | 是 | — | 使用签名要求的文件或句柄。 |
text | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
file 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
kind | "file" | 是 | — |
id | string | 是 | — |
name | string | 是 | — |
size | number | undefined | 可省略 | — |
mime | string | undefined | 可省略 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:files.write。
ctx.guests
管理当前父插件的子项;取消导入和未选中都应有界面反馈。 相关教程
ctx.guests.list
guests.list(): Promise<GuestInfo[]>
无参数。
返回 Promise<GuestInfo[]>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.guests.import
guests.import(adapterId: string): Promise<GuestInfo | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
adapterId | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<GuestInfo | null>
权限与范围:guests.manage。
The Host owns file selection and approval. Cancellation returns null.
ctx.guests.select
guests.select(guestId: string | null): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
guestId | string | null | 是 | — | 已导入的子插件 ID,从当前父插件的管理列表取得。 |
返回 Promise<void>
权限与范围:guests.manage。
ctx.guests.remove
guests.remove(guestId: string): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
guestId | string | 是 | — | 已导入的子插件 ID,从当前父插件的管理列表取得。 |
返回 Promise<void>
权限与范围:guests.manage。
ctx.guests.invoke
guests.invoke(guestId: string, method: string, input: JsonValue, operation: OperationContext): Promise<JsonValue>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
guestId | string | 是 | — | 已导入的子插件 ID,从当前父插件的管理列表取得。 |
method | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
input | JsonValue | 是 | — | 本次动作的数据,结构由对应操作决定。 |
operation | OperationContext | 是 | — | 沿用宿主传入的本次操作,传递取消与截止时间。 |
operation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
deadlineAt | number | 是 | — |
signal | AbortSignal | 是 | — |
connectionId | string | undefined | 可省略 | — |
userIntent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<JsonValue>
权限与范围:guests.run。
ctx.guests.prepareInstall
guests.prepareInstall(request: { adapterId: string; artifactHandle: string; operation: OperationContext; }): Promise<{ draftId: string; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { adapterId: string; artifactHandle: string; operation: OperationContext; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
adapterId | string | 是 | — |
artifactHandle | string | 是 | — |
operation | OperationContext | 是 | — |
返回 Promise<{ draftId: string; }>
权限与范围:按实际使用的宿主能力核对,见对应教程。
Legacy install-draft contract; availability depends on the Host. Prefer import on desktop.
ctx.guests.requestInstall
guests.requestInstall(draftId: string, operation: OperationContext): Promise<{ guestId: string; } | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
draftId | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
operation | OperationContext | 是 | — | 沿用宿主传入的本次操作,传递取消与截止时间。 |
operation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
deadlineAt | number | 是 | — |
signal | AbortSignal | 是 | — |
connectionId | string | undefined | 可省略 | — |
userIntent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<{ guestId: string; } | null>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.history
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.history.list
history.list(cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
cursor | string | undefined | 是 | — | 沿用上一页返回的游标,首次请求按签名传空。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:player.read。
ctx.hooks
在 Logic 中注册;按操作名核对拦截、观察权限和时限。 相关教程
ctx.hooks.on
hooks.on<Name extends HookOperationName>(name: Name, handler: (op: HookContext<Name>, next: (input?: HookInput<Name>) => Promise<HookResult<Name>>) => void | HookResult<Name> | HookInput<Name> | Promise<void | HookResult<Name> | HookInput<Name>>, options?: { priority?: HookPriority; }): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
name | Name | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
handler | (op: HookContext<Name>, next: (input?: HookInput<Name>) => Promise<HookResult<Name>>) => void | HookResult<Name> | HookInput<Name> | Promise<void | HookResult<Name> | HookInput<Name>> | 是 | — | 在对应事件或操作发生时执行的回调。 |
options | { priority?: HookPriority; } | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
options 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
priority | HookPriority | undefined | 可省略 | — |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.hotkeys
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.hotkeys.register
hotkeys.register(request: { id: string; accelerator: string; commandId: string; }, call: ServiceCall): Promise<Disposable>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { id: string; accelerator: string; commandId: string; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
accelerator | string | 是 | — |
commandId | string | 是 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Disposable>
权限与范围:hotkeys.register。
ctx.http
尊重请求取消和来源授权;退出时断开自己创建的连接。 相关教程
ctx.http.create
http.create(options: HttpClientOptions): ReturnType<typeof createHttpClient>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
options | HttpClientOptions | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
options 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
baseURL | string | undefined | 可省略 | — |
headers | Record<string, string> | undefined | 可省略 | — |
permissionKey | string | ((url: URL) => string) | undefined | 可省略 | — |
requestPermission | boolean | undefined | 可省略 | Prompt only when a permission is in the prompt state. Never bypass a denial. |
返回 { request: <T = unknown>(address: string, input: HttpRequestOptions) => Promise<HttpResponse<T>>; authorize: (key: string, _origin: string, operation: OperationContext) => Promise<void>; get<T = unknown>(address: string, input: Omit<HttpRequestOptions, "method">): Promise<T>; post<T = unknown>(address: string, input: Omit<HttpRequestOptions, "method">): Promise<T>; }
权限与范围:按实际使用的宿主能力核对,见对应教程。
Axios-backed Host client with JSON/form helpers and typed results.
ctx.http.request
http.request<Mode extends "arraybuffer" | undefined = undefined>(request: { responseType?: Mode; permissionKey: string; url: string; method?: string; headers?: Record<string, string>; body?: string; timeoutMs?: number; credential?: CredentialRef; operation: OperationContext; }): Promise<{ status: number; headers: Record<string, string>; body: Mode extends "arraybuffer" ? ArrayBuffer : JsonValue; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { responseType?: Mode; permissionKey: string; url: string; method?: string; headers?: Record<string, string>; body?: string; timeoutMs?: number; credential?: CredentialRef; operation: OperationContext; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
responseType | Mode | undefined | 可省略 | — |
permissionKey | string | 是 | — |
url | string | 是 | — |
method | string | undefined | 可省略 | — |
headers | Record<string, string> | undefined | 可省略 | — |
body | string | undefined | 可省略 | — |
timeoutMs | number | undefined | 可省略 | — |
credential | CredentialRef | undefined | 可省略 | — |
operation | OperationContext | 是 | — |
返回 Promise<{ status: number; headers: Record<string, string>; body: Mode extends "arraybuffer" ? ArrayBuffer : JsonValue; }>
权限与范围:network.request。
ctx.icons
只使用宿主公开或插件声明的资源和内置模块。 相关教程
ctx.icons.list
icons.list(): readonly HostIconName[]
无参数。
返回 readonly ("platform.tx" | "platform.kg" | "platform.kw" | "platform.wy" | "platform.mg" | "platform.local" | "platform.all" | "search" | "music-note" | "library" | "cloud" | "server" | "import" | "chart" | "settings" | "play" | "pause" | "download" | "share" | "account" | "heart" | "refresh" | "close" | "add" | "info")[]
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.icons.url
icons.url(name: HostIconName): Promise<string>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
name | "platform.tx" | "platform.kg" | "platform.kw" | "platform.wy" | "platform.mg" | "platform.local" | "platform.all" | "search" | "music-note" | "library" | "cloud" | "server" | "import" | "chart" | "settings" | "play" | "pause" | "download" | "share" | "account" | "heart" | "refresh" | "close" | "add" | "info" | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<string>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.library
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.library.playlists.list
library.playlists.list(request: { location?: PlaylistLocation; cursor?: string; permissionKey: string; operation: OperationContext; }): Promise<Page<LibraryPlaylist>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { location?: PlaylistLocation; cursor?: string; permissionKey: string; operation: OperationContext; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
location | PlaylistLocation | undefined | 可省略 | — |
cursor | string | undefined | 可省略 | — |
permissionKey | string | 是 | — |
operation | OperationContext | 是 | — |
返回 Promise<Page<LibraryPlaylist>>
权限与范围:library.read。
ctx.library.playlists.getTracks
library.playlists.getTracks(request: { target: PlaylistReference; cursor?: string; permissionKey: string; operation: OperationContext; }): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { target: PlaylistReference; cursor?: string; permissionKey: string; operation: OperationContext; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
target | PlaylistReference | 是 | — |
cursor | string | undefined | 可省略 | — |
permissionKey | string | 是 | — |
operation | OperationContext | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:library.read。
ctx.library.playlists.import
library.playlists.import(request: PlaylistImportRequest): Promise<PlaylistImportResult>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | PlaylistImportRequest | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
target | PlaylistReference | undefined | 可省略 | Omit to let the Host show its existing playlist picker/create dialog. |
suggestedName | string | undefined | 可省略 | — |
items | ContentEntity[] | 是 | — |
requestId | string | 是 | Reuse this key when retrying the same batch, so the Host can avoid duplicates. |
permissionKey | string | 是 | — |
operation | OperationContext | 是 | — |
返回 Promise<PlaylistImportResult>
权限与范围:library.write。
Host handles destination selection, auth, deduplication, persistence and cloud sync.
ctx.library.playlists.removeTracks
library.playlists.removeTracks(request: PlaylistRemoveRequest): Promise<PlaylistRemoveResult>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | PlaylistRemoveRequest | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
target | PlaylistReference | 是 | — |
items | ContentEntity[] | 是 | Only `kind: 'track'` entities are accepted. |
permissionKey | string | 是 | — |
operation | OperationContext | 是 | — |
返回 Promise<PlaylistRemoveResult>
权限与范围:library.delete。
Delete tracks from an existing playlist. Requires `library.delete`; never creates or relocates a playlist. `removed + notFound` equals `items.length`.
ctx.library.playlists.clearPlaylist
library.playlists.clearPlaylist(request: { target: PlaylistReference; permissionKey: string; operation: OperationContext; }): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { target: PlaylistReference; permissionKey: string; operation: OperationContext; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
target | PlaylistReference | 是 | — |
permissionKey | string | 是 | — |
operation | OperationContext | 是 | — |
返回 Promise<void>
权限与范围:library.delete。
Empty a playlist while keeping the playlist itself. Requires `library.delete`.
ctx.lifecycle
在逻辑实例中登记,停用或卸载时处理自己持有的资源。 相关教程
ctx.lifecycle.onAppReady
lifecycle.onAppReady(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onInstall
lifecycle.onInstall(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onUninstall
lifecycle.onUninstall(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onEnable
lifecycle.onEnable(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onDisable
lifecycle.onDisable(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onUpdate
lifecycle.onUpdate(handler: (update: { from: string; }) => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | (update: { from: string; }) => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onOnline
lifecycle.onOnline(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onOffline
lifecycle.onOffline(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onLocaleChange
lifecycle.onLocaleChange(handler: (locale: string) => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | (locale: string) => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onBeforeQuit
lifecycle.onBeforeQuit(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onWindowShow
lifecycle.onWindowShow(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onWindowHide
lifecycle.onWindowHide(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onWindowFocus
lifecycle.onWindowFocus(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onWindowBlur
lifecycle.onWindowBlur(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onSuspend
lifecycle.onSuspend(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onResume
lifecycle.onResume(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onLock
lifecycle.onLock(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onUnlock
lifecycle.onUnlock(handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onThemeChange
lifecycle.onThemeChange(handler: (theme: "light" | "dark") => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | (theme: "light" | "dark") => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onConfigChange
lifecycle.onConfigChange(handler: (keys: string[]) => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | (keys: string[]) => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onPermissionChange
lifecycle.onPermissionChange(handler: (keys: string[]) => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | (keys: string[]) => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lifecycle.onIdle
lifecycle.onIdle(milliseconds: number, handler: () => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
milliseconds | number | 是 | — | 单位为毫秒,onIdle 至少 60000。 |
handler | () => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.localMusic
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.localMusic.list
localMusic.list(cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
cursor | string | undefined | 是 | — | 沿用上一页返回的游标,首次请求按签名传空。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:localMusic.read。
ctx.localMusic.scan
localMusic.scan(directories: DirectoryHandle[], call: ServiceCall): Promise<{ taskId: string; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
directories | DirectoryHandle[] | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<{ taskId: string; }>
权限与范围:localMusic.read。
ctx.localMusic.getTags
localMusic.getTags(track: ResourceRef, call: ServiceCall): Promise<JsonObject>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
track | ResourceRef | 是 | — | 保留歌曲身份以及当前接口要求的其他字段。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
track 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<JsonObject>
权限与范围:localMusic.read。
ctx.localMusic.writeTags
localMusic.writeTags(track: ResourceRef, tags: { title?: string; artists?: string[]; album?: string; lyrics?: LyricsDocument; }, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
track | ResourceRef | 是 | — | 保留歌曲身份以及当前接口要求的其他字段。 |
tags | { title?: string; artists?: string[]; album?: string; lyrics?: LyricsDocument; } | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
track 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
tags 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
title | string | undefined | 可省略 | — |
artists | string[] | undefined | 可省略 | — |
album | string | undefined | 可省略 | — |
lyrics | CrLyric | undefined | 可省略 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:localMusic.write。
ctx.log
记录动作名与错误阶段,过滤账号、路径和凭据。 相关教程
ctx.log.debug
log.debug(message: string, data?: JsonValue): void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
message | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
data | JsonValue | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.log.info
log.info(message: string, data?: JsonValue): void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
message | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
data | JsonValue | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.log.warn
log.warn(message: string, data?: JsonValue): void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
message | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
data | JsonValue | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.log.error
log.error(message: string, data?: JsonValue): void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
message | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
data | JsonValue | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lyricConverters
保留歌曲身份,明确毫秒单位和目标格式。 相关教程
ctx.lyricConverters.register
lyricConverters.register(id: string, implementation: LyricConverter): Disposable
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
implementation | LyricConverter | 是 | — | 该扩展点的实现对象;成员决定宿主可以调用哪些回调。 |
返回 Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.modules
只使用宿主公开或插件声明的资源和内置模块。 相关教程
ctx.modules.require
modules.require<K extends keyof BuiltinModules>(name: K): BuiltinModules[K]
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
name | K | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 BuiltinModules[K]
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.music
保存资源引用;解析、播放与搜索可分别失败。 相关教程
ctx.music.sources
music.sources(): Promise<MusicSource[]>
无参数。
返回 Promise<MusicSource[]>
权限与范围:music.read。
ctx.music.search
music.search(sourceId: string, request: SearchRequest, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
sourceId | string | 是 | — | 从可用音源列表取得的来源 ID。 |
request | SearchRequest | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
query | string | 是 | — |
kinds | string[] | 是 | — |
filters | JsonObject | 是 | — |
cursor | string | undefined | 可省略 | — |
limit | number | 是 | Requested size; providers may clamp to their upstream API's supported range. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.suggest
music.suggest(sourceId: string, query: string, call: ServiceCall): Promise<string[]>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
sourceId | string | 是 | — | 从可用音源列表取得的来源 ID。 |
query | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<string[]>
权限与范围:music.read。
ctx.music.hotSearch
music.hotSearch(sourceId: string, call: ServiceCall): Promise<string[]>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
sourceId | string | 是 | — | 从可用音源列表取得的来源 ID。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<string[]>
权限与范围:music.read。
ctx.music.tracks.resolve
music.tracks.resolve(ref: ResourceRef, quality: string | undefined, call: ServiceCall): Promise<ResolveResult>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ref | ResourceRef | 是 | — | 保留来源、种类、稳定 ID 及适用的账号连接。 |
quality | string | undefined | 是 | — | 曲目的音质档位 ID。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
ref 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<ResolveResult>
权限与范围:music.control。
ctx.music.tracks.lyrics
music.tracks.lyrics(ref: ResourceRef, call: ServiceCall): Promise<CrLyric>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ref | ResourceRef | 是 | — | 保留来源、种类、稳定 ID 及适用的账号连接。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
ref 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<CrLyric>
权限与范围:music.read。
ctx.music.tracks.artwork
music.tracks.artwork(ref: ResourceRef, call: ServiceCall): Promise<string | undefined>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ref | ResourceRef | 是 | — | 保留来源、种类、稳定 ID 及适用的账号连接。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
ref 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<string | undefined>
权限与范围:music.read。
ctx.music.playlists.search
music.playlists.search(sourceId: string, request: SearchRequest, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
sourceId | string | 是 | — | 从可用音源列表取得的来源 ID。 |
request | SearchRequest | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
query | string | 是 | — |
kinds | string[] | 是 | — |
filters | JsonObject | 是 | — |
cursor | string | undefined | 可省略 | — |
limit | number | 是 | Requested size; providers may clamp to their upstream API's supported range. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.playlists.categories
music.playlists.categories(sourceId: string, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
sourceId | string | 是 | — | 从可用音源列表取得的来源 ID。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.playlists.list
music.playlists.list(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ref | ResourceRef | 是 | — | 保留来源、种类、稳定 ID 及适用的账号连接。 |
cursor | string | undefined | 是 | — | 沿用上一页返回的游标,首次请求按签名传空。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
ref 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.playlists.get
music.playlists.get(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<PlaylistTrackPage>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ref | ResourceRef | 是 | — | 保留来源、种类、稳定 ID 及适用的账号连接。 |
cursor | string | undefined | 是 | — | 沿用上一页返回的游标,首次请求按签名传空。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
ref 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<PlaylistTrackPage>
权限与范围:music.read。
ctx.music.charts.list
music.charts.list(sourceId: string, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
sourceId | string | 是 | — | 从可用音源列表取得的来源 ID。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.charts.getTracks
music.charts.getTracks(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ref | ResourceRef | 是 | — | 保留来源、种类、稳定 ID 及适用的账号连接。 |
cursor | string | undefined | 是 | — | 沿用上一页返回的游标,首次请求按签名传空。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
ref 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.importers.list
music.importers.list(): Promise<{ id: string; pluginId: string; title: string; description?: string; }[]>
无参数。
返回 Promise<{ id: string; pluginId: string; title: string; description?: string; }[]>
权限与范围:music.read。
ctx.music.importers.parse
music.importers.parse(importerId: string, value: string, cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
importerId | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
value | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
cursor | string | undefined | 是 | — | 沿用上一页返回的游标,首次请求按签名传空。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.play
music.play(ref: ResourceRef, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
ref | ResourceRef | 是 | — | 保留来源、种类、稳定 ID 及适用的账号连接。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
ref 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:music.control。
ctx.music.enqueue
music.enqueue(refs: ResourceRef[], position: "next" | "end", call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
refs | ResourceRef[] | 是 | — | 一组原始资源引用,保留顺序与归属。 |
position | "next" | "end" | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:music.control。
ctx.music.on
music.on(event: "sources.changed", handler: (sources: MusicSource[]) => void): Disposable
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
event | "sources.changed" | 是 | — | 要订阅的事件名,取值由该命名空间的事件类型决定。 |
handler | (sources: MusicSource[]) => void | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.permissions
读写当前插件的数据前,先处理缺失键和旧数据;需要授权的操作使用本次用户意图。 相关教程
ctx.permissions.getGranted
permissions.getGranted(): Promise<PermissionGrant[]>
无参数。
返回 Promise<PermissionGrant[]>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.permissions.requestGroup
permissions.requestGroup(request: PermissionGroupRequest): Promise<PermissionGroupResult>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | PermissionGroupRequest | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
group | "account" | "musicRead" | "musicControl" | "network" | "localServer" | "lanServer" | "audioTransform" | "trustedRuntime" | "localNetwork" | "accountIntercept" | "libraryIntercept" | "searchIntercept" | "searchRead" | "linksRead" | "notificationsRead" | "windowRead" | "libraryRead" | "libraryManage" | "libraryDelete" | "playbackRead" | "navigationRead" | "navigationIntercept" | "playbackIntercept" | "playbackControl" | "downloads" | "files" | "localMusic" | "clipboardRead" | "clipboardWrite" | "notifications" | "external" | "settingsRead" | "settingsWrite" | "window" | "windowIntercept" | "lyricsIntercept" | "downloadsIntercept" | "sharingIntercept" | "linksIntercept" | "notificationsIntercept" | "hotkeys" | "sharing" | "roomsRead" | "roomsControl" | "ai" | "devices" | "uiAppearance" | "background" | "credentials" | "credentialCapture" | "credentialExport" | "guestPlugins" | "services" | 是 | — |
keys | string[] | undefined | 可省略 | Omit to request all statically scoped declarations in this group. |
scopes | Record<string, JsonObject> | undefined | 可省略 | Dynamic scopes keyed by declared permission key. |
intent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<PermissionGroupResult>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.permissions.query
permissions.query(request: { key: string; scope?: JsonObject; }): Promise<{ status: PermissionStatus; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { key: string; scope?: JsonObject; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
key | string | 是 | — |
scope | JsonObject | undefined | 可省略 | — |
返回 Promise<{ status: PermissionStatus; }>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.permissions.request
permissions.request(request: { key: string; scope?: JsonObject; intent?: UserIntentHandle; }): Promise<{ status: PermissionStatus; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { key: string; scope?: JsonObject; intent?: UserIntentHandle; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
key | string | 是 | — |
scope | JsonObject | undefined | 可省略 | — |
intent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<{ status: PermissionStatus; }>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.playback
保存资源引用;解析、播放与搜索可分别失败。 相关教程
ctx.playback.failure
playback.failure(error: MusicFault): ResolveResult
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
error | MusicFault | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
error 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
code | "RATE_LIMITED" | "AUTH_REQUIRED" | "ENTITLEMENT_EXPIRED" | "NOT_FOUND" | "REGION_UNAVAILABLE" | "NETWORK_ERROR" | "PERMISSION_DENIED" | "UNSUPPORTED" | "CANCELLED" | "INTERNAL" | 是 | — |
message | string | 是 | — |
retryAfterMs | number | undefined | 可省略 | — |
retryable | boolean | undefined | 可省略 | — |
recovery | { mode: "default" | "retry-later" | "await-user" | "stop-current"; maxWaitMs?: number; actions?: ({ kind: "retry" | "choose-source" | "cancel"; label?: string; } | { kind: "plugin-command"; commandId: string; label: string; })[]; } | undefined | 可省略 | — |
返回 ResolveResult
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.player
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.player.getState
player.getState(call: ServiceCall): Promise<PlayerState>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<PlayerState>
权限与范围:player.read。
ctx.player.play
player.play(track: ResourceRef | undefined, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
track | ResourceRef | undefined | 是 | — | 保留歌曲身份以及当前接口要求的其他字段。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
track 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:player.control。
ctx.player.pause
player.pause(call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:player.control。
ctx.player.next
player.next(call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:player.control。
ctx.player.previous
player.previous(call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:player.control。
ctx.player.seek
player.seek(positionMs: number, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
positionMs | number | 是 | — | 从曲目开始计算的位置,单位为毫秒。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:player.control。
ctx.player.setVolume
player.setVolume(volume: number, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
volume | number | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:player.control。
ctx.player.setMode
player.setMode(mode: { repeat?: PlayerState["repeat"]; shuffle?: boolean; muted?: boolean; }, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
mode | { repeat?: PlayerState["repeat"]; shuffle?: boolean; muted?: boolean; } | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
mode 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
repeat | "off" | "one" | "all" | undefined | 可省略 | — |
shuffle | boolean | undefined | 可省略 | — |
muted | boolean | undefined | 可省略 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:player.control。
ctx.playlistImporters
登记清单中的导入器 ID;测试空输入、游标和多首结果。 相关教程
ctx.playlistImporters.register
playlistImporters.register(id: string, implementation: PlaylistImporterImplementation): Disposable
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
implementation | PlaylistImporterImplementation | 是 | — | 该扩展点的实现对象;成员决定宿主可以调用哪些回调。 |
返回 Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.plugins
公开服务接受 JSON;检查依赖版本与当前可用性。 相关教程
ctx.plugins.use
plugins.use<T = Record<string, (input: JsonValue) => Promise<JsonValue>>>(pluginId: string, service: string): Promise<T | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
pluginId | string | 是 | — | 目标插件的标识,须符合当前接口的归属或依赖声明。 |
service | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<T | null>
权限与范围:services.consume。
ctx.plugins.list
plugins.list(): Promise<{ pluginId: string; services: ServiceDeclaration[]; }[]>
无参数。
返回 Promise<{ pluginId: string; services: ServiceDeclaration[]; }[]>
权限与范围:services.consume。
ctx.plugins.on
plugins.on(event: "available" | "unavailable", handler: (info: { pluginId: string; service: string; }) => void): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
event | "available" | "unavailable" | 是 | — | 要订阅的事件名,取值由该命名空间的事件类型决定。 |
handler | (info: { pluginId: string; service: string; }) => void | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.providers
保存资源引用;解析、播放与搜索可分别失败。 相关教程
ctx.providers.register
providers.register(id: string, implementation: ProviderImplementation): Disposable
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
implementation | ProviderImplementation | 是 | — | 该扩展点的实现对象;成员决定宿主可以调用哪些回调。 |
implementation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
tracks | TrackProvider | undefined | 可省略 | — |
playlists | PlaylistProvider | undefined | 可省略 | — |
charts | ChartProvider | undefined | 可省略 | — |
sharing | SharingProvider | undefined | 可省略 | — |
返回 Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.queue
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.queue.get
queue.get(call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<QueueState>
权限与范围:player.read。
ctx.queue.append
queue.append(items: ContentEntity[], call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
items | ContentEntity[] | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<QueueState>
权限与范围:player.control。
ctx.queue.replace
queue.replace(items: ContentEntity[], call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
items | ContentEntity[] | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<QueueState>
权限与范围:player.control。
ctx.queue.remove
queue.remove(refs: ResourceRef[], call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
refs | ResourceRef[] | 是 | — | 一组原始资源引用,保留顺序与归属。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<QueueState>
权限与范围:player.control。
ctx.queue.reorder
queue.reorder(refs: ResourceRef[], revision: string, call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
refs | ResourceRef[] | 是 | — | 一组原始资源引用,保留顺序与归属。 |
revision | string | 是 | — | 上一次读取队列时得到的版本;队列变化后重新读取。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<QueueState>
权限与范围:player.control。
ctx.rooms
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.rooms.getState
rooms.getState(call: ServiceCall): Promise<RoomState>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<RoomState>
权限与范围:rooms.read。
ctx.rooms.join
rooms.join(inviteCode: string, call: ServiceCall): Promise<RoomState>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
inviteCode | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<RoomState>
权限与范围:rooms.control。
ctx.rooms.leave
rooms.leave(call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:rooms.control。
ctx.rooms.requestTrack
rooms.requestTrack(track: ResourceRef, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
track | ResourceRef | 是 | — | 保留歌曲身份以及当前接口要求的其他字段。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
track 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
pluginId | string | undefined | 可省略 | Owning plugin for private resources. Public provider-scoped tracks may omit this field so a playlist/search result does not pin playback to its source plugin; the Host fills it in only when invoking a selected implementation. |
providerId | string | 是 | — |
connectionId | string | undefined | 可省略 | — |
kind | string | 是 | — |
id | string | 是 | — |
scope | "provider" | undefined | 可省略 | Public canonical track ID within providerId. Allows the Host's selected resolver. Omit for plugin/account-private IDs. Cannot be combined with connectionId. Cross-plugin calls receive only this public identity, never data. |
data | JsonObject | undefined | 可省略 | Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:rooms.control。
ctx.router
操作使用公开具名页面;检查重复、取消或改向后的结果。 相关教程
ctx.router.beforeEach
router.beforeEach(handler: RouteGuard): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | RouteGuard | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.router.afterEach
router.afterEach(handler: (to: PluginRoute, from: PluginRoute | null) => void | Promise<void>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | (to: PluginRoute, from: PluginRoute | null) => void | Promise<void> | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.router.current
router.current(): Promise<PluginRoute | null>
无参数。
返回 Promise<PluginRoute | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.router.push
router.push(to: PluginRouteTarget): Promise<boolean>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
to | PluginRouteTarget | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<boolean>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.server
仅在能力已获准且资源已声明时启动,停止时释放监听和流。 相关教程
ctx.server.serve
server.serve(handler: ServerHandler, options?: ServerOptions): Promise<ServerHandle>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
handler | ServerHandler | 是 | — | 在对应事件或操作发生时执行的回调。 |
options | ServerOptions | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
options 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
port | number | undefined | 可省略 | — |
lan | boolean | undefined | 可省略 | — |
permissionKey | string | undefined | 可省略 | — |
lanPermissionKey | string | undefined | 可省略 | — |
返回 Promise<ServerHandle>
权限与范围:按实际使用的宿主能力核对,见对应教程。
Starts one HTTP listener per plugin. The Host checks network.serve and any additional LAN permission. Bodies stream in chunks of at most 1 MiB; no more than eight requests may be active in a sandbox at once.
ctx.services
公开服务接受 JSON;检查依赖版本与当前可用性。 相关教程
ctx.services.register
services.register(id: string, handlers: Record<string, ServiceHandler>): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
handlers | Record<string, ServiceHandler> | 是 | — | 以公开方法名为键的服务处理器。 |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.settings
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.settings.get
settings.get(keys: string[], call: ServiceCall): Promise<JsonObject>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
keys | string[] | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<JsonObject>
权限与范围:settings.read。
Only explicit public setting names. Secret/unsafe settings are not part of this API.
ctx.settings.update
settings.update(values: JsonObject, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
values | JsonObject | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:settings.write。
ctx.sharing
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.sharing.create
sharing.create(request: ShareDescriptor, call: ServiceCall): Promise<{ id: string; url: string; expiresAt?: number; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | ShareDescriptor | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
version | 1 | 是 | — |
track | ResourceRef | 是 | — |
title | string | 是 | — |
artists | string[] | 是 | — |
canonicalUrl | string | undefined | 可省略 | — |
resolver | { id: string; resourceId: string; } | undefined | 可省略 | Public resolver identity; never executable plugin code, master keys or auth tokens. |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<{ id: string; url: string; expiresAt?: number; }>
权限与范围:sharing.publish。
ctx.sharing.revoke
sharing.revoke(id: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:sharing.revoke。
ctx.sharing.resolve
sharing.resolve(url: string, operation: OperationContext): Promise<ShareDescriptor>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
url | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
operation | OperationContext | 是 | — | 沿用宿主传入的本次操作,传递取消与截止时间。 |
operation 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
deadlineAt | number | 是 | — |
signal | AbortSignal | 是 | — |
connectionId | string | undefined | 可省略 | — |
userIntent | UserIntentHandle | undefined | 可省略 | — |
返回 Promise<ShareDescriptor>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.sockets
尊重请求取消和来源授权;退出时断开自己创建的连接。 相关教程
ctx.sockets.connect
sockets.connect(options: SocketConnectOptions): Promise<HostSocket>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
options | SocketConnectOptions | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
options 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
permissionKey | string | undefined | 可省略 | Defaults to network.socket. |
operation | OperationContext | 是 | — |
url | string | 是 | wss:// for native WebSocket; https:// for Socket.IO. |
kind | "websocket" | "socket.io" | 是 | — |
path | string | undefined | 可省略 | — |
auth | Record<string, JsonValue> | undefined | 可省略 | — |
reconnection | boolean | undefined | 可省略 | Socket.IO reconnects at most five times. Native WebSocket does not auto-reconnect. |
返回 Promise<HostSocket>
权限与范围:network.socket。
ctx.storage
读写当前插件的数据前,先处理缺失键和旧数据;需要授权的操作使用本次用户意图。 相关教程
ctx.storage.get
storage.get<T extends JsonValue = JsonValue>(key: PluginStorageReadKey): Promise<T | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
key | PluginStorageReadKey | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<T | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
Missing local keys return null. Unauthorized shared reads reject.
ctx.storage.set
storage.set(key: PluginStorageWriteKey, value: JsonValue): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
key | PluginStorageWriteKey | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
value | JsonValue | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.storage.delete
storage.delete(key: PluginStorageReadKey): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
key | PluginStorageReadKey | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.streams
仅在能力已获准且资源已声明时启动,停止时释放监听和流。 相关教程
ctx.streams.registerTransform
streams.registerTransform(id: string, factory: StreamTransformFactory): () => void
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
factory | StreamTransformFactory | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
factory 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
seekable | boolean | 是 | — |
返回 () => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.tasks
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.tasks.schedule
tasks.schedule(request: { id: string; commandId: string; intervalMs: number; }, call: ServiceCall): Promise<{ id: string; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { id: string; commandId: string; intervalMs: number; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
id | string | 是 | — |
commandId | string | 是 | — |
intervalMs | number | 是 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<{ id: string; }>
权限与范围:background.run。
ctx.tasks.cancel
tasks.cancel(id: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:background.run。
ctx.ui
核对清单 ID 和 Logic 注册;UI 快照仅传视图显示所需的数据。 相关教程
ctx.ui.dialogs.confirm
ui.dialogs.confirm(request: { title: string; message: string; confirmText?: string; }): Promise<boolean>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { title: string; message: string; confirmText?: string; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
title | string | 是 | — |
message | string | 是 | — |
confirmText | string | undefined | 可省略 | — |
返回 Promise<boolean>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.dialogs.prompt
ui.dialogs.prompt(request: { title: string; label: string; value?: string; secret?: boolean; }): Promise<string | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { title: string; label: string; value?: string; secret?: boolean; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
title | string | 是 | — |
label | string | 是 | — |
value | string | undefined | 可省略 | — |
secret | boolean | undefined | 可省略 | — |
返回 Promise<string | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.dialogs.pickPlaylist
ui.dialogs.pickPlaylist(request?: { location?: "local" | "cloud"; writable?: boolean; }): Promise<LibraryPlaylist | null>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { location?: "local" | "cloud"; writable?: boolean; } | undefined | 可省略 | 见类型及教程 | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
location | "cloud" | "local" | undefined | 可省略 | — |
writable | boolean | undefined | 可省略 | — |
返回 Promise<LibraryPlaylist | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.navigation.open
ui.navigation.open(request: HostNavigationRequest): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | HostNavigationRequest | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.notifications.show
ui.notifications.show(request: { title: string; body: string; }, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { title: string; body: string; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
title | string | 是 | — |
body | string | 是 | — |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:notifications.system。
ctx.ui.progress.create
ui.progress.create(request: { title: string; cancellable?: boolean; }): Promise<{ id: string; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { title: string; cancellable?: boolean; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
title | string | 是 | — |
cancellable | boolean | undefined | 可省略 | — |
返回 Promise<{ id: string; }>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.progress.update
ui.progress.update(id: string, request: { value?: number; message?: string; }): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
request | { value?: number; message?: string; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
value | number | undefined | 可省略 | — |
message | string | undefined | 可省略 | — |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.progress.close
ui.progress.close(id: string): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
id | string | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.toast
ui.toast(message: { message: string; level?: "info" | "success" | "warning" | "error"; }): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
message | { message: string; level?: "info" | "success" | "warning" | "error"; } | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
message 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
message | string | 是 | — |
level | "info" | "success" | "warning" | "error" | undefined | 可省略 | — |
返回 Promise<void>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.ui.playlistImport.open
ui.playlistImport.open(request: { importerId?: string; initialValue?: string; title?: string; }): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { importerId?: string; initialValue?: string; title?: string; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
importerId | string | undefined | 可省略 | — |
initialValue | string | undefined | 可省略 | — |
title | string | undefined | 可省略 | — |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
Only this plugin's importers are offered. Omit importerId to let the user choose.
ctx.ui.pluginUpdate.request
ui.pluginUpdate.request(request: { version: string; url: string; notes?: string; }): Promise<{ accepted: boolean; updated: boolean; version?: string; queued?: boolean; }>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
request | { version: string; url: string; notes?: string; } | 是 | — | 本次请求的字段组合;展开下方字段表,或到完整类型查其声明。 |
request 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
version | string | 是 | — |
url | string | 是 | — |
notes | string | undefined | 可省略 | — |
返回 Promise<{ accepted: boolean; updated: boolean; version?: string; queued?: boolean; }>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.pages.open
ui.pages.open(pageId: string, props?: JsonObject): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
pageId | string | 是 | — | 清单 ui.pages 中声明的页面 ID。 |
props | JsonObject | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.pages.close
ui.pages.close(pageId: string): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
pageId | string | 是 | — | 清单 ui.pages 中声明的页面 ID。 |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.views.setState
ui.views.setState(viewId: string, state: JsonObject): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
viewId | string | 是 | — | 清单 entry.views 中声明的视图 ID。 |
state | JsonObject | 是 | — | 向视图发送的显示状态,保留界面需要的 JSON 数据。 |
返回 Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.views.on
ui.views.on(event: "mounted" | "unmounted", handler: (info: { viewId: string; instanceId: string; props: JsonObject; }) => void): Disposable
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
event | "mounted" | "unmounted" | 是 | — | 要订阅的事件名,取值由该命名空间的事件类型决定。 |
handler | (info: { viewId: string; instanceId: string; props: JsonObject; }) => void | 是 | — | 在对应事件或操作发生时执行的回调。 |
返回 Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.ui.setState
ui.setState(surfaceId: string, state: JsonObject): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
surfaceId | string | 是 | — | 要操作的视图标识。 |
state | JsonObject | 是 | — | 向视图发送的显示状态,保留界面需要的 JSON 数据。 |
返回 Promise<void>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.ui.notify
ui.notify(message: { key: string; level: "info" | "success" | "warning" | "error"; message: string; }): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
message | { key: string; level: "info" | "success" | "warning" | "error"; message: string; } | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
message 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
key | string | 是 | — |
level | "info" | "success" | "warning" | "error" | 是 | — |
message | string | 是 | — |
返回 Promise<void>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.ui.openView
ui.openView(surfaceId: string): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
surfaceId | string | 是 | — | 要操作的视图标识。 |
返回 Promise<void>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.ui.closeView
ui.closeView(surfaceId: string): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
surfaceId | string | 是 | — | 要操作的视图标识。 |
返回 Promise<void>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.wasm
仅在能力已获准且资源已声明时启动,停止时释放监听和流。 相关教程
ctx.wasm.instantiate
wasm.instantiate(resource: AssetHandle | string, imports?: WebAssembly.Imports): Promise<WebAssembly.WebAssemblyInstantiatedSource>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
resource | string | AssetHandle | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
imports | WebAssembly.Imports | undefined | 可省略 | 见类型及教程 | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
返回 Promise<WebAssembly.WebAssemblyInstantiatedSource>
权限与范围:按实际使用的宿主能力核对,见对应教程。
Instantiate a WebAssembly resource embedded in this plugin's artifact.
ctx.window
先查询宿主是否提供目标方法,修改数据、播放或设备前确认授权及目标对象。 相关教程
ctx.window.control
window.control(action: "show" | "minimize" | "maximize" | "restore" | "mini-player", call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 默认值 | 用法 |
|---|---|---|---|---|
action | "show" | "minimize" | "maximize" | "restore" | "mini-player" | 是 | — | 按本行类型传入;命名类型可在 SDK 声明页查阅 |
call | ServiceCall | 是 | — | 传入本次调用的权限键和操作上下文。 |
call 的对象字段
| 字段 | 类型 | 必填 | SDK 备注 |
|---|---|---|---|
operation | OperationContext | 是 | — |
permissionKey | string | 是 | — |
返回 Promise<void>
权限与范围:window.control。
处理调用失败
有 ServiceCall 参数时,传清单声明的 permissionKey 和当前动作的 operation。查询状态、请求授权、拒绝后的恢复见权限指南。高阶封装、动态操作与本地工具的权限无法只从同名 RPC 推断;方法未列出权限时,请跟随任务索引核对实际行为。宿主能力缺失、撤权、用户取消和参数无效分别处理。操作拦截的时限和副作用按操作目录查。