Newer
Older
import React, { Component } from 'react'
import nodejs from 'nodejs-mobile-react-native'
import { getLicenseFlag, saveEncryptionFlag } from '../local-storage'
import { openDb } from '../db'
import App from './app'
import PasswordPrompt from './password-prompt'
import AppLoadingView from './app-loading'
import store from "../store"
export default class AppWrapper extends Component {
constructor() {
super()
isCheckingLicenseAgreement: true,
shouldShowLicenseAgreement: false,
shouldShowPasswordPrompt: false,
shouldShowApp: false,
nodejs.start('main.js')
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const isLicenseFlagSet = await getLicenseFlag()
if (!isLicenseFlagSet) {
this.enableShowLicenseAgreement()
} else {
this.setState({ isCheckingLicenseAgreement: false })
}
}
async checkDbPasswordSet() {
const canConnectToDb = await openDb()
if (canConnectToDb) {
this.enableShowApp()
await saveEncryptionFlag(false)
return false
}
this.setState({ shouldShowPasswordPrompt: true })
await saveEncryptionFlag(true)
}
enableShowLicenseAgreement = () => {
this.setState({
shouldShowLicenseAgreement: true,
isCheckingLicenseAgreement: false
})
}
disableShowLicenseAgreement = () => {
this.setState({ shouldShowLicenseAgreement: false })
}
enableShowApp = () => {
this.setState({
shouldShowApp: true,
shouldShowPasswordPrompt: false
})
const {
isCheckingLicenseAgreement,
shouldShowLicenseAgreement,
shouldShowPasswordPrompt,
shouldShowApp,
} = this.state
if (isCheckingLicenseAgreement) {
initialView = <AppLoadingView />
} else if (shouldShowLicenseAgreement) {
initialView = <License setLicense={this.disableShowLicenseAgreement}/>
} else if (shouldShowPasswordPrompt) {
initialView = <PasswordPrompt enableShowApp={this.enableShowApp} />
} else if (shouldShowApp) {
initialView = <App />
return <Provider store={store}>{initialView}</Provider>