fix(mobile): don't block startup when offline (#32652)
* fix(mobile): don't block startup when offline * chore: implement suggestions --------- Co-authored-by: Santo Shakil <santoshakil@users.noreply.github.com> (cherry picked from commit 32b137ab3713545324873f552adb51b9ef2aecde)
This commit is contained in:
@@ -299,7 +299,7 @@ class SplashScreenPageState extends ConsumerState<SplashScreenPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
unawaited(ref.read(authProvider.notifier).setOpenApiServiceEndpoint().whenComplete(() => resumeSession()));
|
||||
unawaited(resumeSession());
|
||||
}
|
||||
|
||||
Future<void> resumeSession() async {
|
||||
@@ -314,13 +314,28 @@ class SplashScreenPageState extends ConsumerState<SplashScreenPage> {
|
||||
final backupNotifier = ref.read(backupProvider.notifier);
|
||||
final lifeCycle = ref.read(appStateProvider.notifier);
|
||||
final viewIntentHandler = ref.read(viewIntentHandlerProvider);
|
||||
final authNotifier = ref.read(authProvider.notifier);
|
||||
|
||||
unawaited(
|
||||
ref
|
||||
.read(authProvider.notifier)
|
||||
.saveAuthInfo(accessToken: accessToken)
|
||||
authNotifier
|
||||
.setOpenApiServiceEndpoint()
|
||||
.catchError((Object error, StackTrace stackTrace) {
|
||||
log.warning('Failed to resolve server endpoint', error, stackTrace);
|
||||
return null;
|
||||
})
|
||||
.then((_) async {
|
||||
if (Store.tryGet(StoreKey.accessToken) != accessToken) {
|
||||
return false;
|
||||
}
|
||||
await authNotifier.saveAuthInfo(accessToken: accessToken);
|
||||
return true;
|
||||
})
|
||||
.then(
|
||||
(_) async {
|
||||
(sessionResumed) async {
|
||||
if (!sessionResumed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
wsProvider.connect();
|
||||
unawaited(infoProvider.getServerInfo());
|
||||
|
||||
@@ -115,9 +115,11 @@ class ApiService {
|
||||
Future<bool> _isEndpointAvailable(String serverUrl) async {
|
||||
final endpoint = serverUrl.endsWith('/api') ? serverUrl : '$serverUrl/api';
|
||||
|
||||
// Probe with a throwaway client so the shared client keeps pointing at the active endpoint
|
||||
final probeClient = ApiClient(basePath: endpoint)..client = NetworkRepository.client;
|
||||
|
||||
try {
|
||||
setEndpoint(endpoint);
|
||||
await serverInfoApi.pingServer().timeout(const Duration(seconds: 5));
|
||||
await ServerApi(probeClient).pingServer().timeout(const Duration(seconds: 5));
|
||||
} on TimeoutException catch (_) {
|
||||
return false;
|
||||
} on SocketException catch (_) {
|
||||
|
||||
Reference in New Issue
Block a user