Lompat ke Konten

Getting Started

GitHub

Anda dapat menggunakan Pengaturan Bantu AI untuk menginstal plugin. Tambahkan kemampuan Capgo ke alat AI Anda menggunakan perintah berikut:

Jendela Terminal
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-updater` plugin in my project.

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

Jendela Terminal
bun add @capgo/capacitor-updater
bunx cap sync

Bagian ini tidak perlu dilakukan oleh pengguna biasa, karena kami sarankan mengikuti petunjuk utama Mulai Cepat yang mencakup instalasi plugin dan Capgo integrasi cloud.

Petunjuk Mulai Cepat ini fokus pada detail teknis plugin untuk pengguna lanjutan yang ingin memahami mekanisme yang lebih dalam atau mengimplementasikan pembaruan mandiri.

Plugin pembaruan Capacitor memungkinkan pembaruan perangkat lunak secara nirkabel (OTA) untuk aplikasi Capacitor Anda. Ini memungkinkan Anda untuk membarui aplikasi tanpa harus melewati tinjauan toko aplikasi.

  1. Download Paket: Plugin ini mengunduh bundle pembaruan (file ZIP yang berisi aset web Anda)
  2. Ekstraksi: Bundle dibongkar ke penyimpanan perangkat
  3. Hot Reload: Aplikasi beralih ke bundle baru tanpa memerlukan restart
  4. Fallback: Jika pembaruan gagal, aplikasi kembali ke versi kerja sebelumnya

Cara termudah untuk menggunakan plugin dengan manajemen pembaruan otomatis:

import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Plugin handles everything automatically
// Configure in capacitor.config.ts

Tambahkan ke capacitor.config.ts:

{
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
updateUrl: 'https://your-update-server.com/api/updates'
}
}
}

Untuk kendali lanjutan atas proses pembaruan:

import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Download an update
const bundle = await CapacitorUpdater.download({
url: 'https://your-server.com/updates/v1.0.1.zip',
version: '1.0.1'
});
// Set the bundle (will be used on next app start)
await CapacitorUpdater.set({
id: bundle.id
});
// Or reload immediately
await CapacitorUpdater.reload();

Tidak diperlukan konfigurasi tambahan. Plugin ini berfungsi secara otomatis.

Tidak perlu pengaturan tambahan. Plugin ini berfungsi secara otomatis.

import { CapacitorUpdater } from '@capgo/capacitor-updater';
const bundle = await CapacitorUpdater.download({
url: 'https://example.com/update.zip',
version: '1.0.1'
});
console.log('Downloaded bundle:', bundle.id);
// Set bundle to be used on next app start
await CapacitorUpdater.set({
id: bundle.id
});
// Reload app immediately with new bundle
await CapacitorUpdater.reload();
const { bundles } = await CapacitorUpdater.list();
console.log('Available bundles:', bundles);
await CapacitorUpdater.delete({
id: 'bundle-id'
});
const { bundle } = await CapacitorUpdater.current();
console.log('Current bundle:', bundle.version);

Dengarkan event pembaruan:

import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Listen for download progress
CapacitorUpdater.addListener('download', (info) => {
console.log('Download progress:', info.percent);
});
// Listen for download completion
CapacitorUpdater.addListener('downloadComplete', (bundle) => {
console.log('Download complete:', bundle.version);
});
// Listen for update failures
CapacitorUpdater.addListener('updateFailed', (error) => {
console.error('Update failed:', error);
});
// Listen for successful updates
CapacitorUpdater.addListener('updateAvailable', (info) => {
console.log('Update available:', info.version);
});

Konfigurasi plugin di capacitor.config.ts:

{
plugins: {
CapacitorUpdater: {
// Auto-update settings
autoUpdate: 'atBackground',
updateUrl: 'https://api.example.com/updates',
// Update behavior
resetWhenUpdate: true,
// Version settings
version: '1.0.0',
// Security
allowModifyUrl: false,
// Stats collection
statsUrl: 'https://api.example.com/stats',
// Channel (for Capgo cloud)
defaultChannel: 'production'
}
}
}

Cara termudah untuk memulai:

// Install the Capgo CLI
bun add -g @capgo/cli
// Login to Capgo
npx @capgo/cli login
// Upload your first bundle
npx @capgo/cli bundle upload
// The plugin auto-updates from Capgo cloud

Lihat panduan Quickstart utama untuk informasi lebih lanjut. Pembaruan Otomatis Sendiri

Bab berjudul “Pembaruan Otomatis Sendiri”

Tetapkan server pembaruan Anda sendiri:

Copas ke clipboard

// Configure your update endpoint
{
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
updateUrl: 'https://your-server.com/api/check-update'
}
}
}

Copas ke clipboard

{
"version": "1.0.1",
"url": "https://your-server.com/updates/1.0.1.zip"
}

Pembaruan Otomatis Pembaruan Otomatis Sendiri untuk detail lengkap.

Kontrol lengkap atas pembaruan:

import { CapacitorUpdater } from '@capgo/capacitor-updater';
async function checkAndUpdate() {
// Check for updates from your server
const response = await fetch('https://api.example.com/check-update');
const { version, url } = await response.json();
// Download the update
const bundle = await CapacitorUpdater.download({
url,
version
});
// Notify bundle is ready
await CapacitorUpdater.notifyAppReady();
// Set as next version
await CapacitorUpdater.set({ id: bundle.id });
// Reload when ready
await CapacitorUpdater.reload();
}
  • Selalu panggil notifyAppReady() ketika aplikasi Anda berhasil dimuat
  • Tes pembaruan secara menyeluruh sebelum memasukkannya ke produksi
  • Implementasikan penanganan kesalahan yang tepat untuk gagal jaringan
  • Gunakan nomor versi secara konsisten
  • Pastikan ukuran bundle tetap kecil untuk download yang lebih cepat
  • Pantau tingkat kesuksesan update

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