feat(apps): integrate IOSNotificationPayloadBridge for cold start reminder handling
- Create IOSNotificationPayloadBridge instance to check pending payloads on startup - If pending payload exists, enqueue to ReminderQueueManager and show ReminderOverlay - Convert LinksyApp to StatefulWidget to manage ReminderOverlay lifecycle - Remove dead code: unused reminderForegroundPresenter and non-existent bindInAppReminderHandler
This commit is contained in:
+77
-12
@@ -2,10 +2,12 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'core/constants/app_constants.dart';
|
import 'core/constants/app_constants.dart';
|
||||||
import 'core/cache/cache_refresh_coordinator.dart';
|
import 'core/cache/cache_refresh_coordinator.dart';
|
||||||
import 'core/di/injection.dart';
|
import 'core/di/injection.dart';
|
||||||
|
import 'core/notifications/ios_notification_payload_bridge.dart';
|
||||||
import 'core/notifications/local_notification_service.dart';
|
import 'core/notifications/local_notification_service.dart';
|
||||||
import 'core/notifications/reminder_notification_callbacks.dart';
|
import 'core/notifications/reminder_notification_callbacks.dart';
|
||||||
import 'core/router/app_router.dart';
|
import 'core/router/app_router.dart';
|
||||||
@@ -17,7 +19,10 @@ import 'features/auth/presentation/bloc/auth_state.dart';
|
|||||||
import 'features/calendar/data/services/calendar_service.dart';
|
import 'features/calendar/data/services/calendar_service.dart';
|
||||||
import 'features/calendar/data/services/calendar_repository.dart';
|
import 'features/calendar/data/services/calendar_repository.dart';
|
||||||
import 'features/calendar/reminders/reminder_action_executor.dart';
|
import 'features/calendar/reminders/reminder_action_executor.dart';
|
||||||
import 'features/calendar/reminders/ui/reminder_foreground_presenter.dart';
|
import 'features/calendar/reminders/reminder_queue_manager.dart';
|
||||||
|
import 'features/calendar/reminders/models/reminder_action.dart';
|
||||||
|
import 'features/calendar/reminders/models/reminder_payload.dart';
|
||||||
|
import 'features/calendar/reminders/ui/reminder_overlay.dart';
|
||||||
import 'features/calendar/ui/calendar_state_manager.dart';
|
import 'features/calendar/ui/calendar_state_manager.dart';
|
||||||
import 'features/chat/presentation/bloc/chat_bloc.dart';
|
import 'features/chat/presentation/bloc/chat_bloc.dart';
|
||||||
import 'features/settings/data/services/settings_user_cache.dart';
|
import 'features/settings/data/services/settings_user_cache.dart';
|
||||||
@@ -28,10 +33,6 @@ void main() async {
|
|||||||
await configureDependencies();
|
await configureDependencies();
|
||||||
await AppConstants.init();
|
await AppConstants.init();
|
||||||
final rootNavigatorKey = GlobalKey<NavigatorState>();
|
final rootNavigatorKey = GlobalKey<NavigatorState>();
|
||||||
final reminderForegroundPresenter = ReminderForegroundPresenter(
|
|
||||||
navigatorKey: rootNavigatorKey,
|
|
||||||
executor: sl<ReminderActionExecutor>(),
|
|
||||||
);
|
|
||||||
sl<LocalNotificationService>().bindActionHandler(({
|
sl<LocalNotificationService>().bindActionHandler(({
|
||||||
required action,
|
required action,
|
||||||
required payload,
|
required payload,
|
||||||
@@ -41,11 +42,17 @@ void main() async {
|
|||||||
payload: payload,
|
payload: payload,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
sl<LocalNotificationService>().bindInAppReminderHandler(
|
|
||||||
reminderForegroundPresenter.present,
|
|
||||||
);
|
|
||||||
await sl<LocalNotificationService>().initialize();
|
await sl<LocalNotificationService>().initialize();
|
||||||
|
|
||||||
|
final prefs = sl<SharedPreferences>();
|
||||||
|
final payloadBridge = IOSNotificationPayloadBridge(prefs);
|
||||||
|
final queueManager = ReminderQueueManager();
|
||||||
|
final pendingPayload = await payloadBridge.getPendingPayload();
|
||||||
|
if (pendingPayload != null) {
|
||||||
|
queueManager.enqueueFromClick(pendingPayload);
|
||||||
|
await payloadBridge.clearPendingPayload();
|
||||||
|
}
|
||||||
|
|
||||||
final authBloc = sl<AuthBloc>();
|
final authBloc = sl<AuthBloc>();
|
||||||
authBloc.add(AuthStarted());
|
authBloc.add(AuthStarted());
|
||||||
|
|
||||||
@@ -77,6 +84,8 @@ void main() async {
|
|||||||
notificationService: sl<LocalNotificationService>(),
|
notificationService: sl<LocalNotificationService>(),
|
||||||
reminderActionExecutor: sl<ReminderActionExecutor>(),
|
reminderActionExecutor: sl<ReminderActionExecutor>(),
|
||||||
),
|
),
|
||||||
|
pendingReminderPayload: pendingPayload,
|
||||||
|
reminderQueueManager: queueManager,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -89,35 +98,91 @@ void main() async {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class LinksyApp extends StatelessWidget {
|
class LinksyApp extends StatefulWidget {
|
||||||
final AuthBloc authBloc;
|
final AuthBloc authBloc;
|
||||||
final GlobalKey<NavigatorState> rootNavigatorKey;
|
final GlobalKey<NavigatorState> rootNavigatorKey;
|
||||||
final AuthSessionBootstrapper sessionBootstrapper;
|
final AuthSessionBootstrapper sessionBootstrapper;
|
||||||
|
final ReminderPayload? pendingReminderPayload;
|
||||||
|
final ReminderQueueManager reminderQueueManager;
|
||||||
|
|
||||||
const LinksyApp({
|
const LinksyApp({
|
||||||
super.key,
|
super.key,
|
||||||
required this.authBloc,
|
required this.authBloc,
|
||||||
required this.rootNavigatorKey,
|
required this.rootNavigatorKey,
|
||||||
required this.sessionBootstrapper,
|
required this.sessionBootstrapper,
|
||||||
|
this.pendingReminderPayload,
|
||||||
|
required this.reminderQueueManager,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<LinksyApp> createState() => _LinksyAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LinksyAppState extends State<LinksyApp> {
|
||||||
|
OverlayEntry? _reminderOverlayEntry;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
_maybeShowReminderOverlay();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _maybeShowReminderOverlay() {
|
||||||
|
if (widget.pendingReminderPayload == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final context = widget.rootNavigatorKey.currentContext;
|
||||||
|
if (context == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_reminderOverlayEntry = OverlayEntry(
|
||||||
|
builder: (context) => ReminderOverlay(
|
||||||
|
queueManager: widget.reminderQueueManager,
|
||||||
|
onComplete: _dismissReminderOverlay,
|
||||||
|
onSnooze: (minutes) {
|
||||||
|
final action = minutes >= 10
|
||||||
|
? ReminderAction.snooze10m
|
||||||
|
: ReminderAction.archive;
|
||||||
|
sl<ReminderActionExecutor>().handleAction(
|
||||||
|
action: action,
|
||||||
|
payload: widget.pendingReminderPayload!,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onArchive: () {
|
||||||
|
sl<ReminderActionExecutor>().handleAction(
|
||||||
|
action: ReminderAction.archive,
|
||||||
|
payload: widget.pendingReminderPayload!,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Overlay.of(context).insert(_reminderOverlayEntry!);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _dismissReminderOverlay() {
|
||||||
|
_reminderOverlayEntry?.remove();
|
||||||
|
_reminderOverlayEntry = null;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider<AuthBloc>.value(value: authBloc),
|
BlocProvider<AuthBloc>.value(value: widget.authBloc),
|
||||||
BlocProvider<ChatBloc>(create: (_) => ChatBloc(apiClient: sl())),
|
BlocProvider<ChatBloc>(create: (_) => ChatBloc(apiClient: sl())),
|
||||||
],
|
],
|
||||||
child: BlocListener<AuthBloc, AuthState>(
|
child: BlocListener<AuthBloc, AuthState>(
|
||||||
listenWhen: (previous, current) => previous != current,
|
listenWhen: (previous, current) => previous != current,
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
unawaited(sessionBootstrapper.syncForAuthState(state));
|
unawaited(widget.sessionBootstrapper.syncForAuthState(state));
|
||||||
},
|
},
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
title: 'Linksy',
|
title: 'Linksy',
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
theme: AppTheme.light,
|
theme: AppTheme.light,
|
||||||
routerConfig: createAppRouter(authBloc),
|
routerConfig: createAppRouter(widget.authBloc),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user