-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Expand file tree
/
Copy pathinjection_container.dart
More file actions
98 lines (86 loc) · 3.54 KB
/
Copy pathinjection_container.dart
File metadata and controls
98 lines (86 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import 'package:get_it/get_it.dart';
import 'package:lantern/core/services/app_purchase.dart';
import 'package:lantern/core/services/local_storage_service.dart';
import 'package:lantern/core/services/notification_service.dart';
import 'package:lantern/core/services/stripe_service.dart';
import 'package:lantern/core/updater/updater.dart';
import 'package:lantern/core/utils/deeplink_utils.dart';
import 'package:lantern/core/utils/platform_utils.dart' show PlatformUtils;
import 'package:lantern/core/utils/store_utils.dart';
import 'package:lantern/features/home/provider/app_setting_notifier.dart';
import 'package:lantern/lantern/lantern_ffi_service.dart';
import 'package:lantern/lantern/lantern_platform_service.dart';
import 'package:lantern/lantern/lantern_service.dart';
import '../router/router.dart';
import 'logger_service.dart';
final GetIt sl = GetIt.instance;
Future<void> injectServices() async {
appLogger.debug('Initializing storage services...');
final storage = LocalStorageService();
final storeUtils = StoreUtils();
try {
await Future.wait([storage.init(), storeUtils.init()]);
appLogger.debug('Storage services initialized');
sl.registerSingleton<LocalStorageService>(storage);
sl.registerSingleton<StoreUtils>(storeUtils);
} catch (e, st) {
appLogger.error('Storage init failed', e, st);
rethrow;
}
// Detect when the data directory was deleted but SharedPreferences
// (e.g. NSUserDefaults on macOS) survived. Must run before runApp()
// so that AppSettingNotifier.build() reads the correct defaults.
await AppSettingNotifier.resetIfFreshInstall(storage);
sl.registerLazySingleton<Updater>(() => Updater());
sl.registerLazySingleton<AppRouter>(() => AppRouter());
sl.registerLazySingleton<DeepLinkCallbackManager>(
() => DeepLinkCallbackManager(),
);
sl.registerSingleton<LanternPlatformService>(LanternPlatformService());
appLogger.debug('Registering AppPurchase...');
final appPurchase = AppPurchase();
sl.registerSingleton<AppPurchase>(appPurchase);
if (PlatformUtils.isIOS) {
// StoreKit can deliver pending transaction updates at launch; init()
// only subscribes to the stream and does not fetch product details.
appPurchase.init();
}
appLogger.debug('AppPurchase registered');
sl.registerSingleton<LanternFFIService>(
PlatformUtils.isFFISupported
? LanternFFIService()
: MockLanternFFIService(),
);
sl.registerSingletonAsync<LanternService>(() async {
final service = LanternService(
ffiService: sl<LanternFFIService>(),
platformService: sl<LanternPlatformService>(),
appPurchase: sl<AppPurchase>(),
);
try {
await service.init();
appLogger.debug('LanternService initialized');
} catch (e, st) {
appLogger.error('LanternService init failed', e, st);
}
return service;
});
if (PlatformUtils.isAndroid) {
// The publishable key arrives with the plans response (synced by the
// listenSelf listener in PlansNotifier.build), so no upfront
// initialization.
sl.registerSingleton<StripeService>(StripeService());
appLogger.debug('StripeService registered');
}
appLogger.debug('Initializing notification service...');
final notificationService = NotificationService();
try {
await notificationService.init();
} catch (e, st) {
appLogger.error('Notification init failed', e, st);
}
sl.registerSingleton<NotificationService>(notificationService);
appLogger.debug('NotificationService initialized');
await sl.allReady();
appLogger.info('All services injected ✅');
}