Browse Source

Invalid theme in config fallbacks to default theme

sisyphus
JezerM 4 years ago
parent
commit
adeb249953
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 3
      web-greeter/globals.py
  2. 43
      web-greeter/utils/theme.py

3
web-greeter/globals.py

@ -59,6 +59,8 @@ from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtGui import QColor
import subprocess
from utils import theme
# Typing Helpers
BridgeObj = Type[BridgeObject]
@ -173,6 +175,7 @@ class WebGreeter(App):
def load_theme(self):
self.logger.debug('Loading theme...')
theme.checkTheme(self)
theme_url = '/{0}/{1}/index.html'.format(self.config.themes_dir, self.config.greeter.theme)
self._web_container.load(theme_url)

43
web-greeter/utils/theme.py

@ -33,6 +33,49 @@ import os
# This Application
from .pkg_json import PackageJSON
from logging import (
getLogger,
DEBUG,
Formatter,
StreamHandler,
)
log_format = ''.join([
'%(asctime)s [ %(levelname)s ] %(filename)s %(',
'lineno)d: %(message)s'
])
formatter = Formatter(fmt=log_format, datefmt="%Y-%m-%d %H:%M:%S")
logger = getLogger("theme")
logger.propagate = False
stream_handler = StreamHandler()
stream_handler.setLevel(DEBUG)
stream_handler.setFormatter(formatter)
logger.setLevel(DEBUG)
logger.addHandler(stream_handler)
def checkTheme(self):
themes = listThemes(self)
config_theme = self.config.greeter.theme
default = "gruvbox"
if self.config.greeter.theme in themes:
pass
else:
logger.error("Config theme not valid: \"{0}\". Going with \"{1}\" theme".format(config_theme, default))
self.config.greeter.theme = default
def listThemes(self):
themes_dir = self.config.themes_dir
themes_dir = themes_dir if os.path.exists(themes_dir) else "/usr/share/web-greeter/themes"
filenames = os.listdir(themes_dir)
dirlist = []
for file in filenames:
if os.path.isdir(os.path.join(themes_dir, file)):
dirlist.append(file)
return dirlist
class Theme:
"""

Loading…
Cancel
Save