2024-01-05 06:20:55 +01:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-06-21 01:10:23 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-23 02:36:44 +01:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart' hide Store;
|
2022-06-21 01:10:23 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/backup/backup.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/authentication.provider.dart';
|
|
|
|
import 'package:immich_mobile/providers/gallery_permission.provider.dart';
|
2022-06-21 01:10:23 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
2023-07-28 05:05:27 +02:00
|
|
|
import 'package:logging/logging.dart';
|
2022-06-21 01:10:23 +02:00
|
|
|
|
2024-01-15 17:50:33 +01:00
|
|
|
@RoutePage()
|
2022-06-21 01:10:23 +02:00
|
|
|
class SplashScreenPage extends HookConsumerWidget {
|
2024-01-27 17:14:32 +01:00
|
|
|
const SplashScreenPage({super.key});
|
2022-06-21 01:10:23 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-11-20 18:43:10 +01:00
|
|
|
final apiService = ref.watch(apiServiceProvider);
|
2023-03-23 02:36:44 +01:00
|
|
|
final serverUrl = Store.tryGet(StoreKey.serverUrl);
|
2024-07-30 20:15:48 +02:00
|
|
|
final endpoint = Store.tryGet(StoreKey.serverEndpoint);
|
2023-03-23 02:36:44 +01:00
|
|
|
final accessToken = Store.tryGet(StoreKey.accessToken);
|
2023-07-28 05:05:27 +02:00
|
|
|
final log = Logger("SplashScreenPage");
|
2022-06-21 01:10:23 +02:00
|
|
|
|
|
|
|
void performLoggingIn() async {
|
2024-07-30 20:15:48 +02:00
|
|
|
bool isAuthSuccess = false;
|
2024-04-23 23:09:10 +02:00
|
|
|
|
2024-07-30 20:15:48 +02:00
|
|
|
if (accessToken != null && serverUrl != null && endpoint != null) {
|
|
|
|
apiService.setEndpoint(endpoint);
|
2022-06-21 01:10:23 +02:00
|
|
|
|
2023-11-13 21:15:36 +01:00
|
|
|
try {
|
2024-07-30 20:15:48 +02:00
|
|
|
isAuthSuccess = await ref
|
2023-11-13 21:15:36 +01:00
|
|
|
.read(authenticationProvider.notifier)
|
|
|
|
.setSuccessLoginInfo(
|
|
|
|
accessToken: accessToken,
|
|
|
|
serverUrl: serverUrl,
|
|
|
|
);
|
|
|
|
} catch (error, stackTrace) {
|
|
|
|
log.severe(
|
2024-02-24 04:38:57 +01:00
|
|
|
'Cannot set success login info',
|
2023-11-13 21:15:36 +01:00
|
|
|
error,
|
|
|
|
stackTrace,
|
|
|
|
);
|
|
|
|
}
|
2023-03-15 22:29:07 +01:00
|
|
|
} else {
|
2024-07-30 20:15:48 +02:00
|
|
|
isAuthSuccess = false;
|
2024-04-23 23:09:10 +02:00
|
|
|
log.severe(
|
2024-07-30 20:15:48 +02:00
|
|
|
'Missing authentication, server, or endpoint info from the local store',
|
2024-04-23 23:09:10 +02:00
|
|
|
);
|
2024-07-30 20:15:48 +02:00
|
|
|
}
|
2024-04-23 23:09:10 +02:00
|
|
|
|
2024-07-30 20:15:48 +02:00
|
|
|
if (!isAuthSuccess) {
|
|
|
|
log.severe(
|
|
|
|
'Unable to login using offline or online methods - Logging out completely',
|
|
|
|
);
|
2024-04-23 23:09:10 +02:00
|
|
|
ref.read(authenticationProvider.notifier).logout();
|
2024-01-05 06:20:55 +01:00
|
|
|
context.replaceRoute(const LoginRoute());
|
2024-07-30 20:15:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.replaceRoute(const TabControllerRoute());
|
|
|
|
|
|
|
|
final hasPermission =
|
|
|
|
await ref.read(galleryPermissionNotifier.notifier).hasPermission;
|
|
|
|
if (hasPermission) {
|
|
|
|
// Resume backup (if enable) then navigate
|
|
|
|
ref.watch(backupProvider.notifier).resumeBackup();
|
2022-06-21 01:10:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
2024-07-30 20:15:48 +02:00
|
|
|
performLoggingIn();
|
2022-07-13 14:23:48 +02:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-06-21 01:10:23 +02:00
|
|
|
|
2023-02-06 07:41:07 +01:00
|
|
|
return const Scaffold(
|
2022-06-21 01:10:23 +02:00
|
|
|
body: Center(
|
2023-02-06 07:41:07 +01:00
|
|
|
child: Image(
|
2024-03-13 18:14:59 +01:00
|
|
|
image: AssetImage('assets/immich-logo.png'),
|
2023-02-06 07:41:07 +01:00
|
|
|
width: 80,
|
|
|
|
filterQuality: FilterQuality.high,
|
2022-06-21 01:10:23 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|