瀏覽代碼

implemented ota updates

cdmoss 2 年之前
父節點
當前提交
e993a2c3db
共有 9 個文件被更改,包括 45 次插入4 次删除
  1. 1 1
      App.tsx
  2. 1 1
      android/app/src/main/AndroidManifest.xml
  3. 1 0
      index.js
  4. 1 1
      ios/cnpmobile/Supporting/Expo.plist
  5. 11 0
      package-lock.json
  6. 1 0
      package.json
  7. 23 0
      src/components/Atlas.tsx
  8. 1 1
      src/components/Auth/Intro.tsx
  9. 5 0
      yarn.lock

+ 1 - 1
App.tsx

@@ -3,7 +3,7 @@ import { LogBox } from 'react-native';
 import 'react-native-gesture-handler';
 import { SafeAreaProvider } from 'react-native-safe-area-context';
 import Atlas from './src/components/Atlas';
-import { Asset } from 'expo-asset';
+import 'expo-asset';
 import AppLoading from 'expo-app-loading';
 import * as Updates from "expo-updates";
 

+ 1 - 1
android/app/src/main/AndroidManifest.xml

@@ -21,7 +21,7 @@
     <meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="43.0.0"/>
     <meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
     <meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
-    <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@anonymous/cnp-mobile"/>
+    <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@cdmoss/cnp-mobile"/>
     <activity android:name=".MainActivity" android:exported="true" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
       <intent-filter>
         <action android:name="android.intent.action.MAIN"/>

+ 1 - 0
index.js

@@ -1,4 +1,5 @@
 import 'react-native-gesture-handler';
+import 'expo-asset'
 import { registerRootComponent } from 'expo';
 
 import App from './App';

+ 1 - 1
ios/cnpmobile/Supporting/Expo.plist

@@ -11,6 +11,6 @@
     <key>EXUpdatesSDKVersion</key>
     <string>43.0.0</string>
     <key>EXUpdatesURL</key>
-    <string>https://exp.host/@anonymous/cnp-mobile</string>
+    <string>https://exp.host/@cdmoss/cnp-mobile</string>
   </dict>
 </plist>

+ 11 - 0
package-lock.json

@@ -33,6 +33,7 @@
         "expo-font": "~10.0.3",
         "expo-image-picker": "~11.0.3",
         "expo-linking": "~2.4.2",
+        "expo-modules": "^0.0.0",
         "expo-notifications": "~0.13.3",
         "expo-random": "~12.0.1",
         "expo-secure-store": "~11.0.3",
@@ -13707,6 +13708,11 @@
         "expo-json-utils": "~0.2.0"
       }
     },
+    "node_modules/expo-modules": {
+      "version": "0.0.0",
+      "resolved": "https://registry.npmjs.org/expo-modules/-/expo-modules-0.0.0.tgz",
+      "integrity": "sha512-RsXPsVjxeLIr2AKE9YWIcVhuDvA446DaUP8J9yoQ2VA7DfcgNQdx2ZNpXfy3CI45AFJjtEqFKJ46Vnb3asM/OQ=="
+    },
     "node_modules/expo-modules-autolinking": {
       "version": "0.3.4",
       "resolved": "https://registry.npmjs.org/expo-modules-autolinking/-/expo-modules-autolinking-0.3.4.tgz",
@@ -41937,6 +41943,11 @@
         "expo-json-utils": "~0.2.0"
       }
     },
