-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdater.js
36 lines (33 loc) · 1.34 KB
/
Updater.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import AppUpdate from "react-native-appupdate";
export async function triggerUpdateIfNeeded() {
// Fetch the updater version package of the last github release.
// @todo change to a notification system instead.
let releaseJsonResp = await fetch('https://api.github.com/repos/pnplab/Flux/releases/latest');
let releaseJson = await releaseJsonResp.json();
let updaterVersionPackage = releaseJson
.assets
.filter(a => a.name === "version.json")[0]
.browser_download_url;
// Generate updater.
const updater = new AppUpdate({
// iosAppId: "123456",
apkVersionUrl: updaterVersionPackage,
needUpdateApp: (needUpdate) => {
// Trigger the update without asking the user !
needUpdate(true);
},
forceUpdateApp: () => {
// Forced update, found from the version.json
console.log("Force update will start")
},
notNeedUpdateApp: () => {
console.log("App is up to date")
},
downloadApkStart: () => { console.log("Start") },
downloadApkProgress: (progress) => { console.log(`Downloading ${progress}%...`) },
downloadApkEnd: () => { console.log("End") },
onError: () => { console.log("downloadApkError") }
});
// Check update & install.
updater.checkUpdate();
};