Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
65
66
67
68
import React, { Component } from 'react'
import { View, TextInput, TouchableOpacity } from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import AppText from './app-text'
import { hasEncryptionObservable } from '../local-storage'
import styles from '../styles'
import labels from './labels'
import { openDbConnection } from '../db'
import App from './app'
export default class PasswordPrompt extends Component {
constructor() {
super()
this.state = {}
hasEncryptionObservable.once((hasEncryption) => {
if (hasEncryption) {
this.setState({showPasswordPrompt: true})
} else {
openDbConnection()
this.setState({showApp: true})
}
})
nodejs.channel.addListener(
'message',
msg => {
msg = JSON.parse(msg)
if (msg.type === 'password-check-result') {
if (msg.message) {
this.setState({showApp: true})
} else {
this.setState({wrongPassword: true})
}
}
},
this
)
}
render() {
return (
<View style={{ flex: 1 }}>
{this.state.showApp ?
<App password={this.state.password}/>
:
<View>
{this.state.showPasswordPrompt &&
<View>
<TextInput
onChangeText={val => this.setState({password: val})}
/>
<TouchableOpacity
onPress={async () => {
}}
style={styles.settingsButton}>
<AppText style={styles.settingsButtonText}>
{labels.export.button}
</AppText>
</TouchableOpacity>
{this.state.wrongPassword && <AppText>Wrong PAssword!</AppText>}
</View>
}
</View>
}
</View>
)
}
}