Getting Started
Installation
Section titled âInstallationânpm install @capgo/capacitor-updaternpx cap syncyarn add @capgo/capacitor-updaternpx cap syncpnpm add @capgo/capacitor-updaternpx cap syncbun add @capgo/capacitor-updaternpx cap syncQuick Start
Section titled âQuick StartâFor most users, we recommend following the main Quickstart guide which covers both the plugin installation and Capgo cloud integration.
This getting-started guide focuses on the technical plugin details for advanced users who want to understand the underlying mechanisms or implement self-hosted updates.
Overview
Section titled âOverviewâThe Capacitor Updater plugin enables over-the-air (OTA) updates for your Capacitor applications. This allows you to push updates to your app without going through app store reviews.
How It Works
Section titled âHow It Worksâ- Bundle Download: The plugin downloads update bundles (ZIP files containing your web assets)
- Extraction: Bundles are extracted to the deviceâs storage
- Hot Reload: The app switches to the new bundle without requiring a restart
- Fallback: If an update fails, the app reverts to the previous working version
Usage Modes
Section titled âUsage Modesâ1. Auto-Update Mode (Recommended)
Section titled â1. Auto-Update Mode (Recommended)âThe simplest way to use the plugin with automatic update management:
import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Plugin handles everything automatically// Configure in capacitor.config.tsAdd to your capacitor.config.ts:
{ plugins: { CapacitorUpdater: { autoUpdate: true, updateUrl: 'https://your-update-server.com/api/updates' } }}2. Manual Mode
Section titled â2. Manual ModeâFor advanced control over the update process:
import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Download an updateconst 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 immediatelyawait CapacitorUpdater.reload();Platform Configuration
Section titled âPlatform ConfigurationâNo additional configuration required. The plugin works out of the box.
Android
Section titled âAndroidâNo additional configuration required. The plugin works out of the box.
Basic API Usage
Section titled âBasic API UsageâDownload an Update
Section titled âDownload an Updateâ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 Active Bundle
Section titled âSet Active Bundleâ// Set bundle to be used on next app startawait CapacitorUpdater.set({ id: bundle.id});Reload with New Bundle
Section titled âReload with New Bundleâ// Reload app immediately with new bundleawait CapacitorUpdater.reload();List Bundles
Section titled âList Bundlesâconst { bundles } = await CapacitorUpdater.list();console.log('Available bundles:', bundles);Delete a Bundle
Section titled âDelete a Bundleâawait CapacitorUpdater.delete({ id: 'bundle-id'});Get Current Bundle
Section titled âGet Current Bundleâconst { bundle } = await CapacitorUpdater.current();console.log('Current bundle:', bundle.version);Event Listeners
Section titled âEvent ListenersâListen for update events:
import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Listen for download progressCapacitorUpdater.addListener('download', (info) => { console.log('Download progress:', info.percent);});
// Listen for download completionCapacitorUpdater.addListener('downloadComplete', (bundle) => { console.log('Download complete:', bundle.version);});
// Listen for update failuresCapacitorUpdater.addListener('updateFailed', (error) => { console.error('Update failed:', error);});
// Listen for successful updatesCapacitorUpdater.addListener('updateAvailable', (info) => { console.log('Update available:', info.version);});Configuration Options
Section titled âConfiguration OptionsâConfigure the plugin in your capacitor.config.ts:
{ plugins: { CapacitorUpdater: { // Auto-update settings autoUpdate: true, updateUrl: 'https://api.example.com/updates',
// Update behavior resetWhenUpdate: true, directUpdate: false,
// Version settings version: '1.0.0',
// Security allowModifyUrl: false,
// Stats collection statsUrl: 'https://api.example.com/stats',
// Channel (for Capgo cloud) defaultChannel: 'production' } }}Integration Patterns
Section titled âIntegration PatternsâWith Capgo Cloud
Section titled âWith Capgo CloudâThe easiest way to get started:
// Install the Capgo CLInpm install -g @capgo/cli
// Login to Capgonpx @capgo/cli login
// Upload your first bundlenpx @capgo/cli bundle upload
// The plugin auto-updates from Capgo cloudSee the main Quickstart guide for details.
Self-Hosted Updates
Section titled âSelf-Hosted UpdatesâHost your own update server:
// Configure your update endpoint{ plugins: { CapacitorUpdater: { autoUpdate: true, updateUrl: 'https://your-server.com/api/check-update' } }}Your server should return:
{ "version": "1.0.1", "url": "https://your-server.com/updates/1.0.1.zip"}See Self-Hosted Mode for complete details.
Manual Update Flow
Section titled âManual Update FlowâComplete control over updates:
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();}Best Practices
Section titled âBest Practicesâ- Always call
notifyAppReady()when your app successfully loads - Test updates thoroughly before pushing to production
- Implement proper error handling for network failures
- Use version numbers consistently
- Keep bundle sizes small for faster downloads
- Monitor update success rates
Next Steps
Section titled âNext Stepsâ- Plugin API Reference - Complete API documentation
- Plugin Settings - All configuration options
- Events - Available update events
- Self-Hosted Mode - Run your own update server
- Local Development - Test updates locally
- Debugging - Troubleshooting guide
Support
Section titled âSupportâ- Known Issues - Common problems and solutions
- GitHub Discussions - Community support
- Discord - Real-time chat