Skip to content

Commit

Permalink
feat: Check for update on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
kachnitel committed Dec 8, 2019
1 parent 49517e8 commit e4828e5
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppLoading } from 'expo'
import { AppLoading, Updates } from 'expo'
import * as Font from 'expo-font'
import React from 'react'
import { Platform, StatusBar, StyleSheet, Text, View } from 'react-native'
Expand All @@ -12,6 +12,8 @@ import PushNotifications from './src/PushNotifications'
import navigationService from './src/NavigationService'
import NotificationsHandler from './src/NotificationsHandler'
import { logger } from './src/Logger'
import { alertAsync } from './src/AsyncAlert'
import { getEnvVars } from './constants/Env'

/**
* Set default Text style
Expand All @@ -31,6 +33,10 @@ class App extends React.Component {
isLoadingComplete: false
}

componentDidMount = () => {
this._checkUpdate()
}

render () {
if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
return (
Expand Down Expand Up @@ -63,6 +69,29 @@ class App extends React.Component {
}
}

async _checkUpdate () {
if (getEnvVars().dev === true) {
return
}
try {
let update = await Updates.checkForUpdateAsync()
if (update.isAvailable) {
let confirmDownload = await alertAsync('Update available', 'Download now?')
if (!confirmDownload) {
return
}
await Updates.fetchUpdateAsync()

let confirmReload = await alertAsync('Update downloaded', 'Reload app now?')
if (confirmReload) {
Updates.reloadFromCache()
}
}
} catch (e) {
logger.error('Update failed!', e)
}
}

async _notificationsSubscribe () {
/**
* When the app is started from a notification,
Expand Down

0 comments on commit e4828e5

Please sign in to comment.