diff --git a/lib/main.dart b/lib/main.dart index 296710c7..08324fae 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,6 +16,7 @@ import '/ui/screens/settings_screen_controller.dart'; import '/ui/utils/theme_controller.dart'; import 'ui/screens/home_screen_controller.dart'; import 'ui/utils/home_library_controller.dart'; +import 'utils/house_keeping.dart'; import 'utils/update_check_flag_file.dart'; Future main() async { @@ -23,6 +24,7 @@ Future main() async { await initHive(); _setAppInitPrefs(); startApplicationServices(); + startHouseKeeping(); Get.put(await initAudioService(), permanent: true); SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); diff --git a/lib/utils/house_keeping.dart b/lib/utils/house_keeping.dart new file mode 100644 index 00000000..7d0a54df --- /dev/null +++ b/lib/utils/house_keeping.dart @@ -0,0 +1,24 @@ +import 'package:hive/hive.dart'; + +import '../services/utils.dart'; + +void startHouseKeeping() { + removeExpiredSongsUrlFromDb(); +} + +Future removeExpiredSongsUrlFromDb() async { + try { + final songsUrlCacheBox = Hive.box("SongsUrlCache"); + final songsUrlCacheKeysList = + songsUrlCacheBox.keys.whereType().toList(); + for (var i = 0; i < songsUrlCacheKeysList.length; i++) { + final songUrlKey = songsUrlCacheKeysList[i]; + final songUrl = songsUrlCacheBox.get(songUrlKey); + if (songUrl == null || + (songUrl != null && isExpired(url: songUrl[0] as String))) { + await songsUrlCacheBox.delete(songUrlKey); + } + } + // ignore: empty_catches + } catch (e) {} +}