Skip to content

Commit

Permalink
Develop (#38)
Browse files Browse the repository at this point in the history
* Fix: env variables in github

* Fix: Env variables in release

* Feat: Update page check (#37)
  • Loading branch information
titi0267 authored Feb 26, 2024
1 parent ff62de0 commit b00c71c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ jobs:
body: |
Release version ${{steps.version.outputs.prop}}
Fetures:
- Alert users that an update is available
44 changes: 40 additions & 4 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
import React from 'react';
import React, {useEffect, useState} from 'react';
import {NavigationContainer} from '@react-navigation/native';
import RootStackNavigation from './src/Navigation/RootStackNavigator';
import updateApp from './src/services/updateApp.service';
import {Button, Linking, StyleSheet, Text, View} from 'react-native';

const App = (): JSX.Element => {
const [version, setVersion] = useState(false);
useEffect(() => {
updateApp(setVersion);
}, []);
return (
<NavigationContainer>
<RootStackNavigation />
</NavigationContainer>
<>
{version ? (
<View style={styles.updateContainer}>
<Text style={styles.text}>
Il semblerait que votre application ne soit pas à jour !
</Text>
<Button
title="Mettre à jour"
onPress={() => {
Linking.openURL('market://details?id=com.opticarbu');
}}
/>
</View>
) : (
<NavigationContainer>
<RootStackNavigation />
</NavigationContainer>
)}
</>
);
};

const styles = StyleSheet.create({
updateContainer: {
height: '100%',
justifyContent: 'center',
alignItems: 'center',
},
text: {
width: '80%',
textAlign: 'center',
marginBottom: 10,
fontSize: 18,
},
});

export default App;
6 changes: 0 additions & 6 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,16 @@ def myAppUploadKeyPassword = System.getenv("MYAPP_UPLOAD_KEY_PASSWORD")


def getVersionFromPackageJson() {
// Read and parse package.json file from project root
def inputFile = new File("$rootDir/../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)

// Return the version, you can get any value this way
return packageJson["version"]
}

def getVersionCodeFromPackageJson() {
// Read and parse package.json file from project root
def inputFile = new File("$rootDir/../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)

// Return the version, you can get any value this way
return packageJson["versionCode"]
}

Expand Down Expand Up @@ -161,8 +157,6 @@ android {
debugSymbolLevel 'FULL'
}

// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.release
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "gas-prices",
"version": "0.0.2",
"versionCode": 8,
"version": "0.0.3",
"versionCode": 9,
"private": true,
"scripts": {
"android": "react-native run-android",
"android": "react-native run-android --variant=debug",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
Expand Down
18 changes: 18 additions & 0 deletions src/services/updateApp.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {HOST} from '@env';

const updateApp = async (setVersion: (value: any) => void) => {
const pj = require('../../package.json');
const body = {version: pj.version};
const res = await fetch(`${HOST}/update`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
if (!res.ok) throw Error('Error on osrm services');
const resolve = await res.json();
setVersion(resolve);
};

export default updateApp;

0 comments on commit b00c71c

Please # to comment.