mattermost-mobile/app/mattermost_managed/mattermost-managed.android.js
Jesse Hallam 58b72302d6 update eslint's comma-dangle rule to always-multiline (#1457)
* update eslint's `comma-dangle` rule to `always-multiline`

* add check and fix scripts to package.json

* Invoke `yarn fix` to adopt the updated eslint rules. No other changes are included.
2018-02-23 09:06:02 -05:00

66 lines
1.8 KiB
JavaScript

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {BackHandler, NativeModules, DeviceEventEmitter} from 'react-native';
import LocalAuth from 'react-native-local-auth';
import JailMonkey from 'jail-monkey';
const {MattermostManaged} = NativeModules;
const listeners = [];
let localConfig;
export default {
addEventListener: (name, callback) => {
const listener = DeviceEventEmitter.addListener(name, (config) => {
localConfig = config;
if (callback && typeof callback === 'function') {
callback(config);
}
});
listeners.push(listener);
return listener;
},
clearListeners: () => {
listeners.forEach((listener) => {
listener.remove();
});
},
removeEventListener: (listenerId) => {
const index = listeners.findIndex((listener) => listener === listenerId);
if (index !== -1) {
listenerId.remove();
listeners.splice(index, 1);
}
},
authenticate: LocalAuth.authenticate,
blurAppScreen: MattermostManaged.blurAppScreen,
getConfig: MattermostManaged.getConfig,
getLocalConfig: async () => {
if (!localConfig) {
try {
localConfig = await MattermostManaged.getConfig();
} catch (error) {
// do nothing...
}
}
return localConfig || {};
},
isDeviceSecure: async () => {
try {
return await LocalAuth.isDeviceSecure();
} catch (err) {
return false;
}
},
isTrustedDevice: () => {
if (__DEV__) { //eslint-disable-line no-undef
return true;
}
return JailMonkey.trustFall();
},
quitApp: BackHandler.exitApp,
};