feat: 重构 Reminder Notification 系统并更新应用包名
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -14,6 +15,11 @@ import '../data/cache/cache_scope.dart';
|
||||
import 'services/app_prewarm_orchestrator.dart';
|
||||
import 'router/app_router.dart';
|
||||
import '../core/theme/app_theme.dart';
|
||||
import '../core/inbox/inbox_sync_store.dart';
|
||||
import '../core/notification/services/reminder_permission_service.dart';
|
||||
import '../core/notification/services/reminder_notification_router.dart';
|
||||
import '../core/notification/models/reminder_alarm.dart';
|
||||
import 'router/app_routes.dart';
|
||||
|
||||
class LinksyApp extends StatefulWidget {
|
||||
const LinksyApp({super.key});
|
||||
@@ -25,12 +31,15 @@ class LinksyApp extends StatefulWidget {
|
||||
class _LinksyAppState extends State<LinksyApp> {
|
||||
late final AuthBloc _authBloc;
|
||||
late final GoRouter _router;
|
||||
StreamSubscription<ReminderNotificationTap>? _reminderTapSubscription;
|
||||
String? _pendingReminderRoute;
|
||||
int _cacheScopeVersion = 0;
|
||||
|
||||
Future<void> _onAuthenticated(String userId) async {
|
||||
_cacheScopeVersion += 1;
|
||||
final scopeKey = 'user:$userId:v$_cacheScopeVersion';
|
||||
CacheScope.configureProvider(() => scopeKey);
|
||||
await sl<InboxSyncStore>().resetForUser(userId);
|
||||
await sl<ChatBloc>().switchUser(userId);
|
||||
await sl<AppPrewarmOrchestrator>().ensureStartedFor(userId);
|
||||
}
|
||||
@@ -39,6 +48,7 @@ class _LinksyAppState extends State<LinksyApp> {
|
||||
_cacheScopeVersion += 1;
|
||||
final scopeKey = 'anonymous:v$_cacheScopeVersion';
|
||||
CacheScope.configureProvider(() => scopeKey);
|
||||
await sl<InboxSyncStore>().resetForUser(null);
|
||||
await sl<ChatBloc>().switchUser(null);
|
||||
sl<AppPrewarmOrchestrator>().reset();
|
||||
}
|
||||
@@ -51,10 +61,30 @@ class _LinksyAppState extends State<LinksyApp> {
|
||||
CacheScope.configureProvider(() => initialScopeKey);
|
||||
_authBloc.add(AuthStarted());
|
||||
_router = createAppRouter(_authBloc);
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
unawaited(_bootstrapReminderNotification());
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _bootstrapReminderNotification() async {
|
||||
await sl<ReminderPermissionService>().initializeAtBoot();
|
||||
final router = sl<ReminderNotificationRouter>();
|
||||
await router.start();
|
||||
_reminderTapSubscription ??= router.taps.listen(_onReminderTap);
|
||||
}
|
||||
|
||||
void _onReminderTap(ReminderNotificationTap tap) {
|
||||
final route = AppRoutes.calendarReminderAlarm(tap.eventId);
|
||||
if (_authBloc.state is AuthAuthenticated) {
|
||||
_router.go(route);
|
||||
return;
|
||||
}
|
||||
_pendingReminderRoute = route;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_reminderTapSubscription?.cancel();
|
||||
_router.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -67,6 +97,11 @@ class _LinksyAppState extends State<LinksyApp> {
|
||||
listener: (context, state) {
|
||||
if (state is AuthAuthenticated) {
|
||||
unawaited(_onAuthenticated(state.user.id));
|
||||
final pendingRoute = _pendingReminderRoute;
|
||||
if (pendingRoute != null) {
|
||||
_pendingReminderRoute = null;
|
||||
_router.go(pendingRoute);
|
||||
}
|
||||
}
|
||||
if (state is AuthUnauthenticated) {
|
||||
unawaited(_onUnauthenticated());
|
||||
|
||||
Reference in New Issue
Block a user