capacitor-updater
Download app update from url and install it.
And reload the view.
You can list the version and manage it with the command below.
Install
npm install capacitor-updater
npx cap sync
import { CapacitorUpdater } from 'capacitor-updater'
import { SplashScreen } from '@capacitor/splash-screen'
import { App } from '@capacitor/app'
let version = ""
App.addListener('appStateChange', async(state) => {
if (state.isActive) {
// Do the download during user active app time to prevent failed download
version = await CapacitorUpdater.download({
url: 'https://github.com/Forgr-ee/Mimesis/releases/download/0.0.1/dist.zip',
})
}
if (!state.isActive && version !== "") {
// Do the switch when user leave app
SplashScreen.show()
try {
await CapacitorUpdater.set(version)
} catch () {
SplashScreen.hide() // in case the set fail, otherwise the new app will have to hide it
}
}
})
// or do it when click on button
const updateNow = async () => {
const version = await CapacitorUpdater.download({
url: 'https://github.com/Forgr-ee/Mimesis/releases/download/0.0.1/dist.zip',
})
// show the splashscreen to let the update happen
SplashScreen.show()
await CapacitorUpdater.set(version)
SplashScreen.hide() // in case the set fail, otherwise the new app will have to hide it
}
Be extra carufull for your update if you send a broken update, the app will crash until the user uninstall it.
API
download(...)
download(options: { url: string; }) => Promise<{ version: string; }>
download new version from url, it should be a zip file, with files inside or with a unique folder inside with all your files
Param | Type |
---|---|
options |
{ url: string; } |
Returns: Promise<{ version: string; }>
set(...)
set(options: { version: string; }) => Promise<void>
set version as current version, set will return error if there are no index.html file inside the version folder
Param | Type |
---|---|
options |
{ version: string; } |
delete(...)
delete(options: { version: string; }) => Promise<void>
delete version in storage
Param | Type |
---|---|
options |
{ version: string; } |
list()
list() => Promise<{ versions: string[]; }>
get all avaible versions
Returns: Promise<{ versions: string[]; }>
reset()
reset() => Promise<void>
set the original version (the one sent to Apple store / Google play store ) as current version
current()
current() => Promise<{ current: string; }>
get the curent version, if none are set it return 'default'
Returns: Promise<{ current: string; }>
Inspiraton
Contributer
jamesyoung1337 Thanks a lot for your guidance and support, it was impossible to make this plugin work without you.