2022-08-09 04:43:48 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-07-07 18:40:54 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-08 00:43:09 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-02-03 16:06:44 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-02-06 06:07:56 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2022-08-08 00:43:09 +00:00
|
|
|
import 'package:flutter_displaymode/flutter_displaymode.dart';
|
2022-02-03 16:06:44 +00:00
|
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-05-06 12:22:23 +00:00
|
|
|
import 'package:immich_mobile/modules/backup/models/hive_backup_albums.model.dart';
|
2022-06-23 04:14:14 +00:00
|
|
|
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
|
2022-04-25 02:33:10 +00:00
|
|
|
import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart';
|
2022-06-11 21:12:06 +00:00
|
|
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
2022-02-03 16:06:44 +00:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2022-03-16 15:19:31 +00:00
|
|
|
import 'package:immich_mobile/routing/tab_navigation_observer.dart';
|
2022-02-03 16:06:44 +00:00
|
|
|
import 'package:immich_mobile/shared/providers/app_state.provider.dart';
|
2022-06-23 04:14:14 +00:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2022-06-11 21:12:06 +00:00
|
|
|
import 'package:immich_mobile/shared/providers/release_info.provider.dart';
|
2022-03-22 06:22:04 +00:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2022-02-14 16:40:41 +00:00
|
|
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
2022-04-24 02:08:45 +00:00
|
|
|
import 'package:immich_mobile/shared/views/immich_loading_overlay.dart';
|
2022-06-11 21:12:06 +00:00
|
|
|
import 'package:immich_mobile/shared/views/version_announcement_overlay.dart';
|
2022-08-15 23:53:30 +00:00
|
|
|
import 'package:immich_mobile/utils/immich_app_theme.dart';
|
2022-02-03 16:06:44 +00:00
|
|
|
import 'constants/hive_box.dart';
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
await Hive.initFlutter();
|
2022-05-06 12:22:23 +00:00
|
|
|
|
2022-04-25 02:33:10 +00:00
|
|
|
Hive.registerAdapter(HiveSavedLoginInfoAdapter());
|
2022-05-06 12:22:23 +00:00
|
|
|
Hive.registerAdapter(HiveBackupAlbumsAdapter());
|
|
|
|
|
2022-02-03 16:06:44 +00:00
|
|
|
await Hive.openBox(userInfoBox);
|
2022-04-25 02:33:10 +00:00
|
|
|
await Hive.openBox<HiveSavedLoginInfo>(hiveLoginInfoBox);
|
2022-05-06 12:22:23 +00:00
|
|
|
await Hive.openBox<HiveBackupAlbums>(hiveBackupInfoBox);
|
2022-06-11 21:12:06 +00:00
|
|
|
await Hive.openBox(hiveGithubReleaseInfoBox);
|
2022-08-13 20:51:09 +00:00
|
|
|
await Hive.openBox(userSettingInfoBox);
|
2022-02-03 16:06:44 +00:00
|
|
|
|
2022-02-06 06:07:56 +00:00
|
|
|
SystemChrome.setSystemUIOverlayStyle(
|
|
|
|
const SystemUiOverlayStyle(
|
|
|
|
statusBarIconBrightness: Brightness.light,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2022-07-07 18:40:54 +00:00
|
|
|
await EasyLocalization.ensureInitialized();
|
|
|
|
|
|
|
|
var locales = const [
|
|
|
|
// Default locale
|
|
|
|
Locale('en', 'US'),
|
|
|
|
// Additional locales
|
2022-07-14 15:20:23 +00:00
|
|
|
Locale('da', 'DK'),
|
2022-07-13 16:35:02 +00:00
|
|
|
Locale('de', 'DE'),
|
2022-07-14 15:20:23 +00:00
|
|
|
Locale('es', 'ES'),
|
2022-08-15 23:53:30 +00:00
|
|
|
Locale('fi', 'FI'),
|
2022-07-14 15:20:23 +00:00
|
|
|
Locale('fr', 'FR'),
|
|
|
|
Locale('it', 'IT'),
|
2022-08-15 23:53:30 +00:00
|
|
|
Locale('ja', 'JP'),
|
|
|
|
Locale('pl', 'PL')
|
2022-07-07 18:40:54 +00:00
|
|
|
];
|
|
|
|
|
2022-08-09 04:43:48 +00:00
|
|
|
if (kReleaseMode && Platform.isAndroid) {
|
|
|
|
try {
|
|
|
|
await FlutterDisplayMode.setHighRefreshRate();
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint("Error setting high refresh rate: $e");
|
|
|
|
}
|
2022-08-08 00:43:09 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 12:23:48 +00:00
|
|
|
runApp(
|
|
|
|
EasyLocalization(
|
2022-07-07 18:40:54 +00:00
|
|
|
supportedLocales: locales,
|
|
|
|
path: 'assets/i18n',
|
|
|
|
useFallbackTranslations: true,
|
|
|
|
fallbackLocale: locales.first,
|
2022-07-13 12:23:48 +00:00
|
|
|
child: const ProviderScope(child: ImmichApp()),
|
|
|
|
),
|
|
|
|
);
|
2022-02-03 16:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ImmichApp extends ConsumerStatefulWidget {
|
2022-06-23 04:14:14 +00:00
|
|
|
const ImmichApp({super.key});
|
2022-02-03 16:06:44 +00:00
|
|
|
|
|
|
|
@override
|
2022-06-22 05:23:35 +00:00
|
|
|
ImmichAppState createState() => ImmichAppState();
|
2022-02-03 16:06:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 05:23:35 +00:00
|
|
|
class ImmichAppState extends ConsumerState<ImmichApp>
|
|
|
|
with WidgetsBindingObserver {
|
2022-02-03 16:06:44 +00:00
|
|
|
@override
|
|
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
|
switch (state) {
|
|
|
|
case AppLifecycleState.resumed:
|
|
|
|
debugPrint("[APP STATE] resumed");
|
2022-02-14 16:40:41 +00:00
|
|
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.resumed;
|
2022-06-11 21:12:06 +00: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 16:40:41 +00:00
|
|
|
ref.watch(websocketProvider.notifier).connect();
|
2022-06-11 21:12:06 +00:00
|
|
|
|
|
|
|
ref.watch(releaseInfoProvider.notifier).checkGithubReleaseInfo();
|
2022-03-22 06:22:04 +00:00
|
|
|
|
2022-02-03 16:06:44 +00:00
|
|
|
break;
|
2022-03-22 06:22:04 +00:00
|
|
|
|
2022-02-03 16:06:44 +00:00
|
|
|
case AppLifecycleState.inactive:
|
|
|
|
debugPrint("[APP STATE] inactive");
|
2022-02-14 16:40:41 +00:00
|
|
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.inactive;
|
|
|
|
ref.watch(websocketProvider.notifier).disconnect();
|
2022-03-11 17:02:33 +00:00
|
|
|
ref.watch(backupProvider.notifier).cancelBackup();
|
|
|
|
|
2022-02-03 16:06:44 +00:00
|
|
|
break;
|
2022-03-22 06:22:04 +00:00
|
|
|
|
2022-02-03 16:06:44 +00:00
|
|
|
case AppLifecycleState.paused:
|
|
|
|
debugPrint("[APP STATE] paused");
|
2022-02-14 16:40:41 +00:00
|
|
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.paused;
|
2022-02-03 16:06:44 +00:00
|
|
|
break;
|
2022-03-22 06:22:04 +00:00
|
|
|
|
2022-02-03 16:06:44 +00:00
|
|
|
case AppLifecycleState.detached:
|
|
|
|
debugPrint("[APP STATE] detached");
|
2022-02-14 16:40:41 +00:00
|
|
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.detached;
|
2022-02-03 16:06:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> initApp() async {
|
2022-05-29 03:35:45 +00:00
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2022-02-03 16:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
|
|
|
initApp().then((_) => debugPrint("App Init Completed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2022-05-29 03:35:45 +00:00
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
2022-02-03 16:06:44 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-07-13 12:23:48 +00:00
|
|
|
var router = ref.watch(appRouterProvider);
|
2022-06-11 21:12:06 +00:00
|
|
|
ref.watch(releaseInfoProvider.notifier).checkGithubReleaseInfo();
|
|
|
|
|
2022-04-24 02:08:45 +00:00
|
|
|
return MaterialApp(
|
2022-07-07 18:40:54 +00:00
|
|
|
localizationsDelegates: context.localizationDelegates,
|
|
|
|
supportedLocales: context.supportedLocales,
|
|
|
|
locale: context.locale,
|
2022-02-03 16:06:44 +00:00
|
|
|
debugShowCheckedModeBanner: false,
|
2022-04-24 02:08:45 +00:00
|
|
|
home: Stack(
|
|
|
|
children: [
|
|
|
|
MaterialApp.router(
|
|
|
|
title: 'Immich',
|
|
|
|
debugShowCheckedModeBanner: false,
|
2022-08-15 23:53:30 +00:00
|
|
|
themeMode: ref.watch(immichThemeProvider),
|
|
|
|
darkTheme: immichDarkTheme,
|
|
|
|
theme: immichLightTheme,
|
2022-07-13 12:23:48 +00:00
|
|
|
routeInformationParser: router.defaultRouteParser(),
|
|
|
|
routerDelegate: router.delegate(
|
|
|
|
navigatorObservers: () => [TabNavigationObserver(ref: ref)],
|
|
|
|
),
|
2022-04-24 02:08:45 +00:00
|
|
|
),
|
|
|
|
const ImmichLoadingOverlay(),
|
2022-06-11 21:12:06 +00:00
|
|
|
const VersionAnnouncementOverlay(),
|
2022-04-24 02:08:45 +00:00
|
|
|
],
|
2022-02-03 16:06:44 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|