Parse firefox profiles.ini files to get paths of profiles. (#664)

# Parse firefox profiles.ini files to get paths of profiles

This parses firefox profiles.ini files to get the paths of the profiles
instead of just treating any subdir of the firefox dir as a profile.

This allows supporting profiles without a dot in their name which the
existing glob didn't match which can happen if they are named manually,
as well as profiles configured to be outside of the firefox directory
that were ignored and profiles that are symlinked (by adding a resolve()
on the path before the is_dir()).

There is also an additional try condition to avoid failing for the
remaining profiles if encountering a profile without the
customChrome.css, as it might be installed on some profiles only.

## Changelog

- Fixed theming Firefox profiles that don't have a dot in their name
- Fixed theming Firefox profiles that are outside of the Firefox dir
- Fixed theming Firefox profiles that are symlinks
- Fixed failing to theme remaining profiles after encountering one on
which the firefox-gnome-theme is not present

Please note that I have only tested on non-flatpak Firefox.

Signed-off-by: 0xMRTT <0xMRTT@proton.me>
Co-authored-by: 0xMRTT <0xMRTT@proton.me>
This commit is contained in:
Jonathan Lestrelin 2022-11-30 06:13:57 +00:00 committed by GitHub
parent a8a76b3b63
commit 976270150d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 7 deletions

View file

@ -1,4 +1,5 @@
from pathlib import Path
from configparser import ConfigParser
from yapsy.IPlugin import IPlugin
@ -114,14 +115,34 @@ class FirefoxGnomeTheme2Plugin(IPlugin):
return False
def apply(self, dark_theme=False):
for path in ["~/.mozilla/firefox", "~/.librewolf",
"~/.var/app/org.mozilla.firefox/.mozilla/firefox",
"~/.var/app/io.gitlab.librewolf-community/.librewolf"]:
for path in [
"~/.mozilla/firefox",
"~/.librewolf",
"~/.var/app/org.mozilla.firefox/.mozilla/firefox",
"~/.var/app/io.gitlab.librewolf-community/.librewolf",
]:
try:
for result in Path(path).expanduser().glob("*.*"):
if Path.is_dir(result):
with open(f"{result}/chrome/firefox-gnome-theme/customChrome.css","w") as f:
f.write(self.template.format(**self.variables))
directory = Path(path).expanduser()
cp = ConfigParser()
cp.read(str(directory / "profiles.ini"))
results = []
for section in cp.sections():
if not section.startswith("Profile"):
continue
if cp[section]["IsRelative"] == 0:
results.append(Path(cp[section]["Path"]))
else:
results.append(directory / Path(cp[section]["Path"]))
for result in results:
try:
if result.resolve().is_dir():
with open(
f"{result}/chrome/firefox-gnome-theme/customChrome.css",
"w",
) as f:
f.write(self.template.format(**self.variables))
except OSError:
pass
except OSError:
pass
except StopIteration:

View file

@ -1085,6 +1085,7 @@ The main features of Gradience include the following:
[
"0xMRTT https://github.com/0xMRTT",
"Apisu https://github.com/aspizu",
"Jonathan Lestrelin https://github.com/jle64",
],
)
about.add_credit_section(