2022-06-21 01:10:23 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-03-23 03:36:44 +02: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';
|
|
|
|
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
2023-02-28 18:22:18 +02:00
|
|
|
import 'package:immich_mobile/modules/onboarding/providers/gallery_permission.provider.dart';
|
2022-06-21 01:10:23 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2023-03-23 03:36:44 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2022-11-20 19:43:10 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/api.provider.dart';
|
2022-06-21 01:10:23 +02:00
|
|
|
|
|
|
|
class SplashScreenPage extends HookConsumerWidget {
|
|
|
|
const SplashScreenPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-11-20 19:43:10 +02:00
|
|
|
final apiService = ref.watch(apiServiceProvider);
|
2023-03-23 03:36:44 +02:00
|
|
|
final serverUrl = Store.tryGet(StoreKey.serverUrl);
|
|
|
|
final accessToken = Store.tryGet(StoreKey.accessToken);
|
2022-06-21 01:10:23 +02:00
|
|
|
|
|
|
|
void performLoggingIn() async {
|
2023-03-15 23:29:07 +02:00
|
|
|
bool isSuccess = false;
|
2023-03-23 03:36:44 +02:00
|
|
|
if (accessToken != null && serverUrl != null) {
|
2023-03-15 23:29:07 +02:00
|
|
|
try {
|
2023-01-19 17:45:37 +02:00
|
|
|
// Resolve API server endpoint from user provided serverUrl
|
2023-03-23 03:36:44 +02:00
|
|
|
await apiService.resolveAndSetEndpoint(serverUrl);
|
2023-03-15 23:29:07 +02:00
|
|
|
} catch (e) {
|
|
|
|
// okay, try to continue anyway if offline
|
|
|
|
}
|
2022-06-21 01:10:23 +02:00
|
|
|
|
2023-03-15 23:29:07 +02:00
|
|
|
isSuccess =
|
|
|
|
await ref.read(authenticationProvider.notifier).setSuccessLoginInfo(
|
2023-03-23 03:36:44 +02:00
|
|
|
accessToken: accessToken,
|
|
|
|
serverUrl: serverUrl,
|
2023-03-15 23:29:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (isSuccess) {
|
|
|
|
final hasPermission =
|
|
|
|
await ref.read(galleryPermissionNotifier.notifier).hasPermission;
|
|
|
|
if (hasPermission) {
|
|
|
|
// Resume backup (if enable) then navigate
|
|
|
|
ref.watch(backupProvider.notifier).resumeBackup();
|
2022-11-20 19:43:10 +02:00
|
|
|
}
|
2023-03-15 23:29:07 +02:00
|
|
|
AutoRouter.of(context).replace(const TabControllerRoute());
|
|
|
|
} else {
|
2022-11-21 13:29:43 +02:00
|
|
|
AutoRouter.of(context).replace(const LoginRoute());
|
2022-06-21 01:10:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
2023-03-23 03:36:44 +02:00
|
|
|
if (serverUrl != null && accessToken != null) {
|
2022-07-13 14:23:48 +02:00
|
|
|
performLoggingIn();
|
|
|
|
} else {
|
2022-10-17 20:04:17 +02:00
|
|
|
AutoRouter.of(context).replace(const LoginRoute());
|
2022-07-13 14:23:48 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-06-21 01:10:23 +02:00
|
|
|
|
2023-02-06 08:41:07 +02:00
|
|
|
return const Scaffold(
|
2022-06-21 01:10:23 +02:00
|
|
|
body: Center(
|
2023-02-06 08:41:07 +02:00
|
|
|
child: Image(
|
|
|
|
image: AssetImage('assets/immich-logo-no-outline.png'),
|
|
|
|
width: 80,
|
|
|
|
filterQuality: FilterQuality.high,
|
2022-06-21 01:10:23 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|