2022-02-03 09:06:44 -07:00
|
|
|
import 'package:flutter/material.dart';
|
2022-02-05 23:07:56 -07:00
|
|
|
import 'package:flutter/services.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:immich_mobile/constants/immich_colors.dart';
|
2022-05-06 05:22:23 -07:00
|
|
|
import 'package:immich_mobile/modules/backup/models/hive_backup_albums.model.dart';
|
2022-06-22 21:14:14 -07:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
2022-04-24 19:33:10 -07:00
|
|
|
import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart';
|
2022-06-11 14:12:06 -07:00
|
|
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2022-03-16 08:19:31 -07:00
|
|
|
import 'package:immich_mobile/routing/tab_navigation_observer.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/app_state.provider.dart';
|
2022-06-22 21:14:14 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2022-06-11 14:12:06 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/release_info.provider.dart';
|
2022-03-21 23:22:04 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2022-02-14 09:40:41 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
2022-04-23 19:08:45 -07:00
|
|
|
import 'package:immich_mobile/shared/views/immich_loading_overlay.dart';
|
2022-06-11 14:12:06 -07:00
|
|
|
import 'package:immich_mobile/shared/views/version_announcement_overlay.dart';
|
2022-06-22 21:14:14 -07:00
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'constants/hive_box.dart';
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
await Hive.initFlutter();
|
2022-05-06 05:22:23 -07:00
|
|
|
|
2022-04-24 19:33:10 -07:00
|
|
|
Hive.registerAdapter(HiveSavedLoginInfoAdapter());
|
2022-05-06 05:22:23 -07:00
|
|
|
Hive.registerAdapter(HiveBackupAlbumsAdapter());
|
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
await Hive.openBox(userInfoBox);
|
2022-04-24 19:33:10 -07:00
|
|
|
await Hive.openBox<HiveSavedLoginInfo>(hiveLoginInfoBox);
|
2022-05-06 05:22:23 -07:00
|
|
|
await Hive.openBox<HiveBackupAlbums>(hiveBackupInfoBox);
|
2022-06-11 14:12:06 -07:00
|
|
|
await Hive.openBox(hiveGithubReleaseInfoBox);
|
2022-02-03 09:06:44 -07:00
|
|
|
|
2022-02-05 23:07:56 -07:00
|
|
|
SystemChrome.setSystemUIOverlayStyle(
|
|
|
|
const SystemUiOverlayStyle(
|
|
|
|
statusBarIconBrightness: Brightness.light,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
runApp(const ProviderScope(child: ImmichApp()));
|
|
|
|
}
|
|
|
|
|
|
|
|
class ImmichApp extends ConsumerStatefulWidget {
|
2022-06-22 21:14:14 -07:00
|
|
|
const ImmichApp({super.key});
|
2022-02-03 09:06:44 -07:00
|
|
|
|
|
|
|
@override
|
2022-06-21 22:23:35 -07:00
|
|
|
ImmichAppState createState() => ImmichAppState();
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
2022-06-21 22:23:35 -07:00
|
|
|
class ImmichAppState extends ConsumerState<ImmichApp>
|
|
|
|
with WidgetsBindingObserver {
|
2022-02-03 09:06:44 -07:00
|
|
|
@override
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
switch (state) {
|
|
|
|
case AppLifecycleState.resumed:
|
|
|
|
debugPrint("[APP STATE] resumed");
|
2022-02-14 09:40:41 -07:00
|
|
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.resumed;
|
2022-06-11 14:12:06 -07:00
|
|
|
|
|
|
|
var isAuthenticated = ref.watch(authenticationProvider).isAuthenticated;
|
|
|
|
|
|
|
|
if (isAuthenticated) {
|
|
|
|
ref.watch(backupProvider.notifier).resumeBackup();
|
|
|
|
ref.watch(assetProvider.notifier).getAllAsset();
|
|
|
|
ref.watch(serverInfoProvider.notifier).getServerVersion();
|
|
|
|
}
|
|
|
|
|
2022-02-14 09:40:41 -07:00
|
|
|
ref.watch(websocketProvider.notifier).connect();
|
2022-06-11 14:12:06 -07:00
|
|
|
|
|
|
|
ref.watch(releaseInfoProvider.notifier).checkGithubReleaseInfo();
|
2022-03-21 23:22:04 -07:00
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
break;
|
2022-03-21 23:22:04 -07:00
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
case AppLifecycleState.inactive:
|
|
|
|
debugPrint("[APP STATE] inactive");
|
2022-02-14 09:40:41 -07:00
|
|
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.inactive;
|
|
|
|
ref.watch(websocketProvider.notifier).disconnect();
|
2022-03-11 10:02:33 -07:00
|
|
|
ref.watch(backupProvider.notifier).cancelBackup();
|
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
break;
|
2022-03-21 23:22:04 -07:00
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
case AppLifecycleState.paused:
|
|
|
|
debugPrint("[APP STATE] paused");
|
2022-02-14 09:40:41 -07:00
|
|
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.paused;
|
2022-02-03 09:06:44 -07:00
|
|
|
break;
|
2022-03-21 23:22:04 -07:00
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
case AppLifecycleState.detached:
|
|
|
|
debugPrint("[APP STATE] detached");
|
2022-02-14 09:40:41 -07:00
|
|
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.detached;
|
2022-02-03 09:06:44 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> initApp() async {
|
2022-05-28 20:35:45 -07:00
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
|
|
|
initApp().then((_) => debugPrint("App Init Completed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2022-05-28 20:35:45 -07:00
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
2022-02-03 09:06:44 -07:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
final _immichRouter = AppRouter();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-06-11 14:12:06 -07:00
|
|
|
ref.watch(releaseInfoProvider.notifier).checkGithubReleaseInfo();
|
|
|
|
|
2022-04-23 19:08:45 -07:00
|
|
|
return MaterialApp(
|
2022-02-03 09:06:44 -07:00
|
|
|
debugShowCheckedModeBanner: false,
|
2022-04-23 19:08:45 -07:00
|
|
|
home: Stack(
|
|
|
|
children: [
|
|
|
|
MaterialApp.router(
|
|
|
|
title: 'Immich',
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
theme: ThemeData(
|
2022-05-29 15:32:30 -07:00
|
|
|
useMaterial3: true,
|
2022-04-23 19:08:45 -07:00
|
|
|
brightness: Brightness.light,
|
|
|
|
primarySwatch: Colors.indigo,
|
|
|
|
fontFamily: 'WorkSans',
|
2022-06-21 22:23:35 -07:00
|
|
|
snackBarTheme: const SnackBarThemeData(
|
|
|
|
contentTextStyle: TextStyle(fontFamily: 'WorkSans')),
|
2022-04-23 19:08:45 -07:00
|
|
|
scaffoldBackgroundColor: immichBackgroundColor,
|
|
|
|
appBarTheme: const AppBarTheme(
|
|
|
|
backgroundColor: immichBackgroundColor,
|
|
|
|
foregroundColor: Colors.indigo,
|
|
|
|
elevation: 1,
|
|
|
|
centerTitle: true,
|
|
|
|
systemOverlayStyle: SystemUiOverlayStyle.dark,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
routeInformationParser: _immichRouter.defaultRouteParser(),
|
2022-06-21 22:23:35 -07:00
|
|
|
routerDelegate: _immichRouter.delegate(
|
|
|
|
navigatorObservers: () => [TabNavigationObserver(ref: ref)]),
|
2022-04-23 19:08:45 -07:00
|
|
|
),
|
|
|
|
const ImmichLoadingOverlay(),
|
2022-06-11 14:12:06 -07:00
|
|
|
const VersionAnnouncementOverlay(),
|
2022-04-23 19:08:45 -07:00
|
|
|
],
|
2022-02-03 09:06:44 -07:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|