Include the mission name in the "Mission sent"/"Mission upload failed" System Messages (was just the waypoint count before). Add MissionMeta.switchSeq, bumped only by an actual mission switch (startNew/startNewFromPlace/loadMission) - not by the id a brand-new mission gets from its first autosave, and not by restoreLastSession() on app start. FlyScreen compares it to detect a genuine switch and reacts two ways: logs "Mission changed to ..." and automatically re-uploads the new route to the flight controller, reusing the same send path as the manual send button (same _sending guard, same success/failure snackbar and log entry). Mission-change and drone-profile-change logging intentionally live in FlyScreen's ref.listen callbacks, not in mission_meta_provider.dart / active_drone_profile_provider.dart themselves - those providers have no notion of the app mode (Plan vs Fly, tracked separately by AppModeCubit), and logging there would record a change regardless of mode. Since FlyScreen only exists while Fly mode is active, scoping the listeners there means switching missions or drone profiles from Plan mode produces no System Messages entries, and only a mission switch (not a drone profile switch) triggers the automatic re-upload, matching what was asked for. Also splits systemMessageLogProvider (the plain message list + log(), no telemetry dependency) from the new systemMessageAutoLogProvider (the Connected/lost/battery/failsafe/connection-type auto-detection, which does watch telemetryProvider) - discovered while wiring the mission-change logging that logging a plain message from Plan-mode code was forcing the entire telemetry/transport stack to spin up as a side effect, which broke an unrelated Plan-mode test (UdpTransport threw on a double-disconnect during teardown). Keeping the two concerns apart means calling log() for a one-off message never has that side effect. Verified end to end on the Pixel_10a emulator: switching to an empty mission while in Fly mode correctly showed "No waypoints to send" and logged "Mission changed to ..." automatically, without touching the send button. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
68 lines
2.8 KiB
Dart
68 lines
2.8 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../domain/mission/drone_profile.dart';
|
|
import 'database_provider.dart';
|
|
|
|
/// Haelt das aktuell aktive Drohnenprofil (Doku 3.5/7.3) - bestimmt u.a. den
|
|
/// gueltigen Geschwindigkeits-/Hoehenbereich der Drehraeder sowie die
|
|
/// Flugpfad-Machbarkeitspruefung (Kurvenradius, Steig-/Sinkrate).
|
|
///
|
|
/// T1-Ranger-Konstanten dienen nur als Startwert, bevor initialize() die
|
|
/// Datenbank gelesen hat (verhindert einen Zustand ganz ohne Profil waehrend
|
|
/// des asynchronen Ladens).
|
|
class ActiveDroneProfileNotifier extends Notifier<DroneProfile> {
|
|
@override
|
|
DroneProfile build() => DroneProfile.t1Ranger();
|
|
|
|
/// Stellt sicher, dass mindestens ein Profil in der Datenbank existiert,
|
|
/// und laedt das zuletzt aktive (oder das erste vorhandene) Profil -
|
|
/// analog dem drones/activeDrone-Bootstrap im HTML-Demonstrator.
|
|
Future<void> initialize() async {
|
|
final droneRepo = ref.read(droneProfileRepositoryProvider);
|
|
final settingsRepo = ref.read(appSettingsRepositoryProvider);
|
|
|
|
final seededId = await droneRepo.ensureSeeded();
|
|
final settings = await settingsRepo.load();
|
|
final all = await droneRepo.loadAll();
|
|
|
|
final activeId = settings.activeDroneProfileId ?? seededId;
|
|
final active = all.firstWhere(
|
|
(p) => p.id == activeId,
|
|
orElse: () => all.first,
|
|
);
|
|
state = active;
|
|
if (settings.activeDroneProfileId != active.id) {
|
|
await settingsRepo.setActiveDroneProfileId(active.id);
|
|
}
|
|
}
|
|
|
|
/// Loggt den Wechsel NICHT selbst (Doku: "Wechsel der Mission oder des
|
|
/// Drohnenprofils ... nur im fly modus loggen") - dieser Provider kennt
|
|
/// den App-Modus (AppModeCubit, flutter_bloc) nicht. FlyScreen beobachtet
|
|
/// stattdessen selbst per ref.listen(activeDroneProfileProvider, ...) und
|
|
/// loggt dort, existiert also nur, waehrend der Fly-Modus aktiv ist.
|
|
Future<void> select(DroneProfile profile) async {
|
|
state = profile;
|
|
await ref.read(appSettingsRepositoryProvider).setActiveDroneProfileId(profile.id);
|
|
}
|
|
|
|
/// Nach dem Bearbeiten des aktiven Profils dessen Werte neu einlesen.
|
|
Future<void> reloadIfActive(int id) async {
|
|
if (state.id != id) return;
|
|
final all = await ref.read(droneProfileRepositoryProvider).loadAll();
|
|
final updated = all.where((p) => p.id == id);
|
|
if (updated.isNotEmpty) state = updated.first;
|
|
}
|
|
|
|
/// Nach dem Loeschen des aktiven Profils auf das erste verbleibende
|
|
/// zurueckfallen (analog `if (wasActive) applyDroneProfile(drones[0])`).
|
|
Future<void> fallBackTo(DroneProfile profile) async {
|
|
state = profile;
|
|
await ref.read(appSettingsRepositoryProvider).setActiveDroneProfileId(profile.id);
|
|
}
|
|
}
|
|
|
|
final activeDroneProfileProvider =
|
|
NotifierProvider<ActiveDroneProfileNotifier, DroneProfile>(
|
|
ActiveDroneProfileNotifier.new);
|