コンテンツにスキップ

Manual

このコンテンツはまだ日本語訳がありません。

Before start

Quick install

npm install @capgo/capacitor-updater
npx cap sync

Config

Add this to your config, to disable auto-update:

// capacitor.config.json
{
"appId": "**.***.**",
"appName": "Name",
"plugins": {
"CapacitorUpdater": {
"autoUpdate": false
}
}
}

Then add this code to your app to use manual download

import { CapacitorUpdater } from '@capgo/capacitor-updater'
import { SplashScreen } from '@capacitor/splash-screen'
import { App } from '@capacitor/app'
let data = {version: ""}
CapacitorUpdater.notifyAppReady()
App.addListener('appStateChange', async(state) => {
if (state.isActive) {
// Do the download during user active app time to prevent failed download
data = await CapacitorUpdater.download({
version: '0.0.4',
url: 'https://github.com/Cap-go/demo-app/releases/download/0.0.4/dist.zip',
})
}
if (!state.isActive && data.version !== "") {
// Do the switch when user leave app
SplashScreen.show()
try {
await CapacitorUpdater.set(data)
} catch (err) {
console.log(err)
SplashScreen.hide() // in case the set fail, otherwise the new app will have to hide it
}
}
})

⚠️ If you send a broken update, the app will revert to the last working version, or the one include with the native build, if none works.

Demo app

Check the demo app for more info

GitHub - Cap-go/demo-app: demo app with manual and auto mode

Package

Whatever you choose to name the file you download from your release/update server URL, the zip file should contain the full contents of your production Capacitor build output folder, usually {project directory}/dist/ or {project directory}/www/.

This is where index.html will be located, and it should also contain all bundled JavaScript, CSS, and web resources necessary for your app to run.

Do not password encrypt this file, or it will fail to unpack.