mattermost-mobile/app/mattermost_managed/mattermost-managed.android.js
Daniel Espino García 4c8594d330
Add linter rules for import order and type member delimiters (#5514)
* Add linter rules for import order and type member delimiters

* Remove unneeded group

* Group all app/* imports before the internal imports

* Move app/ imports before parent imports

* Separate @node_modules imports into a different group

* Substitute app paths by aliases

* Fix @node_modules import order and add test related modules

* Add aliases for types and test, and group import types
2021-07-23 11:06:04 +02:00

87 lines
2.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {NativeModules, DeviceEventEmitter} from 'react-native';
import {emptyFunction} from '@utils/general';
const {MattermostManaged} = NativeModules;
const listeners = [];
let cachedConfig = {};
let LocalAuth;
let JailMonkey;
export default {
addEventListener: (name, callback) => {
const listener = DeviceEventEmitter.addListener(name, (config) => {
cachedConfig = 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: (opts) => {
if (!LocalAuth) {
LocalAuth = require('react-native-local-auth');
}
return LocalAuth.auth(opts);
},
blurAppScreen: emptyFunction,
appGroupIdentifier: null,
hasSafeAreaInsets: null,
isRunningInSplitView: MattermostManaged.isRunningInSplitView,
getConfig: async () => {
try {
cachedConfig = await MattermostManaged.getConfig();
} catch (error) {
// do nothing...
}
return cachedConfig;
},
getCachedConfig: () => {
return cachedConfig;
},
goToSecuritySettings: MattermostManaged.goToSecuritySettings,
isDeviceSecure: async () => {
try {
if (!LocalAuth) {
LocalAuth = require('react-native-local-auth');
}
return await LocalAuth.isDeviceSecure();
} catch (err) {
return false;
}
},
isTrustedDevice: () => {
if (__DEV__) {
return true;
}
if (!JailMonkey) {
JailMonkey = require('jail-monkey');
}
return JailMonkey.trustFall();
},
supportsFaceId: async () => false,
quitApp: MattermostManaged.quitApp,
};