mirror of
https://github.com/standardnotes/mobile.git
synced 2026-01-30 10:31:22 -05:00
Decrypted export option
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Alert} from 'react-native';
|
||||
import GlobalStyles from "../../Styles"
|
||||
import {TextInput, View} from 'react-native';
|
||||
|
||||
import SectionHeader from "../../components/SectionHeader";
|
||||
import ButtonCell from "../../components/ButtonCell";
|
||||
import TableSection from "../../components/TableSection";
|
||||
import SectionedTableCell from "../../components/SectionedTableCell";
|
||||
import SectionedAccessoryTableCell from "../../components/SectionedAccessoryTableCell";
|
||||
import SectionedOptionsTableCell from "../../components/SectionedOptionsTableCell";
|
||||
|
||||
export default class OptionsSection extends Component {
|
||||
|
||||
@@ -15,13 +16,25 @@ export default class OptionsSection extends Component {
|
||||
this.state = {loadingExport: false};
|
||||
}
|
||||
|
||||
onExportPress = () => {
|
||||
onExportPress = (option) => {
|
||||
let encrypted = option.key == "encrypted";
|
||||
if(encrypted && !this.props.encryptionAvailable) {
|
||||
Alert.alert('Not Available', "You must be signed in, or have a local passcode set, to generate an encrypted export file.", [{text: 'OK'}])
|
||||
return;
|
||||
}
|
||||
this.setState({loadingExport: true});
|
||||
this.props.onExportPress(() => {
|
||||
this.props.onExportPress(encrypted, () => {
|
||||
this.setState({loadingExport: false});
|
||||
})
|
||||
}
|
||||
|
||||
exportOptions = () => {
|
||||
return [
|
||||
{title: "Encrypted", key: "encrypted", selected: this.props.encryptionAvailable},
|
||||
{title: "Decrypted", key: "decrypted", selected: true}
|
||||
];
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<TableSection>
|
||||
@@ -32,7 +45,15 @@ export default class OptionsSection extends Component {
|
||||
<ButtonCell first={true} leftAligned={true} title={`Sign out (${this.props.email})`} onPress={this.props.onSignOutPress} />
|
||||
}
|
||||
|
||||
<ButtonCell last={true} first={!this.props.signedIn} disabled={this.state.loadingExport} leftAligned={true} title={this.state.loadingExport ? "Preparing Data..." : "Export Data"} onPress={this.onExportPress} />
|
||||
<SectionedOptionsTableCell
|
||||
last={true}
|
||||
first={!this.props.signedIn}
|
||||
disabled={this.state.loadingExport}
|
||||
leftAligned={true}
|
||||
options={this.exportOptions()}
|
||||
title={this.state.loadingExport ? "Preparing Data..." : "Export Data"}
|
||||
onPress={this.onExportPress}
|
||||
/>
|
||||
|
||||
</TableSection>
|
||||
);
|
||||
|
||||
@@ -231,7 +231,7 @@ export default class Account extends Abstract {
|
||||
)
|
||||
}
|
||||
|
||||
async onExportPress(callback) {
|
||||
async onExportPress(encrypted, callback) {
|
||||
var version = Auth.getInstance().protocolVersion();
|
||||
var keys = KeysManager.get().activeKeys();
|
||||
|
||||
@@ -257,8 +257,6 @@ export default class Account extends Abstract {
|
||||
data["auth_params"] = authParams;
|
||||
}
|
||||
|
||||
var encrypted = keys && keys !== null;
|
||||
|
||||
var jsonString = JSON.stringify(data, null, 2 /* pretty print */);
|
||||
var base64String = base64.encode(jsonString);
|
||||
var fileType = App.isAndroid ? ".json" : "json"; // Android creates a tmp file and expects dot with extension
|
||||
@@ -270,10 +268,10 @@ export default class Account extends Abstract {
|
||||
isHTML: true,
|
||||
attachment: { data: App.isIOS ? jsonString : base64String, type: fileType, name: encrypted ? "SN-Encrypted-Backup" : 'SN-Decrypted-Backup' }
|
||||
}, (error, event) => {
|
||||
callback();
|
||||
if(error) {
|
||||
Alert.alert('Error', 'Unable to send email.');
|
||||
}
|
||||
callback();
|
||||
if(error) {
|
||||
Alert.alert('Error', 'Unable to send email.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -425,17 +423,18 @@ export default class Account extends Abstract {
|
||||
|
||||
{this.state.confirmRegistration &&
|
||||
<RegistrationConfirmSection
|
||||
title={"Confirm your password"}
|
||||
password={this.state.params.password}
|
||||
registering={this.state.registering}
|
||||
onSuccess={this.onRegisterConfirmSuccess}
|
||||
onCancel={this.onRegisterConfirmCancel}
|
||||
title={"Confirm your password"}
|
||||
password={this.state.params.password}
|
||||
registering={this.state.registering}
|
||||
onSuccess={this.onRegisterConfirmSuccess}
|
||||
onCancel={this.onRegisterConfirmCancel}
|
||||
/>
|
||||
}
|
||||
|
||||
<OptionsSection
|
||||
signedIn={signedIn}
|
||||
title={"Options"}
|
||||
encryptionAvailable={KeysManager.get().activeKeys()}
|
||||
onSignOutPress={this.onSignOutPress}
|
||||
onExportPress={this.onExportPress}
|
||||
email={KeysManager.get().getUserEmail()}
|
||||
|
||||
Reference in New Issue
Block a user