2018-07-11 09:42:43 +00:00
|
|
|
// @flow
|
2017-01-05 21:06:41 +00:00
|
|
|
|
2017-10-13 16:13:46 +00:00
|
|
|
import React from 'react';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-09-01 19:14:03 +00:00
|
|
|
import '../../analytics';
|
2017-09-18 07:09:43 +00:00
|
|
|
import '../../authentication';
|
2019-01-22 10:32:18 +00:00
|
|
|
import { setColorScheme } from '../../base/color-scheme';
|
2018-09-03 13:53:24 +00:00
|
|
|
import { DialogContainer } from '../../base/dialog';
|
2019-10-18 14:30:59 +00:00
|
|
|
import { CALL_INTEGRATION_ENABLED, updateFlags } from '../../base/flags';
|
2018-07-09 22:14:55 +00:00
|
|
|
import '../../base/jwt';
|
2017-02-10 16:13:39 +00:00
|
|
|
import { Platform } from '../../base/react';
|
2019-11-08 16:42:39 +00:00
|
|
|
import '../../base/responsive-ui';
|
2019-06-11 13:38:33 +00:00
|
|
|
import { updateSettings } from '../../base/settings';
|
2018-08-07 00:30:32 +00:00
|
|
|
import '../../google-api';
|
2017-03-27 09:39:10 +00:00
|
|
|
import '../../mobile/audio-mode';
|
2019-07-11 11:32:17 +00:00
|
|
|
import '../../mobile/back-button';
|
2017-03-27 09:39:10 +00:00
|
|
|
import '../../mobile/background';
|
2019-01-31 16:20:54 +00:00
|
|
|
import '../../mobile/call-integration';
|
2017-06-07 15:50:30 +00:00
|
|
|
import '../../mobile/external-api';
|
2017-03-27 09:39:10 +00:00
|
|
|
import '../../mobile/full-screen';
|
2017-08-18 10:54:05 +00:00
|
|
|
import '../../mobile/permissions';
|
2018-02-01 16:02:07 +00:00
|
|
|
import '../../mobile/picture-in-picture';
|
2017-03-30 08:12:38 +00:00
|
|
|
import '../../mobile/proximity';
|
2017-03-27 09:39:10 +00:00
|
|
|
import '../../mobile/wake-lock';
|
2017-09-27 08:29:42 +00:00
|
|
|
import '../../mobile/watchos';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from '../logger';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
import { AbstractApp } from './AbstractApp';
|
2018-07-11 09:42:43 +00:00
|
|
|
import type { Props as AbstractAppProps } from './AbstractApp';
|
|
|
|
|
|
|
|
declare var __DEV__;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
2018-07-12 16:16:57 +00:00
|
|
|
* The type of React {@code Component} props of {@link App}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-07-11 09:42:43 +00:00
|
|
|
type Props = AbstractAppProps & {
|
|
|
|
|
2019-01-22 10:32:18 +00:00
|
|
|
/**
|
|
|
|
* An object of colors that override the default colors of the app/sdk.
|
|
|
|
*/
|
2019-03-05 11:06:38 +00:00
|
|
|
colorScheme: ?Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Identifier for this app on the native side.
|
|
|
|
*/
|
|
|
|
externalAPIScope: string,
|
2019-01-22 10:32:18 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
/**
|
2019-05-24 11:06:05 +00:00
|
|
|
* An object with the feature flags.
|
2018-07-11 09:42:43 +00:00
|
|
|
*/
|
2019-06-11 13:38:33 +00:00
|
|
|
flags: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object with user information (display name, email, avatar URL).
|
|
|
|
*/
|
|
|
|
userInfo: ?Object
|
2018-07-11 09:42:43 +00:00
|
|
|
};
|
2016-12-01 01:52:39 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
/**
|
2018-07-12 16:16:57 +00:00
|
|
|
* Root app {@code Component} on mobile/React Native.
|
2018-07-11 09:42:43 +00:00
|
|
|
*
|
|
|
|
* @extends AbstractApp
|
|
|
|
*/
|
|
|
|
export class App extends AbstractApp {
|
2019-01-22 10:32:18 +00:00
|
|
|
_init: Promise<*>;
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2018-07-12 16:16:57 +00:00
|
|
|
* Initializes a new {@code App} instance.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2018-07-12 16:16:57 +00:00
|
|
|
* @param {Props} props - The read-only React {@code Component} props with
|
|
|
|
* which the new instance is to be initialized.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-07-11 09:42:43 +00:00
|
|
|
constructor(props: Props) {
|
2016-10-05 14:36:59 +00:00
|
|
|
super(props);
|
|
|
|
|
2017-01-05 21:06:41 +00:00
|
|
|
// In the Release configuration, React Native will (intentionally) throw
|
|
|
|
// an unhandled JavascriptException for an unhandled JavaScript error.
|
2018-07-12 16:16:57 +00:00
|
|
|
// This will effectively kill the app. In accord with the Web, do not
|
|
|
|
// kill the app.
|
2017-01-05 21:06:41 +00:00
|
|
|
this._maybeDisableExceptionsManager();
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-01-24 15:53:28 +00:00
|
|
|
* Initializes the color scheme.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
2019-01-24 15:53:28 +00:00
|
|
|
*
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2019-01-01 23:50:11 +00:00
|
|
|
componentDidMount() {
|
|
|
|
super.componentDidMount();
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2019-01-22 10:32:18 +00:00
|
|
|
this._init.then(() => {
|
2019-06-11 13:38:33 +00:00
|
|
|
// We set these early enough so then we avoid any unnecessary re-renders.
|
|
|
|
const { dispatch } = this.state.store;
|
2019-05-24 11:06:05 +00:00
|
|
|
|
2019-06-11 13:38:33 +00:00
|
|
|
dispatch(setColorScheme(this.props.colorScheme));
|
|
|
|
dispatch(updateFlags(this.props.flags));
|
|
|
|
dispatch(updateSettings(this.props.userInfo || {}));
|
2019-10-18 14:30:59 +00:00
|
|
|
|
|
|
|
// Update settings with feature-flag.
|
|
|
|
const callIntegrationEnabled = this.props.flags[CALL_INTEGRATION_ENABLED];
|
|
|
|
|
|
|
|
if (typeof callIntegrationEnabled !== 'undefined') {
|
|
|
|
dispatch(updateSettings({ disableCallIntegration: !callIntegrationEnabled }));
|
|
|
|
}
|
2019-01-22 10:32:18 +00:00
|
|
|
});
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 21:06:41 +00:00
|
|
|
/**
|
|
|
|
* Attempts to disable the use of React Native
|
|
|
|
* {@link ExceptionsManager#handleException} on platforms and in
|
|
|
|
* configurations on/in which the use of the method in questions has been
|
|
|
|
* determined to be undesirable. For example, React Native will
|
2018-07-12 16:16:57 +00:00
|
|
|
* (intentionally) throw an unhandled {@code JavascriptException} for an
|
2017-01-05 21:06:41 +00:00
|
|
|
* unhandled JavaScript error in the Release configuration. This will
|
2018-07-12 16:16:57 +00:00
|
|
|
* effectively kill the app. In accord with the Web, do not kill the app.
|
2017-01-05 21:06:41 +00:00
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_maybeDisableExceptionsManager() {
|
|
|
|
if (__DEV__) {
|
|
|
|
// As mentioned above, only the Release configuration was observed
|
|
|
|
// to suffer.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Platform.OS !== 'android') {
|
|
|
|
// A solution based on RTCSetFatalHandler was implemented on iOS and
|
|
|
|
// it is preferred because it is at a later step of the
|
|
|
|
// error/exception handling and it is specific to fatal
|
2018-07-12 16:16:57 +00:00
|
|
|
// errors/exceptions which were observed to kill the app. The
|
|
|
|
// solution implemented bellow was tested on Android only so it is
|
|
|
|
// considered safest to use it there only.
|
2017-01-05 21:06:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const oldHandler = global.ErrorUtils.getGlobalHandler();
|
|
|
|
const newHandler = _handleException;
|
|
|
|
|
|
|
|
if (!oldHandler || oldHandler !== newHandler) {
|
|
|
|
newHandler.next = oldHandler;
|
|
|
|
global.ErrorUtils.setGlobalHandler(newHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:53:24 +00:00
|
|
|
/**
|
|
|
|
* Renders the platform specific dialog container.
|
|
|
|
*
|
|
|
|
* @returns {React$Element}
|
|
|
|
*/
|
|
|
|
_renderDialogContainer() {
|
|
|
|
return (
|
|
|
|
<DialogContainer />
|
|
|
|
);
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
2017-01-05 21:06:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a (possibly unhandled) JavaScript error by preventing React Native
|
|
|
|
* from converting a fatal error into an unhandled native exception which will
|
2018-07-12 16:16:57 +00:00
|
|
|
* kill the app.
|
2017-01-05 21:06:41 +00:00
|
|
|
*
|
|
|
|
* @param {Error} error - The (possibly unhandled) JavaScript error to handle.
|
2018-07-12 16:16:57 +00:00
|
|
|
* @param {boolean} fatal - If the specified error is fatal, {@code true};
|
|
|
|
* otherwise, {@code false}.
|
2017-01-05 21:06:41 +00:00
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _handleException(error, fatal) {
|
|
|
|
if (fatal) {
|
|
|
|
// In the Release configuration, React Native will (intentionally) throw
|
|
|
|
// an unhandled JavascriptException for an unhandled JavaScript error.
|
2018-07-12 16:16:57 +00:00
|
|
|
// This will effectively kill the app. In accord with the Web, do not
|
|
|
|
// kill the app.
|
2018-07-30 14:38:25 +00:00
|
|
|
logger.error(error);
|
2017-01-05 21:06:41 +00:00
|
|
|
} else {
|
|
|
|
// Forward to the next globalHandler of ErrorUtils.
|
2018-07-12 16:16:57 +00:00
|
|
|
const { next } = _handleException;
|
2017-01-05 21:06:41 +00:00
|
|
|
|
|
|
|
typeof next === 'function' && next(error, fatal);
|
|
|
|
}
|
|
|
|
}
|