Skip to content

Commit 45448db

Browse files
authored
feat(MediaViewer): clear non-clapper on-disk cache on shutdown (#1091)
1 parent 2050fba commit 45448db

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/Views/MediaViewer.vala

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
448448
last_used_volume = settings.media_viewer_last_used_volume;
449449
#else
450450
last_used_volume = settings.media_viewer_last_used_volume.clamp (0.0, 1.0);
451+
app.shutdown.connect (cache_cleanup);
451452
#endif
452453

453454
if (is_rtl) back_btn.icon_name = "tuba-right-large-symbolic";
@@ -1131,7 +1132,29 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
11311132
} catch (FileError e) {
11321133
warning (@"Error while opening Clapper's cache: $(e.message)");
11331134
}
1134-
return;
1135+
}
1136+
#else
1137+
private void cache_cleanup () {
1138+
string cache_dir = GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S, Tuba.cache_path, "manual", "media");
1139+
try {
1140+
Dir dir = Dir.open (cache_dir, 0);
1141+
string? name = null;
1142+
1143+
while ((name = dir.read_name ()) != null) {
1144+
string path = Path.build_filename (cache_dir, name);
1145+
1146+
File file = File.new_for_path (path);
1147+
file.delete_async.begin (Priority.LOW, null, (obj, res) => {
1148+
try {
1149+
file.delete_async.end (res);
1150+
} catch (Error e) {
1151+
warning (@"Error while deleting Host's cache: $(e.message)");
1152+
}
1153+
});
1154+
}
1155+
} catch (FileError e) {
1156+
warning (@"Error while opening Host's cache: $(e.message)");
1157+
}
11351158
}
11361159
#endif
11371160

0 commit comments

Comments
 (0)