2023-11-28 21:20:00 -07:00
|
|
|
import 'dart:async';
|
2022-08-08 21:43:48 -07:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-04-06 10:51:32 -07:00
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
2022-07-07 11:40:54 -07:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-08-07 17:43:09 -07:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:flutter/material.dart';
|
2023-02-03 09:26:05 -07:00
|
|
|
import 'package:flutter/services.dart';
|
2022-08-07 17:43:09 -07:00
|
|
|
import 'package:flutter_displaymode/flutter_displaymode.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-28 21:20:00 -07:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-11-03 07:04:41 -07:00
|
|
|
import 'package:timezone/data/latest.dart';
|
2022-08-18 07:41:59 -07:00
|
|
|
import 'package:immich_mobile/constants/locales.dart';
|
|
|
|
import 'package:immich_mobile/modules/backup/background_service/background.service.dart';
|
2023-03-18 07:55:11 -07:00
|
|
|
import 'package:immich_mobile/modules/backup/models/backup_album.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/backup/models/duplicated_asset.model.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';
|
2023-09-17 20:57:05 -07:00
|
|
|
import 'package:immich_mobile/shared/cache/widgets_binding.dart';
|
2023-03-03 15:38:30 -07:00
|
|
|
import 'package:immich_mobile/shared/models/album.dart';
|
2023-06-10 11:13:59 -07:00
|
|
|
import 'package:immich_mobile/shared/models/android_device_asset.dart';
|
2023-03-03 15:38:30 -07:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2023-05-24 20:52:43 -07:00
|
|
|
import 'package:immich_mobile/shared/models/etag.dart';
|
2023-03-03 15:38:30 -07:00
|
|
|
import 'package:immich_mobile/shared/models/exif_info.dart';
|
2023-06-10 11:13:59 -07:00
|
|
|
import 'package:immich_mobile/shared/models/ios_device_asset.dart';
|
2023-03-22 18:36:44 -07:00
|
|
|
import 'package:immich_mobile/shared/models/logger_message.model.dart';
|
2023-02-09 10:32:08 -07:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-03-03 15:38:30 -07:00
|
|
|
import 'package:immich_mobile/shared/models/user.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/app_state.provider.dart';
|
2023-02-09 10:32:08 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/db.provider.dart';
|
2022-11-27 13:34:19 -07:00
|
|
|
import 'package:immich_mobile/shared/services/immich_logger.service.dart';
|
2023-08-05 19:40:50 -07:00
|
|
|
import 'package:immich_mobile/shared/services/local_notification.service.dart';
|
2023-09-12 07:51:43 -07:00
|
|
|
import 'package:immich_mobile/utils/http_ssl_cert_override.dart';
|
2022-08-15 16:53:30 -07:00
|
|
|
import 'package:immich_mobile/utils/immich_app_theme.dart';
|
2023-02-09 10:32:08 -07:00
|
|
|
import 'package:immich_mobile/utils/migration.dart';
|
|
|
|
import 'package:isar/isar.dart';
|
2023-02-22 23:36:17 -07:00
|
|
|
import 'package:logging/logging.dart';
|
2023-02-09 10:32:08 -07:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
|
|
|
|
void main() async {
|
2023-09-17 20:57:05 -07:00
|
|
|
ImmichWidgetsBinding();
|
2023-04-06 10:51:32 -07:00
|
|
|
|
2023-02-09 10:32:08 -07:00
|
|
|
final db = await loadDb();
|
2023-03-22 18:36:44 -07:00
|
|
|
await initApp();
|
2023-03-26 19:35:52 -07:00
|
|
|
await migrateDatabaseIfNeeded(db);
|
2023-09-12 07:51:43 -07:00
|
|
|
HttpOverrides.global = HttpSSLCertOverride();
|
2023-11-28 21:20:00 -07:00
|
|
|
|
2023-11-19 09:04:44 -07:00
|
|
|
runApp(
|
|
|
|
ProviderScope(
|
|
|
|
overrides: [dbProvider.overrideWithValue(db)],
|
2023-11-28 21:20:00 -07:00
|
|
|
child: const MainWidget(),
|
2023-11-19 09:04:44 -07:00
|
|
|
),
|
|
|
|
);
|
2023-01-21 20:43:28 -07:00
|
|
|
}
|
2022-05-06 05:22:23 -07:00
|
|
|
|
2023-01-21 20:43:28 -07:00
|
|
|
Future<void> initApp() async {
|
2023-03-22 18:36:44 -07:00
|
|
|
await EasyLocalization.ensureInitialized();
|
2022-02-03 09:06:44 -07:00
|
|
|
|
2022-08-08 21:43:48 -07:00
|
|
|
if (kReleaseMode && Platform.isAndroid) {
|
|
|
|
try {
|
|
|
|
await FlutterDisplayMode.setHighRefreshRate();
|
2023-01-18 08:59:23 -07:00
|
|
|
debugPrint("Enabled high refresh mode");
|
2022-08-08 21:43:48 -07:00
|
|
|
} catch (e) {
|
|
|
|
debugPrint("Error setting high refresh rate: $e");
|
|
|
|
}
|
2022-08-07 17:43:09 -07:00
|
|
|
}
|
|
|
|
|
2022-11-27 13:34:19 -07:00
|
|
|
// Initialize Immich Logger Service
|
2023-03-22 18:36:44 -07:00
|
|
|
ImmichLogger();
|
2023-02-22 23:36:17 -07:00
|
|
|
|
|
|
|
var log = Logger("ImmichErrorLogger");
|
|
|
|
|
|
|
|
FlutterError.onError = (details) {
|
|
|
|
FlutterError.presentError(details);
|
2023-08-27 21:54:04 -07:00
|
|
|
log.severe(
|
|
|
|
'Catch all error: ${details.toString()} - ${details.exception} - ${details.library} - ${details.context} - ${details.stack}',
|
|
|
|
details,
|
|
|
|
details.stack,
|
|
|
|
);
|
2023-02-22 23:36:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
PlatformDispatcher.instance.onError = (error, stack) {
|
2023-08-27 21:54:04 -07:00
|
|
|
log.severe('Catch all error: ${error.toString()} - $error', error, stack);
|
2023-02-22 23:36:17 -07:00
|
|
|
return true;
|
|
|
|
};
|
2023-11-03 07:04:41 -07:00
|
|
|
|
|
|
|
initializeTimeZones();
|
2023-01-21 20:43:28 -07:00
|
|
|
}
|
2022-11-27 13:34:19 -07:00
|
|
|
|
2023-02-09 10:32:08 -07:00
|
|
|
Future<Isar> loadDb() async {
|
|
|
|
final dir = await getApplicationDocumentsDirectory();
|
|
|
|
Isar db = await Isar.open(
|
2023-03-03 15:38:30 -07:00
|
|
|
[
|
|
|
|
StoreValueSchema,
|
|
|
|
ExifInfoSchema,
|
|
|
|
AssetSchema,
|
|
|
|
AlbumSchema,
|
|
|
|
UserSchema,
|
2023-03-18 07:55:11 -07:00
|
|
|
BackupAlbumSchema,
|
|
|
|
DuplicatedAssetSchema,
|
2023-03-22 18:36:44 -07:00
|
|
|
LoggerMessageSchema,
|
2023-05-24 20:52:43 -07:00
|
|
|
ETagSchema,
|
2023-07-14 06:20:04 -07:00
|
|
|
if (Platform.isAndroid) AndroidDeviceAssetSchema,
|
|
|
|
if (Platform.isIOS) IOSDeviceAssetSchema,
|
2023-03-03 15:38:30 -07:00
|
|
|
],
|
2023-02-09 10:32:08 -07:00
|
|
|
directory: dir.path,
|
|
|
|
maxSizeMiB: 256,
|
|
|
|
);
|
|
|
|
Store.init(db);
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
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");
|
2023-08-12 14:02:58 -07:00
|
|
|
ref.read(appStateProvider.notifier).handleAppResume();
|
2022-02-03 09:06:44 -07:00
|
|
|
break;
|
|
|
|
case AppLifecycleState.inactive:
|
|
|
|
debugPrint("[APP STATE] inactive");
|
2023-08-12 14:02:58 -07:00
|
|
|
ref.read(appStateProvider.notifier).handleAppInactivity();
|
2022-02-03 09:06:44 -07:00
|
|
|
break;
|
|
|
|
case AppLifecycleState.paused:
|
|
|
|
debugPrint("[APP STATE] paused");
|
2023-08-12 14:02:58 -07:00
|
|
|
ref.read(appStateProvider.notifier).handleAppPause();
|
2022-02-03 09:06:44 -07:00
|
|
|
break;
|
|
|
|
case AppLifecycleState.detached:
|
|
|
|
debugPrint("[APP STATE] detached");
|
2023-08-12 14:02:58 -07:00
|
|
|
ref.read(appStateProvider.notifier).handleAppDetached();
|
2022-02-03 09:06:44 -07:00
|
|
|
break;
|
2023-08-18 15:52:40 -07:00
|
|
|
case AppLifecycleState.hidden:
|
|
|
|
debugPrint("[APP STATE] hidden");
|
|
|
|
ref.read(appStateProvider.notifier).handleAppHidden();
|
|
|
|
break;
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> initApp() async {
|
2022-05-28 20:35:45 -07:00
|
|
|
WidgetsBinding.instance.addObserver(this);
|
2023-04-06 10:51:32 -07:00
|
|
|
|
|
|
|
// Draw the app from edge to edge
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
|
|
|
|
|
|
|
// Sets the navigation bar color
|
2023-04-16 22:02:07 -07:00
|
|
|
SystemUiOverlayStyle overlayStyle = const SystemUiOverlayStyle(
|
|
|
|
systemNavigationBarColor: Colors.transparent,
|
|
|
|
);
|
2023-04-06 10:51:32 -07:00
|
|
|
if (Platform.isAndroid) {
|
|
|
|
// Android 8 does not support transparent app bars
|
|
|
|
final info = await DeviceInfoPlugin().androidInfo;
|
|
|
|
if (info.version.sdkInt <= 26) {
|
2023-11-28 21:20:00 -07:00
|
|
|
overlayStyle = context.isDarkTheme
|
|
|
|
? SystemUiOverlayStyle.dark
|
|
|
|
: SystemUiOverlayStyle.light;
|
2023-04-16 22:02:07 -07:00
|
|
|
}
|
2023-04-06 10:51:32 -07:00
|
|
|
}
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(overlayStyle);
|
2023-08-05 19:40:50 -07:00
|
|
|
await ref.read(localNotificationService).setup();
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
|
|
|
initApp().then((_) => debugPrint("App Init Completed"));
|
2022-08-18 07:41:59 -07:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
// needs to be delayed so that EasyLocalization is working
|
|
|
|
ref.read(backgroundServiceProvider).resumeServiceIfEnabled();
|
|
|
|
});
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-07-13 05:23:48 -07:00
|
|
|
var router = ref.watch(appRouterProvider);
|
2022-06-11 14:12:06 -07:00
|
|
|
|
2022-04-23 19:08:45 -07:00
|
|
|
return MaterialApp(
|
2022-07-07 11:40:54 -07:00
|
|
|
localizationsDelegates: context.localizationDelegates,
|
|
|
|
supportedLocales: context.supportedLocales,
|
|
|
|
locale: context.locale,
|
2022-02-03 09:06:44 -07:00
|
|
|
debugShowCheckedModeBanner: false,
|
2023-11-28 21:20:00 -07:00
|
|
|
home: MaterialApp.router(
|
|
|
|
title: 'Immich',
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
themeMode: ref.watch(immichThemeProvider),
|
|
|
|
darkTheme: immichDarkTheme,
|
|
|
|
theme: immichLightTheme,
|
|
|
|
routeInformationParser: router.defaultRouteParser(),
|
|
|
|
routerDelegate: router.delegate(
|
|
|
|
navigatorObservers: () => [TabNavigationObserver(ref: ref)],
|
|
|
|
),
|
2022-02-03 09:06:44 -07:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-11-28 21:20:00 -07:00
|
|
|
|
|
|
|
// ignore: prefer-single-widget-per-file
|
|
|
|
class MainWidget extends StatelessWidget {
|
|
|
|
const MainWidget({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return EasyLocalization(
|
|
|
|
supportedLocales: locales,
|
|
|
|
path: translationsPath,
|
|
|
|
useFallbackTranslations: true,
|
|
|
|
fallbackLocale: locales.first,
|
|
|
|
child: const ImmichApp(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|