+    "expo-modules": {
+      "version": "0.0.0",
+      "resolved": "https://registry.npmjs.org/expo-modules/-/expo-modules-0.0.0.tgz",
+      "integrity": "sha512-RsXPsVjxeLIr2AKE9YWIcVhuDvA446DaUP8J9yoQ2VA7DfcgNQdx2ZNpXfy3CI45AFJjtEqFKJ46Vnb3asM/OQ=="
+    },
     "expo-modules-autolinking": {
       "version": "0.3.4",
       "resolved": "https://registry.npmjs.org/expo-modules-autolinking/-/expo-modules-autolinking-0.3.4.tgz",

+ 1 - 0
package.json

@@ -50,6 +50,7 @@
     "expo-font": "~10.0.3",
     "expo-image-picker": "~11.0.3",
     "expo-linking": "~2.4.2",
+    "expo-modules": "^0.0.0",
     "expo-notifications": "~0.13.3",
     "expo-random": "~12.0.1",
     "expo-secure-store": "~11.0.3",

+ 23 - 0
src/components/Atlas.tsx

@@ -25,6 +25,7 @@ import UnauthorizedNavigator from '../navigation/UnauthorizedNavigator';
 import { authStore } from '../libs/auth/AuthStore';
 import { API_URL } from '../utils/RequestUtils';
 import {reportAxiosError} from '../libs/auth/core'
+import * as Updates from 'expo-updates'
 
 export enum TokenState {
   CheckingToken,
@@ -44,10 +45,32 @@ const Atlas : React.FC = () => {
    */
   const [checkingToken, setCheckingToken] = useState<boolean>(true);
   const { refreshAccessToken } = useAuth();
+  const [updatesDismissed, setUpdatesDismissed] = useState<boolean>(false)
   const [fontsLoaded, error] = useFonts({
     RacingSansOne_400Regular
   });
 
+    useEffect(() => {
+      const timer = setInterval(async () => {
+        const update = await Updates.checkForUpdateAsync()
+        if (update.isAvailable && !updatesDismissed) {
+          Alert.alert('Update Available', 'An update is available. Would you like to update now?', [
+            {"text": "Yes", "onPress": async () => {
+              await Updates.fetchUpdateAsync()
+              await Updates.reloadAsync()
+            }},
+            {"text": "No", "onPress": () => {
+              setUpdatesDismissed(true)
+              Alert.alert('Update Available', 'Update dismissed, you can always revisit it in settings', [
+                {"text": "OK"}
+              ])
+            }}
+          ])
+        }
+      }, 3000)
+      return () => clearInterval(timer)
+    }, [])
+
   /**
    * Checks if there is an access token available in {@link AuthStore}, then checks if that access token is valid by calling the API. 
    * If the response is valid, the access token will be stored in memory, otherwise the user will be directed to intro screen.

+ 1 - 1
src/components/Auth/Intro.tsx

@@ -121,7 +121,7 @@ const Intro : React.FC<IntroProps> = ({navigation}) => {
                     <Text style={styles.title} >Click & Push</Text>
                 </View>
                 <View style={styles.btnContainer}>
-                    <PrimaryButton text="Login" onPress={login}/>
+                    <PrimaryButton text="Login test" onPress={login}/>
                     <SecondaryButton text="Create account" onPress={goToRegistration} />
                 </View>
             </View> :

+ 5 - 0
yarn.lock

@@ -7520,6 +7520,11 @@
     "compare-versions" "^3.4.0"
     "invariant" "^2.2.4"
 
+"expo-modules@^0.0.0":
+  "integrity" "sha512-RsXPsVjxeLIr2AKE9YWIcVhuDvA446DaUP8J9yoQ2VA7DfcgNQdx2ZNpXfy3CI45AFJjtEqFKJ46Vnb3asM/OQ=="
+  "resolved" "https://registry.npmjs.org/expo-modules/-/expo-modules-0.0.0.tgz"
+  "version" "0.0.0"
+
 "expo-notifications@~0.13.3":
   "integrity" "sha512-2iQVydhLZ+S3s/tKdcBPRWQyqztQOyex9WaSDj/2noKLWBpIqFouV/Dln+8vYj/BAKb0JoeHko6XA+wnel7qdA=="
   "resolved" "https://registry.npmjs.org/expo-notifications/-/expo-notifications-0.13.3.tgz"