Skip to content

Commit

Permalink
Show complete changelog from missed updates
Browse files Browse the repository at this point in the history
  • Loading branch information
niwla23 committed Mar 28, 2021
1 parent 1e50d76 commit 1959e24
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ android {
applicationId "com.schulhack"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 11
versionName "1.4.2"
versionCode 12
versionName "1.4.3"
multiDexEnabled true
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "https://gitlab.com/niwla23/schulhack/-/issues"
},
"scripts": {
"android": "react-native run-android",
"android": "UPDATE_SERVER_BASE_URL=http://192.168.178.82:8888 ENABLE_AUTO_UPDATE=true react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
Expand Down
29 changes: 21 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import { UpdateOverlay } from './components/updateOverlay'
import axios from "axios"
import { Linking } from 'react-native';
import getSimpleVersionCode from './helpers/getSimpleVersionCode'


const App = () => {
Expand All @@ -23,32 +24,44 @@ const App = () => {
setTheme(read_value)
}
})
console.log(`foo is equal to ${process.env["FOO"]}`);

if (Boolean(process.env["ENABLE_AUTO_UPDATE"])) {
console.log("checking for updates")
console.log(Number(DeviceInfo.getBuildNumber()))
const currentVersionCode = Number(DeviceInfo.getBuildNumber())
const abi = DeviceInfo.supportedAbisSync()[0]
axios.get(`${process.env["UPDATE_SERVER_BASE_URL"]}/versions.json?cb=${new Date().getTime()}`).then(r => {


const versionData = r.data[abi]

setShowUpdateOverlay(versionData.versionCode > DeviceInfo.getBuildNumber())
setShowUpdateOverlay(versionData.versionCode > currentVersionCode)
setNewVersionName(versionData.versionName)
console.log(versionData.url)
setUpdateUrl(versionData.url)

axios.get(`${process.env["UPDATE_SERVER_BASE_URL"]}/release_notes.json?cb=${new Date().getTime()}`).then(b => {
setReleaseNotes(b.data[String(versionData.simpleVersionCode)].de)
const missedVersions = []
for (var i = currentVersionCode; i <= versionData.versionCode; i++) {
missedVersions.push(i);
}
if (missedVersions.length > 1) {
missedVersions.shift()
}

const localReleaseNotes: Array<string> = []
missedVersions.forEach((element) => {
const simpleVersionCode = getSimpleVersionCode(element, abi)
b.data[String(simpleVersionCode)].de.forEach(line => {
localReleaseNotes.push(line)
});
})

// setReleaseNotes(b.data[String(versionData.simpleVersionCode)].de)
setReleaseNotes(localReleaseNotes)
})
})
}

}, []);

const acceptUpdate = () => {
console.log("yay, user accepted")
Linking.openURL(updateUrl)
}

Expand Down
11 changes: 11 additions & 0 deletions src/helpers/getSimpleVersionCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const getSimpleVersionCode = (longCode: number, abi: string): Number => {
const abi_to_num = {
"armeabi-v7a": 1,
"x86": 2,
"arm64-v8a": 3,
"x86_64": 4
}
return longCode - abi_to_num[abi] * 1048576
}

export default getSimpleVersionCode

0 comments on commit 1959e24

Please sign in to comment.