-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
119 lines (114 loc) · 4.29 KB
/
Copy pathApp.js
File metadata and controls
119 lines (114 loc) · 4.29 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React, { Component } from 'react';
import {View, Text, WebView, Button, TextInput, SafeAreaView, StyleSheet, StatusBar, NativeModules} from 'react-native';
import FweiView from './FweiView';
import Options from './Options';
import Popup from './Popup';
import Welcome from './Welcome';
import CookieManager from '@react-native-cookies/cookies';
import config from './config';
import KeepAwake from 'react-native-keep-awake';
import AsyncStorage from '@react-native-community/async-storage';
import crashlytics from '@react-native-firebase/crashlytics';
function setPersistentSession(domain) {
if (!domain) return Promise.resolve();
return AsyncStorage.getItem('FWEI.persistentSession').then((persistentSession) => {
if (persistentSession) {
return CookieManager.set("https://" + domain, {
name: 'persistentSession',
value: persistentSession,
domain: domain,
origin: domain,
path: '/',
version: '1',
expiration: '2030-01-01T12:30:00.00-05:00'
}, true).then((res) => {
crashlytics().log('CookieManager.set =>', domain, persistentSession);
console.log('CookieManager.set =>', domain, persistentSession);
});
} else {
crashlytics().log("no persistensSession");
console.log("no persistensSession");
}
}).catch(e => {
crashlytics().recordError(e);
console.error(e);
});
}
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {popup: false, options: false, baseURL: undefined, init: false};
crashlytics().log('App started');
}
async componentDidMount() {
try {
const baseURL = await AsyncStorage.getItem('FWEI.baseURL');
if (baseURL) {
await setPersistentSession(baseURL);
this.setState({baseURL});
}
} catch (e) {
crashlytics().recordError(e);
const baseURL = config.defaultBaseURL;
await setPersistentSession(baseURL);
this.setState({baseURL});
} finally {
this.setState({init: true});
}
}
render() {
const {init, options, popup, legacyData, baseURL} = this.state;
return (
<SafeAreaView style={styles.safeArea}>
<KeepAwake />
<StatusBar
backgroundColor="#222"
barStyle="light-content"
/>
<View style={styles.appArea}>
{baseURL && <View style={{flex: 1}}>
<FweiView baseURL={baseURL}
legacyData={legacyData}
onOpenOptions={() => this.setState({options: true})}
onOpenPopup={(url) => this.setState({popup: url})}>
</FweiView>
</View>}
{popup && <View style={{flex: 1000}}>
<Popup
baseURL={baseURL}
url={popup}
onClose={() => this.setState({popup: false})}>
</Popup>
</View>
}
{options && <View style={{flex: 1000}}>
<Options
baseURL={baseURL}
onClose={() => this.setState({options: false})}
onSave={(baseURL) => this.setState({options: false, baseURL})}>
</Options>
</View>
}
{init && !baseURL && <View style={{flex: 1000}}>
<Welcome
baseURL={config.defaultBaseURL}
onSave={(baseURL) => this.setState({baseURL})}>
</Welcome>
</View>
}
</View>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: '#222'
},
appArea: {
flex: 1,
backgroundColor: '#FFF'
}
});