Page MenuHomePhabricator

D9004.id30487.diff
No OneTemporary

D9004.id30487.diff

diff --git a/native/profile/dev-tools.react.js b/native/profile/dev-tools.react.js
--- a/native/profile/dev-tools.react.js
+++ b/native/profile/dev-tools.react.js
@@ -1,6 +1,7 @@
// @flow
import invariant from 'invariant';
+import { entries } from 'lodash/object.js';
import * as React from 'react';
import { View, Text, Platform } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
@@ -8,9 +9,11 @@
import { urlPrefixSelector } from 'lib/selectors/keyserver-selectors.js';
import type { Dispatch } from 'lib/types/redux-types.js';
+import { getMessageForException } from 'lib/utils/errors.js';
import { setURLPrefix } from 'lib/utils/url-utils.js';
import type { ProfileNavigationProp } from './profile.react.js';
+import { useClientBackup } from '../backup/use-client-backup.js';
import Button from '../components/button.react.js';
import SWMansionIcon from '../components/swmansion-icon.react.js';
import { commCoreModule } from '../native-modules.js';
@@ -18,6 +21,7 @@
import { CustomServerModalRouteName } from '../navigation/route-names.js';
import { useSelector } from '../redux/redux-utils.js';
import { useColors, useStyles, type Colors } from '../themes/colors.js';
+import Alert from '../utils/alert.js';
import { wipeAndExit } from '../utils/crash-utils.js';
import { checkForMissingNatDevHostname } from '../utils/dev-hostname.js';
import { nodeServerOptions } from '../utils/url-utils.js';
@@ -42,6 +46,7 @@
+colors: Colors,
+styles: typeof unboundStyles,
+dispatch: Dispatch,
+ +testRestore: () => Promise<void>,
};
class DevTools extends React.PureComponent<Props> {
render() {
@@ -138,6 +143,18 @@
Wipe state and kill app
</Text>
</Button>
+ <View style={this.props.styles.hr} />
+ <Button
+ onPress={this.onPressTestRestore}
+ style={this.props.styles.row}
+ iosFormat="highlight"
+ iosHighlightUnderlayColor={underlay}
+ iosActiveOpacity={0.85}
+ >
+ <Text style={this.props.styles.redText}>
+ Test backup restore protocol
+ </Text>
+ </Button>
</View>
<Text style={this.props.styles.header}>SERVER</Text>
<View style={this.props.styles.slightlyPaddedSection}>
@@ -160,6 +177,10 @@
await wipeAndExit();
};
+ onPressTestRestore = async () => {
+ await this.props.testRestore();
+ };
+
onSelectServer = (server: string) => {
if (server !== this.props.urlPrefix) {
this.props.dispatch({
@@ -242,6 +263,22 @@
const colors = useColors();
const styles = useStyles(unboundStyles);
const dispatch = useDispatch();
+ const userStore = useSelector(state => state.userStore);
+ const { restoreBackupProtocol } = useClientBackup();
+
+ const testRestore = React.useCallback(async () => {
+ let message;
+ try {
+ const result = await restoreBackupProtocol({ userStore });
+ message = entries(result)
+ .map(([key, value]) => `${key}: ${value}`)
+ .join('\n');
+ } catch (e) {
+ console.error(`Backup uploading error: ${e}`);
+ message = `Backup restore error: ${String(getMessageForException(e))}`;
+ }
+ Alert.alert('Restore protocol result', message);
+ }, [restoreBackupProtocol, userStore]);
return (
<DevTools
@@ -251,6 +288,7 @@
colors={colors}
styles={styles}
dispatch={dispatch}
+ testRestore={testRestore}
/>
);
},

File Metadata

Mime Type
text/plain
Expires
Sat, Sep 28, 10:56 PM (17 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2198234
Default Alt Text
D9004.id30487.diff (3 KB)

Event Timeline