Lompat ke Konten

Getting Started

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

Instalasi
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Lalu gunakan prompt berikut:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-auto` plugin in my project.

Jika Anda lebih suka Setup Manual, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah ini:

  1. Instal paket

    Jendela terminal
    npm i @capgo/capacitor-auto
  2. Sinkronkan proyek native

    Jendela terminal
    npx cap sync
  3. Atur template root car

    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' },
    },
    ],
    },
    ],
    });
  4. Aktifkan aksi mobil

    await Auto.addListener('carAction', async (event) => {
    if (event.id === 'open-main-door') {
    await openGarageDoor(event.payload?.doorId);
    }
    });
  5. Monitor status koneksi

    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);
    });

Atur emptyText ketika template tidak memiliki baris:

await Auto.setRootTemplate({
title: 'Garage',
emptyText: 'No actions are available right now.',
sections: [],
});

Pilih sendMessage untuk pesan jembatan native yang ditentukan aplikasi:

await Auto.sendMessage({
type: 'status',
payload: { online: true },
});

Jika Anda menggunakan Getting Started untuk merencanakan kerja plugin native, hubungkannya dengan Menggunakan @capgo/capacitor-auto untuk kemampuan native dalam Menggunakan @capgo/capacitor-auto, Capgo Direktori Plugin untuk alur kerja produk dalam Capgo Direktori Plugin, Capacitor Plugin oleh Capgo untuk detail implementasi dalam Capacitor Plugin oleh Capgo, Mengambah atau Mengupdate Plugin untuk detail implementasi di Mengambah atau Mengupdate Plugin, dan Alternatif Plugin Enterprise Ionic untuk alur kerja produk di Alternatif Plugin Enterprise Ionic.