Skip to content

Commit

Permalink
PR: addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ddshd committed Jul 16, 2023
1 parent f7a194a commit 6e22da3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
12 changes: 4 additions & 8 deletions mobile/lib/modules/login/providers/authentication.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,11 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
User? user;

bool retResult = false;
User? offlineUser = Store.tryGet(StoreKey.currentUser);

if (offlineLogin) {
User? offlineUser = Store.tryGet(StoreKey.currentUser);

if (offlineUser != null) {
user = offlineUser;
retResult = false;
}

if (offlineLogin && offlineUser != null) {
user = offlineUser;
retResult = false;
} else {
UserResponseDto? userResponseDto;
try {
Expand Down
12 changes: 7 additions & 5 deletions mobile/lib/shared/services/api.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class ApiService {
Future<String> _resolveEndpoint(String serverUrl) async {
final url = sanitizeUrl(serverUrl);

await _isEndpointAvailable(serverUrl);
if (!await _isEndpointAvailable(serverUrl)) {
throw ApiException(503, "Server is not reachable");
}

// Check for /.well-known/immich
final wellKnownEndpoint = await _getWellKnownEndpoint(url);
Expand All @@ -74,7 +76,7 @@ class ApiService {
return url;
}

Future<void> _isEndpointAvailable(String serverUrl) async {
Future<bool> _isEndpointAvailable(String serverUrl) async {
final Client client = Client();

if (!serverUrl.endsWith('/api')) {
Expand All @@ -89,12 +91,12 @@ class ApiService {
Uri.parse(serverUrl),
)
.timeout(const Duration(seconds: 5));
return;
} on TimeoutException catch (_) {
rethrow;
return false;
} on SocketException catch (_) {
rethrow;
return false;
}
return true;
}

Future<String> _getWellKnownEndpoint(String baseUrl) async {
Expand Down
14 changes: 12 additions & 2 deletions mobile/lib/shared/views/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:immich_mobile/modules/onboarding/providers/gallery_permission.pr
import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/shared/models/store.dart';
import 'package:immich_mobile/shared/providers/api.provider.dart';
import 'package:logging/logging.dart';
import 'package:openapi/api.dart';

class SplashScreenPage extends HookConsumerWidget {
const SplashScreenPage({Key? key}) : super(key: key);
Expand All @@ -17,6 +19,7 @@ class SplashScreenPage extends HookConsumerWidget {
final apiService = ref.watch(apiServiceProvider);
final serverUrl = Store.tryGet(StoreKey.serverUrl);
final accessToken = Store.tryGet(StoreKey.accessToken);
final _log = Logger("SplashScreenPage");

void performLoggingIn() async {
bool isSuccess = false;
Expand All @@ -25,9 +28,16 @@ class SplashScreenPage extends HookConsumerWidget {
try {
// Resolve API server endpoint from user provided serverUrl
await apiService.resolveAndSetEndpoint(serverUrl);
} catch (e) {
} on ApiException catch (e) {
// okay, try to continue anyway if offline
deviceIsOffline = true;
if (e.code == 503) {
deviceIsOffline = true;
_log.fine("Device seems to be offline upon launch");
} else {
_log.severe(e);
}
} catch (e) {
_log.severe(e);
}

isSuccess =
Expand Down

0 comments on commit 6e22da3

Please sign in to comment.