Hybrid update
When pushing updates to your user you have a few ways to deal with the update cycle as you see fit before applying them.
- Silent update
- Listen for
updateAvailableevent - Show a modal window or delay updates
Silent update
You can force an update cycle to happen at every app start by setting autoUpdate to "always",
this will trigger the update cycle as usual without the user interaction.
// capacitor.config.json{ "appId": "**.***.**", "appName": "Name", "plugins": { "CapacitorUpdater": { "autoUpdate": "always", }, "SplashScreen": { "launchAutoHide": false, } }}And then in your app, you should hide the splash screen when you receive the event appReady:
import { CapacitorUpdater } from '@capgo/capacitor-updater'import { SplashScreen } from '@capacitor/splash-screen'
CapacitorUpdater.addListener('appReady', () => { // Hide splash SplashScreen.hide()})
CapacitorUpdater.notifyAppReady()Force update
Use "onlyDownload" if you want the plugin to download updates automatically, then add a listener to the event updateAvailable and show an alert to let the user know the app will update:
// capacitor.config.json{ "plugins": { "CapacitorUpdater": { "autoUpdate": "onlyDownload" } }}import { CapacitorUpdater } from '@capgo/capacitor-updater'import { Dialog } from '@capacitor/dialog'
CapacitorUpdater.addListener('updateAvailable', async (res) => { try { await Dialog.alert({ title: 'Update Available', message: `Version ${res.bundle.version} is available. The app will update now`, }) CapacitorUpdater.set(res.bundle) } catch (error) { console.log(error) }})
CapacitorUpdater.notifyAppReady()Modal update
You can also let the user decide by showing a dialog to ask them to update:
import { CapacitorUpdater } from '@capgo/capacitor-updater'import { Dialog } from '@capacitor/dialog'
CapacitorUpdater.addListener('updateAvailable', async (res) => { try { const { value } = await Dialog.confirm({ title: 'Update Available', message: `Version ${res.bundle.version} is available. Would you like to update now?`, })
if (value) CapacitorUpdater.set(res.bundle)
} catch (error) { console.log(error) }})
CapacitorUpdater.notifyAppReady()