Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offline status log #41719

Merged
merged 13 commits into from
Jun 3, 2024
12 changes: 11 additions & 1 deletion src/libs/NetworkConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,18 @@ Onyx.connect({
shouldForceOffline = currentShouldForceOffline;
if (shouldForceOffline) {
setOfflineStatus(true);
Log.info(`[NetworkStatus] Setting "offlineStatus" to "true" because user is under force offline`);
} else {
// If we are no longer forcing offline fetch the NetInfo to set isOffline appropriately
NetInfo.fetch().then((state) => setOfflineStatus((state.isInternetReachable ?? false) === false));
NetInfo.fetch().then((state) => {
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
const isInternetReachable = Boolean(state.isInternetReachable);
setOfflineStatus(isInternetReachable);
Log.info(
`[NetworkStatus] The force-offline mode was turned off. Getting the device network status from NetInfo. Network state: ${JSON.stringify(
state,
)}. Setting the offline status to: ${isInternetReachable}.`,
);
});
}
},
});
Expand Down Expand Up @@ -151,6 +160,7 @@ function subscribeToNetworkStatus(): () => void {
return;
}
setOfflineStatus(state.isInternetReachable === false);
Log.info(`[NetworkStatus] NetInfo.addEventListener event coming, setting "offlineStatus" to ${Boolean(state.isInternetReachable)} with network state: ${JSON.stringify(state)}`);
setNetWorkStatus(state.isInternetReachable);
});

Expand Down
Loading