fix: harden school imports and add optional feedback diagnostics

This commit is contained in:
Codex
2026-10-15 10:37:32 +08:00
parent 674df1ceb3
commit 7299f4d8b6
25 changed files with 722 additions and 42 deletions
+22
View File
@@ -6,6 +6,7 @@ import '../domain/app_settings.dart';
import '../data/snapshot_store.dart';
import '../data/json_schedule_import.dart';
import '../services/notification_service.dart';
import '../services/diagnostic_log.dart';
import '../services/calendar_service.dart';
import '../domain/schedule_engine.dart';
import '../data/demo_schedule.dart';
@@ -40,6 +41,10 @@ class AppController extends ChangeNotifier {
await operation();
} catch (error) {
lastError = error.toString();
DiagnosticLog.instance.add(
'operation_failed',
fields: {'code': error.runtimeType.toString()},
);
}
notifyListeners();
});
@@ -57,6 +62,10 @@ class AppController extends ChangeNotifier {
await store.save(next);
snapshot = next;
lastError = null;
DiagnosticLog.instance.add(
'snapshot_saved',
fields: {'count': next.courses.length, 'term': next.schoolTerm?.id},
);
}
Future<void> initialize({bool reconcileServices = true}) => _run(() async {
@@ -171,6 +180,8 @@ class AppController extends ChangeNotifier {
schoolTerm: draft.schoolTerm,
clearExams:
draft.schoolTerm?.school != SupportedSchool.uestcUndergraduate &&
snapshot.examSchedule?.school !=
SupportedSchool.uestcUndergraduate &&
_differentTerm(draft.schoolTerm),
settings: _differentTerm(draft.schoolTerm)
? snapshot.settings.copyWith(clearSemester: true)
@@ -359,12 +370,23 @@ class AppController extends ChangeNotifier {
clock(),
);
reminderErrorCode = null;
DiagnosticLog.instance.add(
'reminders_reconciled',
fields: {
'count': occurrences.length,
'status': reminderResult.status.name,
},
);
} catch (error) {
reminderErrorCode = error is ReminderSetupException
? error.code
: error is PlatformException
? error.code
: error.runtimeType.toString();
DiagnosticLog.instance.add(
'reminders_failed',
fields: {'code': error.runtimeType.toString()},
);
reminderResult = ReminderResult(
ReminderStatus.error,
message: error is ReminderSetupException