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