系统
系统 API 用于发送通知和打开外部链接。
showNotification
发送系统通知,标题缺省使用插件名称。
api.showNotification(body: string, title?: string): Promise<boolean>
const shown = api && api.showNotification
? await api.showNotification('处理完成', '文本工作台')
: false
通知应对应用户能够理解的操作结果,不要用于高频日志输出。
shellOpenExternal
使用系统默认浏览器打开 HTTP(S) 链接。
api.shellOpenExternal(url: string): Promise<boolean>
if (api && api.shellOpenExternal) {
await api.shellOpenExternal('https://toolzen.top/')
}
宿主只接受 http:// 和 https:// 地址。通过 fetch 请求网络时,需要声明 network:fetch 权限并满足 CORS。
showOpenDialog
显示系统文件选择对话框,返回用户选择的路径数组;取消或未声明 file:dialog 时返回空数组。
api.showOpenDialog(options?: {
title?: string
defaultPath?: string
buttonLabel?: string
filters?: Array<{ name: string; extensions: string[] }>
properties?: Array<'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles'>
}): Promise<string[]>
宿主只返回路径,不替插件读取、写入或删除文件。
showSaveDialog
显示系统文件保存对话框,返回用户选择的路径;取消或未声明 file:dialog 时返回空字符串。
api.showSaveDialog(options?: {
title?: string
defaultPath?: string
buttonLabel?: string
filters?: Array<{ name: string; extensions: string[] }>
}): Promise<string>
shellBeep
播放系统提示音。成功返回 true。
api.shellBeep(): Promise<boolean>
应用运行环境
getAppName / getAppVersion
读取宿主应用名称和版本。
api.getAppName(): Promise<string>
api.getAppVersion(): Promise<string>
getPlatform
返回 Electron 的平台标识,例如 win32、darwin、linux。
api.getPlatform(): string
isDev
判断当前是否为本地调试插件。通过开发者专区登记的插件返回 true,商店或远程插件返回 false。
isMacOS / isWindows / isLinux
按当前平台返回布尔值。
api.isMacOS(): boolean
api.isWindows(): boolean
api.isLinux(): boolean