v2.42.1 — HIGH: Timer-Periodic-Leak behoben
- MeloApp von StatelessWidget zu StatefulWidget konvertiert - _autoScanTimer als globale Variable gespeichert - Timer wird in _MeloAppState.dispose() gecancelt
This commit is contained in:
+19
-4
@@ -21,6 +21,9 @@ import 'screens/login_screen.dart';
|
|||||||
final FlutterLocalNotificationsPlugin notificationsPlugin =
|
final FlutterLocalNotificationsPlugin notificationsPlugin =
|
||||||
FlutterLocalNotificationsPlugin();
|
FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
|
/// Globaler Timer für periodischen Auto-Scan (wird in MeloAppState.dispose gecancelt)
|
||||||
|
Timer? _autoScanTimer;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
@@ -96,7 +99,7 @@ void main() async {
|
|||||||
runApp(const MeloApp());
|
runApp(const MeloApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Führt Musik-Scan beim Start aus + Timer.periodic alle 3 Stunden (Issue #6)
|
/// Führt Musik-Scan beim Start aus + startet Timer.periodic alle 3 Stunden (Issue #6)
|
||||||
void _starteAutoScan() {
|
void _starteAutoScan() {
|
||||||
// Sofort beim Start scannen (asynchron, blockiert nicht)
|
// Sofort beim Start scannen (asynchron, blockiert nicht)
|
||||||
MusikScanner().scanneMusikOrdner().then((songs) {
|
MusikScanner().scanneMusikOrdner().then((songs) {
|
||||||
@@ -105,8 +108,8 @@ void _starteAutoScan() {
|
|||||||
MeloLogger().fehler('auto_scan_start', e);
|
MeloLogger().fehler('auto_scan_start', e);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Periodischer Scan alle 3 Stunden
|
// Periodischer Scan alle 3 Stunden – Timer wird in MeloAppState.dispose() gecancelt
|
||||||
Timer.periodic(const Duration(hours: 3), (_) {
|
_autoScanTimer = Timer.periodic(const Duration(hours: 3), (_) {
|
||||||
MusikScanner().scanneMusikOrdner().then((songs) {
|
MusikScanner().scanneMusikOrdner().then((songs) {
|
||||||
MeloLogger().zustand('auto_scan_periodisch', {'gefunden': songs.length});
|
MeloLogger().zustand('auto_scan_periodisch', {'gefunden': songs.length});
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
@@ -172,9 +175,14 @@ Future<bool> _onServiceStart(ServiceInstance service) async {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MeloApp extends StatelessWidget {
|
class MeloApp extends StatefulWidget {
|
||||||
const MeloApp({super.key});
|
const MeloApp({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MeloApp> createState() => _MeloAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MeloAppState extends State<MeloApp> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final auth = AuthService();
|
final auth = AuthService();
|
||||||
@@ -188,4 +196,11 @@ class MeloApp extends StatelessWidget {
|
|||||||
: const LoginScreen(),
|
: const LoginScreen(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_autoScanTimer?.cancel();
|
||||||
|
_autoScanTimer = null;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user