Skip to content

Commit

Permalink
Fix #168
Browse files Browse the repository at this point in the history
  • Loading branch information
l0drex committed Mar 7, 2023
1 parent 0c8813d commit c414ad0
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/plugins/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
logger = logging.getLogger(__name__)


def get_default_profile_path() -> str:
def get_profile_paths() -> str:
path = str(Path.home()) + '/.mozilla/firefox/'
config_parser = ConfigParser()
config_parser.read(path + '/profiles.ini')
path += config_parser['Profile0']['Path']

return path
for section in config_parser:
if not section.startswith('Profile'):
continue
yield path + config_parser[section]['Path']


class Firefox(ExternalPlugin):
Expand All @@ -33,18 +34,19 @@ def available_themes(self) -> dict:
if not self.available:
return {}

path = get_default_profile_path() + '/extensions.json'
paths = (p + '/extensions.json' for p in get_profile_paths())
themes: dict[str, str] = {}

try:
with open(path, 'r') as file:
for path in paths:
try:
with open(path, 'r') as file:
content = json.load(file)
for addon in content['addons']:
if addon['type'] == 'theme':
themes[addon['id']] = addon['defaultLocale']['name']
except FileNotFoundError as e:
logger.error(f'Error: {e}.')
return {}
except FileNotFoundError as e:
logger.warning(f'Firefox profile has no extensions installed: {path}')
continue

assert themes != {}, 'No themes found!'
return themes
Expand Down

0 comments on commit c414ad0

Please sign in to comment.