From a5ad81d02b80d2e39a483473bdaeb7ae022c7c2e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 7 May 2024 10:17:19 +0700 Subject: [PATCH 1/8] Add offline status log --- src/libs/NetworkConnection.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 2077a168b4b9..940e97da1126 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -63,9 +63,17 @@ 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) => { + setOfflineStatus((state.isInternetReachable ?? false) === false); + Log.info( + `[NetworkStatus] The user is not under force offline, calling NetInfo.fetch, setting "offlineStatus" to ${ + (state.isInternetReachable ?? false) === false + } with network state: ${JSON.stringify(state)}`, + ); + }); } }, }); @@ -110,6 +118,11 @@ function subscribeToNetInfo(): void { return; } setOfflineStatus((state.isInternetReachable ?? false) === false); + Log.info( + `[NetworkStatus] NetInfo.addEventListener event coming, setting "offlineStatus" to ${(state.isInternetReachable ?? false) === false} with network state: ${JSON.stringify( + state, + )}`, + ); let networkStatus; if (!isBoolean(state.isInternetReachable)) { networkStatus = CONST.NETWORK.NETWORK_STATUS.UNKNOWN; From c845d3e7331c04b4f626d11bd1eb87fa5346a52e Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 8 May 2024 23:32:32 +0700 Subject: [PATCH 2/8] Update src/libs/NetworkConnection.ts Co-authored-by: Hayata Suenaga --- src/libs/NetworkConnection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 940e97da1126..bb934a19e8e5 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -67,7 +67,7 @@ Onyx.connect({ } else { // If we are no longer forcing offline fetch the NetInfo to set isOffline appropriately NetInfo.fetch().then((state) => { - setOfflineStatus((state.isInternetReachable ?? false) === false); + setOfflineStatus(Boolean(state.isInternetReachable)); Log.info( `[NetworkStatus] The user is not under force offline, calling NetInfo.fetch, setting "offlineStatus" to ${ (state.isInternetReachable ?? false) === false From 3f3af72e664f38615af00b3e61c9b9283b6114ad Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 8 May 2024 23:32:38 +0700 Subject: [PATCH 3/8] Update src/libs/NetworkConnection.ts Co-authored-by: Hayata Suenaga --- src/libs/NetworkConnection.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index bb934a19e8e5..3e834b6e6406 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -69,9 +69,7 @@ Onyx.connect({ NetInfo.fetch().then((state) => { setOfflineStatus(Boolean(state.isInternetReachable)); Log.info( - `[NetworkStatus] The user is not under force offline, calling NetInfo.fetch, setting "offlineStatus" to ${ - (state.isInternetReachable ?? false) === false - } with network state: ${JSON.stringify(state)}`, +`[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: ${Boolean(state.isInternetReachable)}.`, ); }); } From 005cfb344d1187c9082cbcf4bc05d51033a266bf Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 9 May 2024 01:00:50 +0700 Subject: [PATCH 4/8] fix lint --- src/libs/NetworkConnection.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 3e834b6e6406..6accdb220f5e 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -69,7 +69,9 @@ Onyx.connect({ NetInfo.fetch().then((state) => { setOfflineStatus(Boolean(state.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: ${Boolean(state.isInternetReachable)}.`, + `[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: ${Boolean(state.isInternetReachable)}.`, ); }); } From c7ab997b4d1b464aeb5dfa052607f6e608a72bb6 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 9 May 2024 15:11:28 +0700 Subject: [PATCH 5/8] define a new variable --- src/libs/NetworkConnection.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 6accdb220f5e..c618dff4df32 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -67,11 +67,12 @@ Onyx.connect({ } else { // If we are no longer forcing offline fetch the NetInfo to set isOffline appropriately NetInfo.fetch().then((state) => { - setOfflineStatus(Boolean(state.isInternetReachable)); + 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: ${Boolean(state.isInternetReachable)}.`, + )}. Setting the offline status to: ${isInternetReachable}.`, ); }); } From 25f3565af74be6181770d0179484e6e437ac5d98 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 9 May 2024 15:35:27 +0700 Subject: [PATCH 6/8] fix lint --- src/libs/NetworkConnection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index c618dff4df32..aa4481bc9ab6 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -67,7 +67,7 @@ Onyx.connect({ } else { // If we are no longer forcing offline fetch the NetInfo to set isOffline appropriately NetInfo.fetch().then((state) => { - const isInternetReachable = Boolean(state.isInternetReachable) + 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( From 7619a7ef60cd3443221d83af146a49e0a3e6cf6d Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Thu, 16 May 2024 00:00:22 +0700 Subject: [PATCH 7/8] Update src/libs/NetworkConnection.ts Co-authored-by: Hayata Suenaga --- src/libs/NetworkConnection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 824968195906..396f5257b1cb 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -161,7 +161,7 @@ function subscribeToNetworkStatus(): () => void { } setOfflineStatus(state.isInternetReachable === false); Log.info( - `[NetworkStatus] NetInfo.addEventListener event coming, setting "offlineStatus" to ${(state.isInternetReachable ?? false) === false} with network state: ${JSON.stringify( + `[NetworkStatus] NetInfo.addEventListener event coming, setting "offlineStatus" to ${Boolean(state.isInternetReachable)} with network state: ${JSON.stringify( state, )}`, ); From bd2cb24aed5c8f34fb38b7263c6d3ba8f497be1a Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 16 May 2024 00:22:36 +0700 Subject: [PATCH 8/8] fix lint --- src/libs/NetworkConnection.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 396f5257b1cb..b3dd24fcd4ae 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -160,11 +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, - )}`, - ); + Log.info(`[NetworkStatus] NetInfo.addEventListener event coming, setting "offlineStatus" to ${Boolean(state.isInternetReachable)} with network state: ${JSON.stringify(state)}`); setNetWorkStatus(state.isInternetReachable); });