完整 API 目录与教程入口
适用读者:需要确认某个 v3 API 是否存在、怎样调用和去哪里学习的作者。前置条件:CLI / SDK 3.0.0。
这一页从当前安装的 SDK 类型和宿主契约生成,覆盖 PluginContext 的全部公开方法。参数字段和嵌套类型继续看逐项方法索引与SDK 原始类型。页面中的方法数量会随 SDK 版本变化,构建时自动更新。
当前目录包含 181 条 SDK 方法签名。相同方法存在重载时,每条签名都会保留。每个命名空间都链接到对应的动手教程。
按方法名筛选
ctx.account
读取澜音账号会话和公开资料。 打开对应教程
ctx.account.getSession
account.getSession(call: ServiceCall): Promise<AccountSession>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<AccountSession>
权限与范围:account.profile。
ctx.account.getProfile
account.getProfile(call: ServiceCall): Promise<AccountProfile | null>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<AccountProfile | null>
权限与范围:account.profile。
ctx.account.openLogin
Opens the application's own account page. Plugins do not implement login or receive its token.
account.openLogin(operation: OperationContext): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
operation | OperationContext | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.accounts
注册第三方账号和上报凭据过期。 打开对应教程
ctx.accounts.current
accounts.current(accountId: string): Promise<{ connectionId: string; expired: boolean; } | null>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
accountId | string | 是 | 字段和约束见类型声明 |
返回值:Promise<{ connectionId: string; expired: boolean; } | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.accounts.reportExpired
accounts.reportExpired(accountId: string, connectionId: string, credential: CredentialRef): Promise<boolean>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
accountId | string | 是 | 字段和约束见类型声明 |
connectionId | string | 是 | 字段和约束见类型声明 |
credential | CredentialRef | 是 | 字段和约束见类型声明 |
返回值:Promise<boolean>
权限与范围:credentials.use。
ctx.accounts.register
accounts.register(id: string, implementation: AccountImplementation): () => void
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
implementation | AccountImplementation | 是 | 字段和约束见类型声明 |
返回值:() => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.actions
把 View 动作连接到 Logic。 打开对应教程
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 | 是 | 字段和约束见类型声明 |
handler | (input: TInput, operation: OperationContext) => MaybePromise<TResult> | 是 | 字段和约束见类型声明 |
返回值:Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.ai
调用宿主 AI 能力。 打开对应教程
ctx.ai.generate
ai.generate(request: { prompt: string; maxOutputChars?: number; }, call: ServiceCall): Promise<{ text: string; }>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | { prompt: string; maxOutputChars?: number; } | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
input | OperationInputs[Name] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<OperationToolResult<Name>>
权限与范围:依当前操作或资源范围决定,见对应任务指南。
ctx.app.getInfo
app.getInfo(): Promise<AppInfo>
无参数。
返回值:Promise<AppInfo>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.app.openSettings
app.openSettings(section?: string): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
section | string | undefined | 可省略 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.app.openExternal
app.openExternal(url: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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" | 是 | 字段和约束见类型声明 |
返回值:Promise<string>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.capabilities
查询服务和可用方法。 打开对应教程
ctx.capabilities.list
capabilities.list(): Promise<ServiceAvailability[]>
无参数。
返回值:Promise<ServiceAvailability[]>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.capabilities.get
capabilities.get(service: string): Promise<ServiceAvailability>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
service | string | 是 | 字段和约束见类型声明 |
返回值:Promise<ServiceAvailability>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.clipboard
读写剪贴板。 打开对应教程
ctx.clipboard.readText
clipboard.readText(call: ServiceCall): Promise<string>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<string>
权限与范围:clipboard.read。
ctx.clipboard.writeText
clipboard.writeText(text: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
text | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
key | string | Uint8Array<ArrayBufferLike> | 是 | 字段和约束见类型声明 |
iv | string | Uint8Array<ArrayBufferLike> | 是 | 字段和约束见类型声明 |
options | CryptoStreamOptions | 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 | 是 | 字段和约束见类型声明 |
key | string | Uint8Array<ArrayBufferLike> | 是 | 字段和约束见类型声明 |
iv | string | Uint8Array<ArrayBufferLike> | 是 | 字段和约束见类型声明 |
options | CryptoStreamOptions | undefined | 可省略 | 字段和约束见类型声明 |
返回值:TransformStream<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.devices
列出和选择播放设备。 打开对应教程
ctx.devices.list
devices.list(call: ServiceCall): Promise<AudioDevice[]>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<AudioDevice[]>
权限与范围:devices.control。
ctx.devices.select
devices.select(id: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:devices.control。
ctx.downloads
管理下载任务。 打开对应教程
ctx.downloads.list
downloads.list(call: ServiceCall): Promise<DownloadTask[]>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
返回值:Promise<DownloadTask[]>
权限与范围:downloads.create。
ctx.downloads.pause
downloads.pause(ids: string[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ids | string[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:downloads.manage。
ctx.downloads.resume
downloads.resume(ids: string[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ids | string[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:downloads.manage。
ctx.downloads.cancel
downloads.cancel(ids: string[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ids | string[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:downloads.manage。
ctx.downloads.retry
downloads.retry(ids: string[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ids | string[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:downloads.manage。
ctx.downloads.reveal
downloads.reveal(id: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:downloads.manage。
ctx.effects
登记清理函数。 打开对应教程
ctx.effects.add
effects.add(dispose: Disposable): void
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
dispose | Disposable | 是 | 字段和约束见类型声明 |
返回值:void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.entries
刷新和读取来源选择。 打开对应教程
ctx.entries.invalidate
entries.invalidate(): Promise<void>
无参数。
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.entries.selection
entries.selection(): Promise<SourceSelection>
无参数。
返回值:Promise<SourceSelection>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.events
订阅宿主事件。 打开对应教程
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 | 可省略 | 字段和约束见类型声明 |
返回值:Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.favorites
管理宿主收藏。 打开对应教程
ctx.favorites.contains
favorites.contains(refs: ResourceRef[], call: ServiceCall): Promise<boolean[]>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
refs | ResourceRef[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<boolean[]>
权限与范围:library.read。
ctx.favorites.add
favorites.add(refs: ResourceRef[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
refs | ResourceRef[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:library.write。
ctx.favorites.remove
favorites.remove(refs: ResourceRef[], call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
refs | ResourceRef[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
返回值:Promise<FileHandle[]>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.files.pickDirectory
files.pickDirectory(operation: OperationContext): Promise<DirectoryHandle | null>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
operation | OperationContext | 是 | 字段和约束见类型声明 |
返回值:Promise<DirectoryHandle | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.files.readText
files.readText(file: FileHandle, call: ServiceCall): Promise<string>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file | FileHandle | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<string>
权限与范围:files.read。
ctx.files.readBase64
files.readBase64(file: FileHandle, call: ServiceCall): Promise<string>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file | FileHandle | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
返回值:Promise<FileHandle | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.files.writeText
files.writeText(file: FileHandle, text: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file | FileHandle | 是 | 字段和约束见类型声明 |
text | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:files.write。
ctx.guests
管理 Guest 子插件。 打开对应教程
ctx.guests.list
guests.list(): Promise<GuestInfo[]>
无参数。
返回值:Promise<GuestInfo[]>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.guests.import
The Host owns file selection and approval. Cancellation returns null.
guests.import(adapterId: string): Promise<GuestInfo | null>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
adapterId | string | 是 | 字段和约束见类型声明 |
返回值:Promise<GuestInfo | null>
权限与范围:guests.manage。
ctx.guests.select
guests.select(guestId: string | null): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
guestId | string | null | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:guests.manage。
ctx.guests.remove
guests.remove(guestId: string): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
guestId | string | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:guests.manage。
ctx.guests.invoke
guests.invoke(guestId: string, method: string, input: JsonValue, operation: OperationContext): Promise<JsonValue>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
guestId | string | 是 | 字段和约束见类型声明 |
method | string | 是 | 字段和约束见类型声明 |
input | JsonValue | 是 | 字段和约束见类型声明 |
operation | OperationContext | 是 | 字段和约束见类型声明 |
返回值:Promise<JsonValue>
权限与范围:guests.run。
ctx.guests.prepareInstall
Legacy install-draft contract; availability depends on the Host. Prefer import on desktop.
guests.prepareInstall(request: { adapterId: string; artifactHandle: string; operation: OperationContext; }): Promise<{ draftId: string; }>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | { adapterId: string; artifactHandle: string; operation: OperationContext; } | 是 | 字段和约束见类型声明 |
返回值:Promise<{ draftId: string; }>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.guests.requestInstall
guests.requestInstall(draftId: string, operation: OperationContext): Promise<{ guestId: string; } | null>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
draftId | string | 是 | 字段和约束见类型声明 |
operation | OperationContext | 是 | 字段和约束见类型声明 |
返回值:Promise<{ guestId: string; } | null>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.history
读取播放历史。 打开对应教程
ctx.history.list
history.list(cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
cursor | string | undefined | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:player.read。
ctx.hooks
拦截、放行或改写操作。 打开对应教程
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 | 是 | 字段和约束见类型声明 |
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 | 可省略 | 字段和约束见类型声明 |
返回值:() => 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 | 是 | 字段和约束见类型声明 |
返回值:Promise<Disposable>
权限与范围:hotkeys.register。
ctx.http
请求 HTTP 服务。 打开对应教程
ctx.http.create
Axios-backed Host client with JSON/form helpers and typed results.
http.create(options: HttpClientOptions): ReturnType<typeof createHttpClient>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
options | HttpClientOptions | 是 | 字段和约束见类型声明 |
返回值:{ 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>; }
权限与范围:按实际使用的宿主能力核对,见对应教程。
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; } | 是 | 字段和约束见类型声明 |
返回值: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" | 是 | 字段和约束见类型声明 |
返回值: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; } | 是 | 字段和约束见类型声明 |
返回值: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; } | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:library.read。
ctx.library.playlists.import
Host handles destination selection, auth, deduplication, persistence and cloud sync.
library.playlists.import(request: PlaylistImportRequest): Promise<PlaylistImportResult>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | PlaylistImportRequest | 是 | 字段和约束见类型声明 |
返回值:Promise<PlaylistImportResult>
权限与范围:library.write。
ctx.library.playlists.removeTracks
Delete tracks from an existing playlist. Requires `library.delete`; never creates or relocates a playlist. `removed + notFound` equals `items.length`.
library.playlists.removeTracks(request: PlaylistRemoveRequest): Promise<PlaylistRemoveResult>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | PlaylistRemoveRequest | 是 | 字段和约束见类型声明 |
返回值:Promise<PlaylistRemoveResult>
权限与范围:library.delete。
ctx.library.playlists.clearPlaylist
Empty a playlist while keeping the playlist itself. Requires `library.delete`.
library.playlists.clearPlaylist(request: { target: PlaylistReference; permissionKey: string; operation: OperationContext; }): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | { target: PlaylistReference; permissionKey: string; operation: OperationContext; } | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围: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 | 是 | 字段和约束见类型声明 |
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 | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:localMusic.read。
ctx.localMusic.scan
localMusic.scan(directories: DirectoryHandle[], call: ServiceCall): Promise<{ taskId: string; }>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
directories | DirectoryHandle[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<{ taskId: string; }>
权限与范围:localMusic.read。
ctx.localMusic.getTags
localMusic.getTags(track: ResourceRef, call: ServiceCall): Promise<JsonObject>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
track | ResourceRef | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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; } | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:localMusic.write。
ctx.log
记录可脱敏日志。 打开对应教程
ctx.log.debug
log.debug(message: string, data?: JsonValue): void
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
message | string | 是 | 字段和约束见类型声明 |
data | JsonValue | undefined | 可省略 | 字段和约束见类型声明 |
返回值:void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.log.info
log.info(message: string, data?: JsonValue): void
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
message | string | 是 | 字段和约束见类型声明 |
data | JsonValue | undefined | 可省略 | 字段和约束见类型声明 |
返回值:void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.log.warn
log.warn(message: string, data?: JsonValue): void
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
message | string | 是 | 字段和约束见类型声明 |
data | JsonValue | undefined | 可省略 | 字段和约束见类型声明 |
返回值:void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.log.error
log.error(message: string, data?: JsonValue): void
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
message | string | 是 | 字段和约束见类型声明 |
data | JsonValue | undefined | 可省略 | 字段和约束见类型声明 |
返回值:void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.lyricConverters
注册歌词转换器。 打开对应教程
ctx.lyricConverters.register
lyricConverters.register(id: string, implementation: LyricConverter): Disposable
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
implementation | LyricConverter | 是 | 字段和约束见类型声明 |
返回值:Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.modules
加载兼容模块。 打开对应教程
ctx.modules.require
modules.require<K extends keyof BuiltinModules>(name: K): BuiltinModules[K]
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
name | K | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
request | SearchRequest | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.suggest
music.suggest(sourceId: string, query: string, call: ServiceCall): Promise<string[]>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
sourceId | string | 是 | 字段和约束见类型声明 |
query | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<string[]>
权限与范围:music.read。
ctx.music.hotSearch
music.hotSearch(sourceId: string, call: ServiceCall): Promise<string[]>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
sourceId | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<string[]>
权限与范围:music.read。
ctx.music.tracks.resolve
music.tracks.resolve(ref: ResourceRef, quality: string | undefined, call: ServiceCall): Promise<ResolveResult>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ref | ResourceRef | 是 | 字段和约束见类型声明 |
quality | string | undefined | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<ResolveResult>
权限与范围:music.control。
ctx.music.tracks.lyrics
music.tracks.lyrics(ref: ResourceRef, call: ServiceCall): Promise<CrLyric>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ref | ResourceRef | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<CrLyric>
权限与范围:music.read。
ctx.music.tracks.artwork
music.tracks.artwork(ref: ResourceRef, call: ServiceCall): Promise<string | undefined>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ref | ResourceRef | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<string | undefined>
权限与范围:music.read。
ctx.music.playlists.search
music.playlists.search(sourceId: string, request: SearchRequest, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
sourceId | string | 是 | 字段和约束见类型声明 |
request | SearchRequest | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.playlists.categories
music.playlists.categories(sourceId: string, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
sourceId | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.playlists.list
music.playlists.list(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ref | ResourceRef | 是 | 字段和约束见类型声明 |
cursor | string | undefined | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.playlists.get
music.playlists.get(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<PlaylistTrackPage>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ref | ResourceRef | 是 | 字段和约束见类型声明 |
cursor | string | undefined | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<PlaylistTrackPage>
权限与范围:music.read。
ctx.music.charts.list
music.charts.list(sourceId: string, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
sourceId | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.charts.getTracks
music.charts.getTracks(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ref | ResourceRef | 是 | 字段和约束见类型声明 |
cursor | string | undefined | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
value | string | 是 | 字段和约束见类型声明 |
cursor | string | undefined | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<Page<ContentEntity>>
权限与范围:music.read。
ctx.music.play
music.play(ref: ResourceRef, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ref | ResourceRef | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:music.control。
ctx.music.enqueue
music.enqueue(refs: ResourceRef[], position: "next" | "end", call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
refs | ResourceRef[] | 是 | 字段和约束见类型声明 |
position | "next" | "end" | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
返回值:Promise<PermissionGroupResult>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.permissions.query
permissions.query(request: { key: string; scope?: JsonObject; }): Promise<{ status: PermissionStatus; }>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | { key: string; scope?: JsonObject; } | 是 | 字段和约束见类型声明 |
返回值: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; } | 是 | 字段和约束见类型声明 |
返回值:Promise<{ status: PermissionStatus; }>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.playback
处理播放失败。 打开对应教程
ctx.playback.failure
playback.failure(error: MusicFault): ResolveResult
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
error | MusicFault | 是 | 字段和约束见类型声明 |
返回值:ResolveResult
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.player
控制播放器。 打开对应教程
ctx.player.getState
player.getState(call: ServiceCall): Promise<PlayerState>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<PlayerState>
权限与范围:player.read。
ctx.player.play
player.play(track: ResourceRef | undefined, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
track | ResourceRef | undefined | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:player.control。
ctx.player.pause
player.pause(call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:player.control。
ctx.player.next
player.next(call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:player.control。
ctx.player.previous
player.previous(call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:player.control。
ctx.player.seek
player.seek(positionMs: number, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
positionMs | number | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:player.control。
ctx.player.setVolume
player.setVolume(volume: number, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
volume | number | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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; } | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:player.control。
ctx.playlistImporters
注册歌单导入器。 打开对应教程
ctx.playlistImporters.register
playlistImporters.register(id: string, implementation: PlaylistImporterImplementation): Disposable
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
implementation | PlaylistImporterImplementation | 是 | 字段和约束见类型声明 |
返回值:Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.plugins
使用其他插件服务。 打开对应教程
ctx.plugins.use
plugins.use<T = Record<string, (input: JsonValue) => Promise<JsonValue>>>(pluginId: string, service: string): Promise<T | null>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
pluginId | string | 是 | 字段和约束见类型声明 |
service | string | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
implementation | ProviderImplementation | 是 | 字段和约束见类型声明 |
返回值:Disposable
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.queue
管理播放队列。 打开对应教程
ctx.queue.get
queue.get(call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<QueueState>
权限与范围:player.read。
ctx.queue.append
queue.append(items: ContentEntity[], call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
items | ContentEntity[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<QueueState>
权限与范围:player.control。
ctx.queue.replace
queue.replace(items: ContentEntity[], call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
items | ContentEntity[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<QueueState>
权限与范围:player.control。
ctx.queue.remove
queue.remove(refs: ResourceRef[], call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
refs | ResourceRef[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<QueueState>
权限与范围:player.control。
ctx.queue.reorder
queue.reorder(refs: ResourceRef[], revision: string, call: ServiceCall): Promise<QueueState>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
refs | ResourceRef[] | 是 | 字段和约束见类型声明 |
revision | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<QueueState>
权限与范围:player.control。
ctx.rooms
管理多人房间。 打开对应教程
ctx.rooms.getState
rooms.getState(call: ServiceCall): Promise<RoomState>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<RoomState>
权限与范围:rooms.read。
ctx.rooms.join
rooms.join(inviteCode: string, call: ServiceCall): Promise<RoomState>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
inviteCode | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<RoomState>
权限与范围:rooms.control。
ctx.rooms.leave
rooms.leave(call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:rooms.control。
ctx.rooms.requestTrack
rooms.requestTrack(track: ResourceRef, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
track | ResourceRef | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
返回值:Promise<boolean>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.server
启动本机服务。 打开对应教程
ctx.server.serve
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.
server.serve(handler: ServerHandler, options?: ServerOptions): Promise<ServerHandle>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
handler | ServerHandler | 是 | 字段和约束见类型声明 |
options | ServerOptions | undefined | 可省略 | 字段和约束见类型声明 |
返回值:Promise<ServerHandle>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.services
提供插件服务。 打开对应教程
ctx.services.register
services.register(id: string, handlers: Record<string, ServiceHandler>): () => void
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
handlers | Record<string, ServiceHandler> | 是 | 字段和约束见类型声明 |
返回值:() => void
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.settings
读写宿主设置。 打开对应教程
ctx.settings.get
Only explicit public setting names. Secret/unsafe settings are not part of this API.
settings.get(keys: string[], call: ServiceCall): Promise<JsonObject>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
keys | string[] | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<JsonObject>
权限与范围:settings.read。
ctx.settings.update
settings.update(values: JsonObject, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
values | JsonObject | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
返回值:Promise<{ id: string; url: string; expiresAt?: number; }>
权限与范围:sharing.publish。
ctx.sharing.revoke
sharing.revoke(id: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:sharing.revoke。
ctx.sharing.resolve
sharing.resolve(url: string, operation: OperationContext): Promise<ShareDescriptor>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | string | 是 | 字段和约束见类型声明 |
operation | OperationContext | 是 | 字段和约束见类型声明 |
返回值:Promise<ShareDescriptor>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.sockets
连接实时服务。 打开对应教程
ctx.sockets.connect
sockets.connect(options: SocketConnectOptions): Promise<HostSocket>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
options | SocketConnectOptions | 是 | 字段和约束见类型声明 |
返回值:Promise<HostSocket>
权限与范围:network.socket。
ctx.storage
保存和迁移数据。 打开对应教程
ctx.storage.get
Missing local keys return null. Unauthorized shared reads reject.
storage.get<T extends JsonValue = JsonValue>(key: PluginStorageReadKey): Promise<T | null>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
key | PluginStorageReadKey | 是 | 字段和约束见类型声明 |
返回值:Promise<T | null>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.storage.set
storage.set(key: PluginStorageWriteKey, value: JsonValue): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
key | PluginStorageWriteKey | 是 | 字段和约束见类型声明 |
value | JsonValue | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.storage.delete
storage.delete(key: PluginStorageReadKey): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
key | PluginStorageReadKey | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.streams
注册媒体流变换器。 打开对应教程
ctx.streams.registerTransform
streams.registerTransform(id: string, factory: StreamTransformFactory): () => void
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
factory | StreamTransformFactory | 是 | 字段和约束见类型声明 |
返回值:() => 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 | 是 | 字段和约束见类型声明 |
返回值:Promise<{ id: string; }>
权限与范围:background.run。
ctx.tasks.cancel
tasks.cancel(id: string, call: ServiceCall): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:background.run。
ctx.ui
管理页面、通知和进度。 打开对应教程
ctx.ui.dialogs.confirm
ui.dialogs.confirm(request: { title: string; message: string; confirmText?: string; }): Promise<boolean>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | { title: string; message: string; confirmText?: string; } | 是 | 字段和约束见类型声明 |
返回值: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; } | 是 | 字段和约束见类型声明 |
返回值: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 | 可省略 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:notifications.system。
ctx.ui.progress.create
ui.progress.create(request: { title: string; cancellable?: boolean; }): Promise<{ id: string; }>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | { title: string; cancellable?: boolean; } | 是 | 字段和约束见类型声明 |
返回值:Promise<{ id: string; }>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.progress.update
ui.progress.update(id: string, request: { value?: number; message?: string; }): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
request | { value?: number; message?: string; } | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.progress.close
ui.progress.close(id: string): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 字段和约束见类型声明 |
返回值: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"; } | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:按实际使用的宿主能力核对,见对应教程。
ctx.ui.playlistImport.open
Only this plugin's importers are offered. Omit importerId to let the user choose.
ui.playlistImport.open(request: { importerId?: string; initialValue?: string; title?: string; }): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
request | { importerId?: string; initialValue?: string; title?: string; } | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
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; } | 是 | 字段和约束见类型声明 |
返回值:Promise<{ accepted: boolean; updated: boolean; version?: string; queued?: boolean; }>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.pages.open
ui.pages.open(pageId: string, props?: JsonObject): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
pageId | string | 是 | 字段和约束见类型声明 |
props | JsonObject | undefined | 可省略 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.pages.close
ui.pages.close(pageId: string): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
pageId | string | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:此调用没有独立权限,宿主仍检查归属与输入。
ctx.ui.views.setState
ui.views.setState(viewId: string, state: JsonObject): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
viewId | string | 是 | 字段和约束见类型声明 |
state | JsonObject | 是 | 字段和约束见类型声明 |
返回值: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 | 是 | 字段和约束见类型声明 |
返回值: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; } | 是 | 字段和约束见类型声明 |
返回值: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
加载 WASM 能力。 打开对应教程
ctx.wasm.instantiate
Instantiate a WebAssembly resource embedded in this plugin's artifact.
wasm.instantiate(resource: AssetHandle | string, imports?: WebAssembly.Imports): Promise<WebAssembly.WebAssemblyInstantiatedSource>
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
resource | string | AssetHandle | 是 | 字段和约束见类型声明 |
imports | WebAssembly.Imports | undefined | 可省略 | 字段和约束见类型声明 |
返回值:Promise<WebAssembly.WebAssemblyInstantiatedSource>
权限与范围:按实际使用的宿主能力核对,见对应教程。
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" | 是 | 字段和约束见类型声明 |
call | ServiceCall | 是 | 字段和约束见类型声明 |
返回值:Promise<void>
权限与范围:window.control。
不属于 ctx 方法的公开入口
方法目录只展开 PluginContext 的可调用成员。下面这些导出同样属于 SDK 公共 API,分别在对应教程和类型页说明:
| 入口 | 用途 | 教程 |
|---|---|---|
| definePlugin | 定义 Logic 入口,接收 PluginContext 或生命周期选项对象 | 生命周期 |
| defineSurface | 定义隔离 Web 页面入口,接收 SurfaceContext | 隔离 HTML 页面 |
| defineNativeView、assertNativeView | 定义并校验宿主原生视图数据 | 原生歌单与动作 |
| defineGuestAdapter | 定义 Guest bootstrap 入口 | Guest 兼容环境 |
| defineManifest | 对清单对象提供类型约束 | Manifest 与页面入口 |
| definePluginConfig | 对插件配置对象提供类型推断 | 配置、存储与升级 |
| defineUISchema | 对兼容 UI Schema 提供类型约束 | SDK 类型与方法签名 |
| failure | 构造音源解析失败结果 | 歌曲引用、歌词与音质 |
| Vue hooks 和区域 hooks | 在 Vue 组件中读取动作、状态、宿主组件和播放区域 | Vue hooks 与宿主组件 |
ctx.plugin、ctx.host 和 ctx.utils.lodash 是只读属性,不会在方法目录中重复计数。SurfaceContext、GuestContext 和 Provider、Native View 的上下文也不是 PluginContext 方法,它们的完整签名在SDK 类型中按类型展开。
歌单 API 快速定位
歌单能力分布在两层。ctx.library.playlists 负责读取、导入、移除歌曲和清空歌单。创建歌单、删除歌单、向指定歌单添加或移除歌曲属于宿主操作,需要通过 ctx.app.call 调用。完整代码见本地歌单 API 实战。
| 需求 | 方法 |
|---|---|
| 查询本地歌单 | ctx.library.playlists.list |
| 获取歌单中的歌曲 | ctx.library.playlists.getTracks |
| 创建本地歌单 | ctx.app.call('playlist.create', ...) |
| 添加歌曲 | ctx.app.call('playlist.addTracks', ...) |
| 移除歌曲 | ctx.app.call('playlist.removeTracks', ...) |
| 清空但保留歌单 | ctx.library.playlists.clearPlaylist |
| 删除歌单 | ctx.app.call('playlist.delete', ...) |
| 修改名称、描述或封面 | 当前 v3 SDK 没有公开插件 API |