Cleanup, add theme options

Add theme options to settings to choose between light and dark.
This commit is contained in:
Harvey Tindall 2020-07-05 15:09:42 +01:00
parent adef32ef89
commit 4fb99d1724
6 changed files with 49 additions and 22 deletions

View File

@ -15,6 +15,8 @@ device_id = jf-accounts-0.3.0
[ui] [ui]
; settings related to the ui and program functionality. ; settings related to the ui and program functionality.
; choose the look of jellyfin-accounts.
theme = Jellyfin (Dark)
; set 0.0.0.0 to run on localhost ; set 0.0.0.0 to run on localhost
host = 0.0.0.0 host = 0.0.0.0
port = 8056 port = 8056

View File

@ -142,10 +142,7 @@ def load_config(config_path, data_dir):
or config["jellyfin"]["public_server"] == "" or config["jellyfin"]["public_server"] == ""
): ):
config["jellyfin"]["public_server"] = config["jellyfin"]["server"] config["jellyfin"]["public_server"] = config["jellyfin"]["server"]
if ( if "bs5" not in config["ui"] or config["ui"]["bs5"] == "":
"bs5" not in config["ui"]
or config["ui"]["bs5"] == ""
):
config["ui"]["bs5"] = "false" config["ui"]["bs5"] = "false"
return config return config
@ -192,11 +189,31 @@ data_store = JSONStorage(
if config.getboolean("ui", "bs5"): if config.getboolean("ui", "bs5"):
css_file = "bs5-jf.css" css_file = "bs5-jf.css"
log.debug('Using Bootstrap 5') log.debug("Using Bootstrap 5")
else: else:
css_file = "bs4-jf.css" css_file = "bs4-jf.css"
if "custom_css" in config["files"]:
with open(config_base_path, "r") as f:
themes = json.load(f)["ui"]["theme"]
theme_options = themes["options"]
if "theme" not in config["ui"] or config["ui"]["theme"] not in theme_options:
config["ui"]["theme"] = themes["value"]
if config.getboolean("ui", "bs5"):
num = 5
else:
num = 4
current_theme = config["ui"]["theme"]
if "Bootstrap" in current_theme:
css_file = f"bs{num}.css"
elif "Jellyfin" in current_theme:
css_file = f"bs{num}-jf.css"
elif "Custom" in current_theme and "custom_css" in config["files"]:
if config["files"]["custom_css"] != "": if config["files"]["custom_css"] != "":
try: try:
css_path = Path(config["files"]["custom_css"]) css_path = Path(config["files"]["custom_css"])

View File

@ -70,6 +70,19 @@
"name": "General", "name": "General",
"description": "Settings related to the UI and program functionality." "description": "Settings related to the UI and program functionality."
}, },
"theme": {
"name": "Look",
"required": false,
"requires_restart": true,
"type": "select",
"options": [
"Bootstrap (Light)",
"Jellyfin (Dark)",
"Custom CSS"
],
"value": "Jellyfin (Dark)",
"description": "Choose the look of jellyfin-accounts."
},
"host": { "host": {
"name": "Address", "name": "Address",
"required": true, "required": true,

View File

@ -3,7 +3,7 @@ var bsVersion = {{ bsVersion }};
if (bsVersion == 5) { if (bsVersion == 5) {
function createModal(id, find = false) { function createModal(id, find = false) {
if (find) { if (find) {
return bootstrap.Modal.getInstance(document.getElementById(modalId)); return bootstrap.Modal.getInstance(document.getElementById(id));
}; };
return new bootstrap.Modal(document.getElementById(id)); return new bootstrap.Modal(document.getElementById(id));
}; };

View File

@ -11,7 +11,7 @@ def page_not_found(e):
return ( return (
render_template( render_template(
"404.html", "404.html",
bs5=config.getboolean('ui', 'bs5'), bs5=config.getboolean("ui", "bs5"),
css_file=css_file, css_file=css_file,
contactMessage=config["ui"]["contact_message"], contactMessage=config["ui"]["contact_message"],
), ),
@ -24,7 +24,7 @@ def admin():
# return app.send_static_file('admin.html') # return app.send_static_file('admin.html')
return render_template( return render_template(
"admin.html", "admin.html",
bs5=config.getboolean('ui', 'bs5'), bs5=config.getboolean("ui", "bs5"),
css_file=css_file, css_file=css_file,
contactMessage="", contactMessage="",
email_enabled=config.getboolean("invite_emails", "enabled"), email_enabled=config.getboolean("invite_emails", "enabled"),
@ -35,17 +35,16 @@ def admin():
def static_proxy(path): def static_proxy(path):
if "html" not in path: if "html" not in path:
if "admin.js" in path: if "admin.js" in path:
if config.getboolean('ui', 'bs5'): if config.getboolean("ui", "bs5"):
bsVersion = 5 bsVersion = 5
else: else:
bsVersion = 4 bsVersion = 4
return render_template("admin.js", return render_template("admin.js", bsVersion=bsVersion)
bsVersion=bsVersion)
return app.send_static_file(path) return app.send_static_file(path)
return ( return (
render_template( render_template(
"404.html", "404.html",
bs5=config.getboolean('ui', 'bs5'), bs5=config.getboolean("ui", "bs5"),
css_file=css_file, css_file=css_file,
contactMessage=config["ui"]["contact_message"], contactMessage=config["ui"]["contact_message"],
), ),
@ -63,7 +62,7 @@ def inviteProxy(path):
email = "" email = ""
return render_template( return render_template(
"form.html", "form.html",
bs5=config.getboolean('ui', 'bs5'), bs5=config.getboolean("ui", "bs5"),
css_file=css_file, css_file=css_file,
contactMessage=config["ui"]["contact_message"], contactMessage=config["ui"]["contact_message"],
helpMessage=config["ui"]["help_message"], helpMessage=config["ui"]["help_message"],
@ -80,7 +79,7 @@ def inviteProxy(path):
log.debug("Attempted use of invalid invite") log.debug("Attempted use of invalid invite")
return render_template( return render_template(
"invalidCode.html", "invalidCode.html",
bs5=config.getboolean('ui', 'bs5'), bs5=config.getboolean("ui", "bs5"),
css_file=css_file, css_file=css_file,
contactMessage=config["ui"]["contact_message"], contactMessage=config["ui"]["contact_message"],
) )

View File

@ -338,13 +338,9 @@ def modifyConfig():
for section in data: for section in data:
if section in temp_config: if section in temp_config:
for item in data[section]: for item in data[section]:
if item in temp_config[section]: temp_config[section][item] = data[section][item]
temp_config[section][item] = data[section][item] data[section][item] = True
data[section][item] = True log.debug(f"{section}/{item} modified")
log.debug(f"{section}/{item} modified")
else:
data[section][item] = False
log.debug(f"{section}/{item} does not exist in config")
with open(config_path, "w") as config_file: with open(config_path, "w") as config_file:
temp_config.write(config_file) temp_config.write(config_file)
config = load_config(config_path, data_dir) config = load_config(config_path, data_dir)