Skip to content

Commit

Permalink
Tour deletion for new format
Browse files Browse the repository at this point in the history
  • Loading branch information
invpt committed Mar 23, 2024
1 parent 7f5e15f commit c9a204a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 11 additions & 2 deletions lib/src/asset_garbage_collector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class AssetGarbageCollector {
static late final String base;
static bool isRunning = false;

static Future<void> run() async {
/// Runs the garbage collector.
///
/// `ignoredTours` contains the list of tours that will be ignored when computing
/// the set of used assets. Hence, to delete assets which are only required by a
/// given tour or set of tours, include the IDs of those tours in ignoredTours.
static Future<void> run({Set<String>? ignoredTours}) async {
if (isRunning) return;
isRunning = true;

Expand All @@ -29,6 +34,10 @@ class AssetGarbageCollector {
usedAssets.add("tourforge.json");

for (var tourEntry in index.tours) {
if (ignoredTours != null && ignoredTours.contains(tourEntry.id)) {
continue;
}

usedAssets.addAll(tourEntry.allAssets.map((e) => e.id));
}

Expand All @@ -50,7 +59,7 @@ class AssetGarbageCollector {
}
} catch (e, stack) {
if (kDebugMode) {
print("Unexpected rror while garbage collecting: $e");
print("Unexpected error while garbage collecting: $e");
print("Garbage collection error stack trace: $stack");
}
} finally {
Expand Down
4 changes: 1 addition & 3 deletions lib/src/screens/home.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:tourforge_baseline/src/asset_garbage_collector.dart';
import 'package:tourforge_baseline/src/config.dart';
import 'package:tourforge_baseline/src/download_manager.dart';

import '/src/data.dart';
import '/src/screens/tour_details.dart';
Expand Down Expand Up @@ -163,8 +162,7 @@ class _TourListItemState extends State<_TourListItem> {
),
TextButton(
onPressed: () async {
//await DownloadManager.instance.delete(widget.tour.content);
await AssetGarbageCollector.run();
await AssetGarbageCollector.run(ignoredTours: {widget.tour.id});

if (!context.mounted) return;
Navigator.pop(context);
Expand Down

0 comments on commit c9a204a

Please sign in to comment.