-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 a switch on dev and staging to force offline mode #12135
Changes from all commits
075f04f
acabf93
5101892
587955a
294101e
2e8dea9
3b79301
036b718
d4f7f2d
70c5008
14bbfd8
b6db0a7
a16d31a
6ba03a9
db4ce83
a96133b
6fada1a
1bbe8ae
3608ff4
16802f0
2d1c45f
6d86036
41fa6c1
e4d0e3f
09007c1
3104a7e
5d44b69
a467667
7960bdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import Pusher from './library'; | ||
import TYPE from './EventType'; | ||
import Log from '../Log'; | ||
|
||
let shouldForceOffline = false; | ||
Onyx.connect({ | ||
key: ONYXKEYS.NETWORK, | ||
callback: (network) => { | ||
if (!network) { | ||
return; | ||
} | ||
shouldForceOffline = Boolean(network.shouldForceOffline); | ||
}, | ||
}); | ||
|
||
let socket; | ||
const socketEventCallbacks = []; | ||
let customAuthorizer; | ||
|
@@ -112,6 +125,11 @@ function bindEventToChannel(channel, eventName, eventCallback = () => {}) { | |
|
||
const chunkedDataEvents = {}; | ||
const callback = (eventData) => { | ||
if (shouldForceOffline) { | ||
Log.info('[Pusher] Ignoring a Push event because shouldForceOffline = true'); | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. coming from #28063, also check |
||
|
||
let data; | ||
try { | ||
data = _.isObject(eventData) ? eventData : JSON.parse(eventData); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,16 @@ Onyx.connect({ | |
}); | ||
|
||
let currentIsOffline; | ||
let currentShouldForceOffline; | ||
Onyx.connect({ | ||
key: ONYXKEYS.NETWORK, | ||
callback: val => currentIsOffline = val.isOffline, | ||
callback: (network) => { | ||
if (!network) { | ||
return; | ||
} | ||
currentIsOffline = network.isOffline; | ||
currentShouldForceOffline = Boolean(network.shouldForceOffline); | ||
}, | ||
}); | ||
|
||
/** | ||
|
@@ -31,6 +38,7 @@ function clearStorageAndRedirect(errorMessage) { | |
const activeClients = currentActiveClients; | ||
const preferredLocale = currentPreferredLocale; | ||
const isOffline = currentIsOffline; | ||
const shouldForceOffline = currentShouldForceOffline; | ||
|
||
// Clearing storage discards the authToken. This causes a redirect to the SignIn screen | ||
Onyx.clear() | ||
|
@@ -41,7 +49,10 @@ function clearStorageAndRedirect(errorMessage) { | |
if (activeClients && activeClients.length > 0) { | ||
Onyx.set(ONYXKEYS.ACTIVE_CLIENTS, activeClients); | ||
} | ||
if (isOffline) { | ||
|
||
// After signing out, set ourselves as offline if we were offline before logging out and we are not forcing it. | ||
// If we are forcing offline, ignore it while signed out, otherwise it would require a refresh because there's no way to toggle the switch to go back online while signed out. | ||
if (isOffline && !shouldForceOffline) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also seems like a good opportunity to just use the "real" value of the network and just let the sign in screen be not testable. If we were logged in before and had If we want to be able to use "forced offline mode" on the sign in screen then we can do a more global switch that can be used from anywhere. The way we've done it here we can only set it on or off if we are logged in and looking at the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exact purpose of this change is to prevent the user from being unable to sign in if they log out when shouldForceOffline is true. |
||
Onyx.set(ONYXKEYS.NETWORK, {isOffline}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine if we want to start with this - but I personally think this would be more useful if you could quickly switch to offline from anywhere. Maybe with a secret gesture or something. Having to navigate to the
/settings/preferences
screen and back to whatever you were doing before is not ideal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the toggle is a good first step for now. I like the gesture idea, as long as its difficult to accidentally trigger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking maybe 4 or 5 quick taps in a row?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in an ideal world, we could launch a PopOver containing the debug tools settings page.
As for how to launch this, 4-5 taps still seems too easy to accidentally trigger IMO. By any chance do we have a list of currently unused recognized gestures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Launching a Popover with the debug tools is a good idea, that way it's easy to observe the state of the settings.
To be clear we would only add this gesture on staging or dev, or maybe just on dev. I don't think there would be a huge consequence to triggering it if it just opens a popover. I really have no idea about gestures, I'll create an issue to add this and we can investigate there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a follow up issue https://github.com/Expensify/Expensify/issues/246352