mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-06 10:50:13 +00:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {AppState, Platform, type NativeEventSubscription} from 'react-native';
|
|
|
|
import {callsOnAppStateChange} from '@calls/state';
|
|
import {logDebug} from '@utils/log';
|
|
|
|
let appStateChangeListener: NativeEventSubscription | undefined;
|
|
let appStateBlurListener: NativeEventSubscription | undefined;
|
|
let appStateFocusListener: NativeEventSubscription | undefined;
|
|
|
|
const initialize = () => {
|
|
logDebug('CallsManager: Initializing');
|
|
if (Platform.OS === 'android') {
|
|
appStateBlurListener = AppState.addEventListener('blur', () => {
|
|
callsOnAppStateChange('inactive');
|
|
});
|
|
appStateFocusListener = AppState.addEventListener('focus', () => {
|
|
callsOnAppStateChange('active');
|
|
});
|
|
} else {
|
|
appStateChangeListener = AppState.addEventListener('change', callsOnAppStateChange);
|
|
}
|
|
};
|
|
|
|
const cleanup = () => {
|
|
appStateChangeListener?.remove();
|
|
appStateBlurListener?.remove();
|
|
appStateFocusListener?.remove();
|
|
};
|
|
|
|
export const CallsManager = {
|
|
initialize,
|
|
cleanup,
|
|
};
|