开始入门
复制一个设置提示,包含安装步骤和此插件的完整 Markdown 指南。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-auto`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/auto/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
标题为“安装”您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 Capgo 技能添加到您的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-auto` plugin in my project.如果您更喜欢手动设置,请运行以下命令安装插件,并遵循以下平台特定的说明:
-
安装包
终端窗口 npm i @capgo/capacitor-auto -
同步本机项目
终端窗口 npx cap sync -
设置根级车模板
import { Auto } from '@capgo/capacitor-auto';await Auto.setRootTemplate({title: 'Garage',sections: [{header: 'Doors',items: [{id: 'open-main-door',title: 'Open main door',subtitle: 'Tap to send the action to the phone app',payload: { doorId: 'main' },},],},],}); -
处理车辆动作
await Auto.addListener('carAction', async (event) => {if (event.id === 'open-main-door') {await openGarageDoor(event.payload?.doorId);}}); -
跟踪连接状态
const status = await Auto.isAvailable();console.log(status.available, status.connected, status.platform);await Auto.addListener('connectionChanged', (event) => {console.log('Car connected:', event.connected, event.platform);});
空状态
标题:空状态设置 emptyText 当模板没有行时:
await Auto.setRootTemplate({ title: 'Garage', emptyText: 'No actions are available right now.', sections: [],});发送桥消息
标题:发送桥消息使用 sendMessage 用于应用定义的本机桥消息:
await Auto.sendMessage({ type: 'status', payload: { online: true },});平台设置
平台设置继续从Getting Started
如果您正在使用Getting Started 来规划原生插件工作,连接它 to plan native plugin work, connect it with 使用 @capgo/capacitor-auto 用于本地能力的 @capgo/capacitor-auto Capgo 插件目录 用于产品工作流程的 Capgo 插件目录 Capacitor 由 Capgo 提供的插件 用于实现细节的 Capacitor 由 Capgo 提供的插件 添加或更新插件 用于实现细节的添加或更新插件 Ionic 企业插件替代品 用于产品工作流程的 Ionic 企业插件替代品