59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
// Metro module 1211 (f1212).
|
|
import ApexExperimentStore from "../../experiments/apex/ApexExperimentStore";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import AppStateStore from "../../../stores/native/AppStateStore";
|
|
import { AppStates } from "../../../Constants";
|
|
import LifecycleManager from "../../../lib/LifecycleManager";
|
|
import ZoomedInTelemetry from "./channels/ZoomedInTelemetry";
|
|
import ProcessUtils_native from "../../../utils/ProcessUtils.native";
|
|
import Dispatcher from "../../../Dispatcher";
|
|
import TelemetryRingNative_android from "./TelemetryRingNative.android";
|
|
class TelemetryRingLifecycleImpl extends LifecycleManager {
|
|
_initialized = false;
|
|
_experimentUnsubscribe = null;
|
|
_handleEligibilityChange = () => {
|
|
this._updateZoomedInExport();
|
|
};
|
|
_handleLogout = () => {
|
|
TelemetryRingNative_android.clear();
|
|
ZoomedInTelemetry.reset();
|
|
};
|
|
_updateZoomedInExport() {
|
|
const state = AppStateStore.getState();
|
|
ProcessUtils_native.setShouldCollectHermesInstrumentedStats(state === AppStates.ACTIVE && ZoomedInTelemetry.shouldRun());
|
|
if (state === AppStates.ACTIVE) {
|
|
ZoomedInTelemetry.start();
|
|
} else {
|
|
ZoomedInTelemetry.stop();
|
|
}
|
|
}
|
|
_initialize() {
|
|
if (!this._initialized) {
|
|
this._initialized = true;
|
|
Dispatcher.subscribe("LOGOUT", this._handleLogout);
|
|
AppStateStore.addChangeListener(this._handleEligibilityChange);
|
|
UserStore.addChangeListener(this._handleEligibilityChange);
|
|
ApexExperimentStore.addChangeListener(this._handleEligibilityChange);
|
|
this._experimentUnsubscribe = () => {
|
|
ApexExperimentStore.removeChangeListener(this._handleEligibilityChange);
|
|
};
|
|
ZoomedInTelemetry.initialize();
|
|
this._updateZoomedInExport();
|
|
}
|
|
}
|
|
_terminate() {
|
|
Dispatcher.unsubscribe("LOGOUT", this._handleLogout);
|
|
AppStateStore.removeChangeListener(this._handleEligibilityChange);
|
|
UserStore.removeChangeListener(this._handleEligibilityChange);
|
|
if (this._experimentUnsubscribe != null) {
|
|
this._experimentUnsubscribe();
|
|
this._experimentUnsubscribe = null;
|
|
}
|
|
ZoomedInTelemetry.stop();
|
|
ProcessUtils_native.setShouldCollectHermesInstrumentedStats(false);
|
|
this._initialized = false;
|
|
}
|
|
}
|
|
const telemetryRingLifecycleImpl = new TelemetryRingLifecycleImpl();
|
|
export default telemetryRingLifecycleImpl;
|