Skip to content

Commit

Permalink
HouseKeeping: add temp and trash options (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Apr 2, 2024
1 parent 7c964b1 commit 755d0f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions data/io.elementary.settings-daemon.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
<summary>Whether the Screenshots folder should be automatically cleaned up.</summary>
<description></description>
</key>
<key type="b" name="cleanup-temp-folder">
<default>false</default>
<summary>Whether the Temp folder should be automatically cleaned up.</summary>
<description></description>
</key>
<key type="b" name="cleanup-trash-folder">
<default>false</default>
<summary>Whether the Trash folder should be automatically cleaned up.</summary>
<description></description>
</key>
<key type="i" name="old-files-age">
<default>30</default>
<summary>How many days to keep an old file before it is cleaned up.</summary>
Expand Down
24 changes: 23 additions & 1 deletion src/Backends/Housekeeping.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public class SettingsDaemon.Backends.Housekeeping : Object {
write_systemd_tmpfiles_config.begin ();
});

if (housekeeping_settings.get_boolean ("cleanup-downloads-folder")) {
if (
housekeeping_settings.get_boolean ("cleanup-downloads-folder") ||
housekeeping_settings.get_boolean ("cleanup-screenshots-folder") ||
housekeeping_settings.get_boolean ("cleanup-temp-folder") ||
housekeeping_settings.get_boolean ("cleanup-trash-folder")
) {
enable_systemd_tmpfiles.begin ();
}

Expand Down Expand Up @@ -130,6 +135,8 @@ public class SettingsDaemon.Backends.Housekeeping : Object {
private class CleanupConfig : Object {
public bool clean_downloads { private get; public construct; }
public bool clean_screenshots { private get; public construct; }
public bool clean_temp { private get; public construct; }
public bool clean_trash { private get; public construct; }
public int clean_after_days { private get; public construct; }

public bool is_disabled { get {
Expand All @@ -141,6 +148,8 @@ public class SettingsDaemon.Backends.Housekeeping : Object {
clean_downloads: settings.get_boolean ("cleanup-downloads-folder")
&& downloads_are_not_home (),
clean_screenshots: settings.get_boolean ("cleanup-screenshots-folder"),
clean_temp: settings.get_boolean ("cleanup-temp-folder"),
clean_trash: settings.get_boolean ("cleanup-trash-folder"),
clean_after_days: settings.get_int ("old-files-age")
);
}
Expand Down Expand Up @@ -171,6 +180,19 @@ public class SettingsDaemon.Backends.Housekeeping : Object {
lines += template.printf (screenshots_dir, clean_after_days);
}

if (clean_temp) {
var temp_dir = Environment.get_tmp_dir ();
lines += template.printf (temp_dir, clean_after_days);
}

if (clean_trash) {
var user_data_dir = Environment.get_user_data_dir ();
var trash_files_dir = Path.build_filename (user_data_dir, "Trash", "files");
var trash_info_dir = Path.build_filename (user_data_dir, "Trash", "info");
lines += template.printf (trash_files_dir, clean_after_days);
lines += template.printf (trash_info_dir, clean_after_days);
}

return string.joinv ("\n", lines).data;
}
}
Expand Down

0 comments on commit 755d0f3

Please sign in to comment.