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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
unawaited(ref.read(authProvider.notifier).setOpenApiServiceEndpoint().whenComplete(() => resumeSession()));
|
unawaited(resumeSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> resumeSession() async {
|
Future<void> resumeSession() async {
|
||||||
@@ -314,13 +314,28 @@ class SplashScreenPageState extends ConsumerState<SplashScreenPage> {
|
|||||||
final backupNotifier = ref.read(backupProvider.notifier);
|
final backupNotifier = ref.read(backupProvider.notifier);
|
||||||
final lifeCycle = ref.read(appStateProvider.notifier);
|
final lifeCycle = ref.read(appStateProvider.notifier);
|
||||||
final viewIntentHandler = ref.read(viewIntentHandlerProvider);
|
final viewIntentHandler = ref.read(viewIntentHandlerProvider);
|
||||||
|
final authNotifier = ref.read(authProvider.notifier);
|
||||||
|
|
||||||
unawaited(
|
unawaited(
|
||||||
ref
|
authNotifier
|
||||||
.read(authProvider.notifier)
|
.setOpenApiServiceEndpoint()
|
||||||
.saveAuthInfo(accessToken: accessToken)
|
.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(
|
.then(
|
||||||
(_) async {
|
(sessionResumed) async {
|
||||||
|
if (!sessionResumed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wsProvider.connect();
|
wsProvider.connect();
|
||||||
unawaited(infoProvider.getServerInfo());
|
unawaited(infoProvider.getServerInfo());
|
||||||
|
|||||||
@@ -115,9 +115,11 @@ class ApiService {
|
|||||||
Future<bool> _isEndpointAvailable(String serverUrl) async {
|
Future<bool> _isEndpointAvailable(String serverUrl) async {
|
||||||
final endpoint = serverUrl.endsWith('/api') ? serverUrl : '$serverUrl/api';
|
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 {
|
try {
|
||||||
setEndpoint(endpoint);
|
await ServerApi(probeClient).pingServer().timeout(const Duration(seconds: 5));
|
||||||
await serverInfoApi.pingServer().timeout(const Duration(seconds: 5));
|
|
||||||
} on TimeoutException catch (_) {
|
} on TimeoutException catch (_) {
|
||||||
return false;
|
return false;
|
||||||
} on SocketException catch (_) {
|
} on SocketException catch (_) {
|
||||||
|
|||||||
Reference in New Issue
Block a user