blob: 38bb927a937f9a2fdc2dc6744050bca8a47c0f91 (
plain)
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
|
// @flow
import React from 'react';
import RX, { Component } from 'reactxp';
import { Provider } from 'react-redux';
import { Router } from 'react-router-redux';
import { createMemoryHistory } from 'history';
import makeRoutes from './routes';
import configureStore from './redux/store';
import { log } from './lib/platform';
import { Backend, BackendError } from './lib/backend';
import { DeviceEventEmitter } from 'react-native';
import { MobileAppBridge } from 'NativeModules';
import { Dimensions } from 'react-native';
const initialState = null;
const memoryHistory = createMemoryHistory();
const store = configureStore(initialState, memoryHistory);
//////////////////////////////////////////////////////////////////////////
// Backend
//////////////////////////////////////////////////////////////////////////
const backend = new Backend(store);
DeviceEventEmitter.addListener('com.mullvad.backend-info', async (_event, args) => {
backend.setCredentials(args.credentials);
backend.sync();
try {
await backend.autologin();
await backend.fetchRelaySettings();
await backend.fetchSecurityState();
await backend.connect();
} catch (e) {
if (e instanceof BackendError) {
if (e.type === 'NO_ACCOUNT') {
log.debug('No user set in the backend, showing window');
MobileAppBridge.showWindow();
}
}
}
});
MobileAppBridge.startBackend()
.then((_response) => {})
.catch((e) => {
log.error('Failed starting backend:', e);
});
const _isPortrait = () => {
const dim = RX.UserInterface.measureWindow();
return dim.height >= dim.width;
};
export default class App extends Component {
constructor() {
super();
this.state = {
orientation: _isPortrait() ? 'portrait' : 'landscape',
};
Dimensions.addEventListener('change', () => {
this.setState({
orientation: _isPortrait() ? 'portrait' : 'landscape',
});
});
}
render() {
return (
<Provider store={store}>
<Router history={memoryHistory}>{makeRoutes(store.getState, { backend })}</Router>
</Provider>
);
}
}
|