Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshots housekeeping #56

Merged
merged 6 commits into from
Jun 1, 2023

Conversation

Antolius
Copy link
Member

Resolve #55

This pull request can be tested on its own by manually changing gsettings, triggering cleanup (and potentially updating system date to simulate the time passing). Cleanup can be manually triggered with:

systemd-tmpfiles --user --clean

The tmpfiles config which this feature updates can be found at ~/.config/user-tmpfiles.d/io.elementary.settings-daemon.downloads-folder.conf.

var config_path = GLib.Path.build_filename (
GLib.Environment.get_user_config_dir (),
var config_path = Path.build_filename (
Environment.get_user_config_dir (),
"user-tmpfiles.d",
"io.elementary.settings-daemon.downloads-folder.conf"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the same name of the tmpfiles config file. It is technically no longer correct, as it can now contain config for screenshots dir in addition to downloads. My thinking behind this:

  1. The implementation is simpler if we only have one file for all cleanup related config.
  2. If we wanted to change the file name we'd need to make sure to delete the old file when we upgrade the daemon. Without that the old file would drift out of sync with gsettings and keep causing problems. This "swap files on upgrade" logic seemed like an unnecessary complication, so I kept the name the same.

Copy link
Member Author

@Antolius Antolius Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if we ship this only with OS 7 we can get away with renaming the file, as the old one won't exist on a fresh install.

This ship has sailed. 😅


if (clean_screenshots) {
var pictures_dir = Environment.get_user_special_dir (UserDirectory.PICTURES);
var screenshots_dir = Path.build_filename (pictures_dir, _("Screenshots"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This _("Screenshots") here bothers me. The Screenshot app itself uses a translated directory name. That's why I used a translated string here as well. However, that leaves room for missing, or just inconsistent, translations (in either app) which will lead to incorrect cleanup behavior.

I guess this could be avoided if we somehow synced translations, but I'm not sure if that's possible (or how to do it). @danirabbit do you have any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a way to include the gettext domain here and use the translations from screenshot. I think we should actually be using the GNOME Settings daemon gettext domain here maybe? @tintou would probably know what to do about that

Copy link
Member Author

@Antolius Antolius May 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some digging:

  1. I did not find a translation for "Screenshots" in GNOME settings daemon. And if I'm reading its code correctly, I thing GNOME's default screenshot utility saves images straight into ~/Pictures, without a dedicated screenshots sub-directory.
  2. I noticed that we have screenshot saving implemented in 2 places: in Gala and in standalone Screenshot app.

The implementation differs slightly between Gala and Screenshot app: the app allows users to override the directory and will remember the new destination for later. On the other hand Gala implementation always uses the translated ~/Pictures/Screenshots directory.

Since Gala implementation looked more "stable" to me I opted for reusing that translation for this housekeeping feature. This effectively means that we'll "leak" screenshot images taken with the Screenshot app in 2 cases:

  1. If user overrides the default directory.
  2. If Screenshot app's translation differs from Gala's.

The 2nd one could be resolved by updating the Screenshot app to reuse Gala translations similar to how it's done here. The 1st case, on the other hand, would be tricky to support. For example user might want to save screenshots into their home directory. It would be wrong to clean up all images from their home dir because of this.

What do you think? Is this implementation good enough?

@danirabbit
Copy link
Member

@Antolius can you revert changes to translation files here please? Translation files are automatically kept up to date by CI

Remove unnecessary GLib prefixes in Housekeeping.vala
in accordance with elementary code style guide.
Extend gschema schema with flag for screenshot cleanup. When
enabled, include the ~/Pictures/Screenshots directory in tmpfiles
configuration file. Refactor code of Housekeeping class to make
it easier to add more cleanup options in the future.
Using gala's gettext domain to get the accurate
name of Screenshots directory.
@Antolius
Copy link
Member Author

Antolius commented May 7, 2023

@Antolius can you revert changes to translation files here please? Translation files are automatically kept up to date by CI

I removed that commit.

@Antolius Antolius requested a review from danirabbit May 20, 2023 21:56
Copy link
Member

@lenemter lenemter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and contents of created config files look good (screenshots folder is translated as well). Good job 🎉

@danirabbit danirabbit merged commit b7799a1 into elementary:master Jun 1, 2023
@Antolius Antolius deleted the screenshots-housekeeping branch June 2, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add screenshots to housekeeping
3 participants