Download app update from url and install it.
And reload the view.
You can list the version and manage it with the command below.
Join the discord to get help : https://discord.gg/VnYRvBfgA6
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.
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/
. 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.
download(...)
set(...)
delete(...)
list()
reset()
current()
reload()
versionName()
notifyAppReady()
delayUpdate()
cancelDelay()
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(options: { version: string; versionName?: string; }) => Promise<void>
Set version as current version, set will return error if there are no index.html file inside the version folder, versionName is optional and it's a custom value who will be saved for you
Param | Type |
---|---|
options |
{ version: string; versionName?: string; } |
delete(options: { version: string; }) => Promise<void>
Delete version in storage
Param | Type |
---|---|
options |
{ version: string; } |
list() => Promise<{ versions: string[]; }>
Get all avaible versions
Returns: Promise<{ versions: string[]; }>
reset() => Promise<void>
Set the original version (the one sent to Apple store / Google play store ) as current version
current() => Promise<{ current: string; }>
Get the curent version, if none are set it return 'default'
Returns: Promise<{ current: string; }>
reload() => Promise<void>
Reload the view
versionName() => Promise<{ versionName: string; }>
Get the version name, if it was set during the set phase
Returns: Promise<{ versionName: string; }>
notifyAppReady() => Promise<void>
Notify native plugin that the update is working, only in auto update
delayUpdate() => Promise<void>
Skip update in the next app backgrounding, only in auto update
cancelDelay() => Promise<void>
allow update in the next app backgrounding, only in auto update
jamesyoung1337 Thanks a lot for your guidance and support, it was impossible to make this plugin work without you.