Skip to content

Commit

Permalink
fix: disable communication in offline mode (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
irishrain authored Dec 30, 2024
1 parent e09034f commit ffe905d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions kitchenowl/lib/cubits/auth_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ class AuthCubit extends Cubit<AuthState> {
return null;
}

Future<void> refresh() => ApiService.getInstance().refresh();
Future<void> refresh() {
// Don't refresh if we're in forced offline mode
if (_forcedOfflineMode) {
return Future.value();
}
return ApiService.getInstance().refresh();
}

Future<void> refreshUser() async {
if (state is Authenticated) {
Expand Down Expand Up @@ -285,8 +291,12 @@ class AuthCubit extends Cubit<AuthState> {
void setForcedOfflineMode(bool forcedOfflineMode) async {
_forcedOfflineMode = forcedOfflineMode;
await PreferenceStorage.getInstance().writeBool(key: 'forcedOfflineMode', value: forcedOfflineMode);
updateState(); // force refresh if state stays the same
refresh();
// Always update state to reflect the change immediately
updateState();
if (!forcedOfflineMode) {
// When disabling offline mode, also do a full refresh to reconnect
refresh();
}
}
}

Expand Down

0 comments on commit ffe905d

Please sign in to comment.