Skip to content

Commit

Permalink
added housekeeping works
Browse files Browse the repository at this point in the history
  • Loading branch information
anandnet committed Aug 19, 2023
1 parent 9480262 commit fe9294f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ 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<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await initHive();
_setAppInitPrefs();
startApplicationServices();
startHouseKeeping();
Get.put<AudioHandler>(await initAudioService(), permanent: true);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
Expand Down
24 changes: 24 additions & 0 deletions lib/utils/house_keeping.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:hive/hive.dart';

import '../services/utils.dart';

void startHouseKeeping() {
removeExpiredSongsUrlFromDb();
}

Future<void> removeExpiredSongsUrlFromDb() async {
try {
final songsUrlCacheBox = Hive.box("SongsUrlCache");
final songsUrlCacheKeysList =
songsUrlCacheBox.keys.whereType<String>().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) {}
}

0 comments on commit fe9294f

Please sign in to comment.