Add db deletion button for when things go wrong
This commit is contained in:
@@ -5,7 +5,7 @@ import { AppText } from './app-text'
|
|||||||
import { hasEncryptionObservable } from '../local-storage'
|
import { hasEncryptionObservable } from '../local-storage'
|
||||||
import styles from '../styles'
|
import styles from '../styles'
|
||||||
import { passwordPrompt } from './labels'
|
import { passwordPrompt } from './labels'
|
||||||
import { openDbConnection, requestHash } from '../db'
|
import { openDbConnection, requestHash, deleteDbAndOpenNew } from '../db'
|
||||||
import App from './app'
|
import App from './app'
|
||||||
|
|
||||||
export default class PasswordPrompt extends Component {
|
export default class PasswordPrompt extends Component {
|
||||||
@@ -32,6 +32,7 @@ export default class PasswordPrompt extends Component {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await openDbConnection(key)
|
await openDbConnection(key)
|
||||||
|
this.setState({showApp: true})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
this.setState({ wrongPassword: true })
|
this.setState({ wrongPassword: true })
|
||||||
@@ -79,6 +80,17 @@ export default class PasswordPrompt extends Component {
|
|||||||
</AppText>
|
</AppText>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
{this.state.wrongPassword && <AppText>Wrong PAssword!</AppText>}
|
{this.state.wrongPassword && <AppText>Wrong PAssword!</AppText>}
|
||||||
|
<TouchableOpacity
|
||||||
|
style={styles.settingsButton}
|
||||||
|
onPress={async () => {
|
||||||
|
await deleteDbAndOpenNew()
|
||||||
|
this.setState({showApp: true})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<AppText style={styles.settingsButtonText}>
|
||||||
|
{'Delete old db and make unencrypted new'}
|
||||||
|
</AppText>
|
||||||
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
+9
-3
@@ -20,7 +20,7 @@ const realmConfig = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openDbConnection(key) {
|
export async function openDbConnection(key) {
|
||||||
realmConfig.encryptionKey = key
|
if(key) realmConfig.encryptionKey = key
|
||||||
db = await Realm.open(realmConfig)
|
db = await Realm.open(realmConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,6 @@ function tryToImportWithoutDelete(cycleDays) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function requestHash(pw) {
|
function requestHash(pw) {
|
||||||
console.log('requesting hash')
|
|
||||||
nodejs.channel.send(JSON.stringify({
|
nodejs.channel.send(JSON.stringify({
|
||||||
type: 'request-SHA512',
|
type: 'request-SHA512',
|
||||||
message: pw || 'mypassword'
|
message: pw || 'mypassword'
|
||||||
@@ -191,6 +190,12 @@ async function encryptAndRestartApp(key) {
|
|||||||
restart.Restart()
|
restart.Restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteDbAndOpenNew() {
|
||||||
|
const exists = await fs.exists(Realm.defaultPath)
|
||||||
|
if (exists) await fs.unlink(Realm.defaultPath)
|
||||||
|
await openDbConnection()
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
saveSymptom,
|
saveSymptom,
|
||||||
getOrCreateCycleDay,
|
getOrCreateCycleDay,
|
||||||
@@ -207,5 +212,6 @@ export {
|
|||||||
tryToImportWithDelete,
|
tryToImportWithDelete,
|
||||||
tryToImportWithoutDelete,
|
tryToImportWithoutDelete,
|
||||||
requestHash,
|
requestHash,
|
||||||
encryptAndRestartApp
|
encryptAndRestartApp,
|
||||||
|
deleteDbAndOpenNew
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user