beeware / toga

A Python native, OS native GUI toolkit.
https://toga.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
4.3k stars 668 forks source link

Local environment configuration is not respected for app file storage #2867

Open rmartin16 opened 5 days ago

rmartin16 commented 5 days ago

Describe the bug

Toga makes assumptions about which file paths to use for toga.Paths; this can conflict with local machine configuration that should affect arbitrary application storage. For instance, on GTK, if I configure my XDG env vars to something other than the default values, then Toga will ignore this.

Steps to reproduce

For the system, configure application storage with values other than the default and run a Toga app that creates filesystem content.

Expected behavior

Toga should respect local machine configuration for application storage. Given this configuration can be complex on any given platform, the platformdirs package provides nice abstractions. In the least, their logic should be used on Desktop, I think. Outside of Linux distros going rogue....this is also probably important for enterprise environments where IT wants apps to work in a certain way.

Screenshots

No response

Environment

Logs

No response

Additional context

I see that https://github.com/beeware/toga/pull/1964 confirms the same default behavior as platformdirs....but it seemed to have been a foregone conclusion that platformdirs would not become a dependency for Toga.

MrStickyPiston commented 5 days ago

This would remove the need to give flatpaks whole file system access, making it a lot more secure.

freakboy3742 commented 5 days ago

FWIW: The primary reason for avoiding a platformdirs dependency was that platformdirs didn't have any support for iOS or Android - and it was problematic to submit patches for those platforms, because iOS and Android weren't officially supported platforms.

Now that isn't the case, adding a platformdirs dependency would make more sense (assuming patches upstream have been submitted and accepted).

However, this bug notwithstanding, we've essentially got an implementation of platformdirs functionality, so I'm not sure we gain much by replacing a (mostly) working implementation with an external dependency.

So - my inclination would be to add the handling necessary to honour XDG variables natively to Toga, and leave it at that.

rmartin16 commented 5 days ago

It may also be worth evaluating the situation on Windows; it can be a bit more complicated than even the XDG environment variables on Linux since the Windows registry is involved as well....and Windows is likely more relevant to enterprise.