diff --git a/config-default.ini b/config-default.ini index 82e4f96..33271ef 100644 --- a/config-default.ini +++ b/config-default.ini @@ -15,6 +15,8 @@ device_id = jf-accounts-0.3.0 [ui] ; 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 host = 0.0.0.0 port = 8056 diff --git a/jellyfin_accounts/__init__.py b/jellyfin_accounts/__init__.py index 1b08add..7956b48 100755 --- a/jellyfin_accounts/__init__.py +++ b/jellyfin_accounts/__init__.py @@ -142,10 +142,7 @@ def load_config(config_path, data_dir): or config["jellyfin"]["public_server"] == "" ): config["jellyfin"]["public_server"] = config["jellyfin"]["server"] - if ( - "bs5" not in config["ui"] - or config["ui"]["bs5"] == "" - ): + if "bs5" not in config["ui"] or config["ui"]["bs5"] == "": config["ui"]["bs5"] = "false" return config @@ -192,11 +189,31 @@ data_store = JSONStorage( if config.getboolean("ui", "bs5"): css_file = "bs5-jf.css" - log.debug('Using Bootstrap 5') + log.debug("Using Bootstrap 5") else: 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"] != "": try: css_path = Path(config["files"]["custom_css"]) diff --git a/jellyfin_accounts/data/config-base.json b/jellyfin_accounts/data/config-base.json index 5661623..3b26383 100644 --- a/jellyfin_accounts/data/config-base.json +++ b/jellyfin_accounts/data/config-base.json @@ -70,6 +70,19 @@ "name": "General", "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": { "name": "Address", "required": true, diff --git a/jellyfin_accounts/data/templates/admin.js b/jellyfin_accounts/data/templates/admin.js index 37bd290..c1ce4df 100644 --- a/jellyfin_accounts/data/templates/admin.js +++ b/jellyfin_accounts/data/templates/admin.js @@ -3,7 +3,7 @@ var bsVersion = {{ bsVersion }}; if (bsVersion == 5) { function createModal(id, find = false) { if (find) { - return bootstrap.Modal.getInstance(document.getElementById(modalId)); + return bootstrap.Modal.getInstance(document.getElementById(id)); }; return new bootstrap.Modal(document.getElementById(id)); }; diff --git a/jellyfin_accounts/web.py b/jellyfin_accounts/web.py index 7d172d4..43b9fcd 100644 --- a/jellyfin_accounts/web.py +++ b/jellyfin_accounts/web.py @@ -11,7 +11,7 @@ def page_not_found(e): return ( render_template( "404.html", - bs5=config.getboolean('ui', 'bs5'), + bs5=config.getboolean("ui", "bs5"), css_file=css_file, contactMessage=config["ui"]["contact_message"], ), @@ -24,7 +24,7 @@ def admin(): # return app.send_static_file('admin.html') return render_template( "admin.html", - bs5=config.getboolean('ui', 'bs5'), + bs5=config.getboolean("ui", "bs5"), css_file=css_file, contactMessage="", email_enabled=config.getboolean("invite_emails", "enabled"), @@ -35,17 +35,16 @@ def admin(): def static_proxy(path): if "html" not in path: if "admin.js" in path: - if config.getboolean('ui', 'bs5'): + if config.getboolean("ui", "bs5"): bsVersion = 5 else: bsVersion = 4 - return render_template("admin.js", - bsVersion=bsVersion) + return render_template("admin.js", bsVersion=bsVersion) return app.send_static_file(path) return ( render_template( "404.html", - bs5=config.getboolean('ui', 'bs5'), + bs5=config.getboolean("ui", "bs5"), css_file=css_file, contactMessage=config["ui"]["contact_message"], ), @@ -63,7 +62,7 @@ def inviteProxy(path): email = "" return render_template( "form.html", - bs5=config.getboolean('ui', 'bs5'), + bs5=config.getboolean("ui", "bs5"), css_file=css_file, contactMessage=config["ui"]["contact_message"], helpMessage=config["ui"]["help_message"], @@ -80,7 +79,7 @@ def inviteProxy(path): log.debug("Attempted use of invalid invite") return render_template( "invalidCode.html", - bs5=config.getboolean('ui', 'bs5'), + bs5=config.getboolean("ui", "bs5"), css_file=css_file, contactMessage=config["ui"]["contact_message"], ) diff --git a/jellyfin_accounts/web_api.py b/jellyfin_accounts/web_api.py index 0713e4d..598e6da 100644 --- a/jellyfin_accounts/web_api.py +++ b/jellyfin_accounts/web_api.py @@ -338,13 +338,9 @@ def modifyConfig(): for section in data: if section in temp_config: for item in data[section]: - if item in temp_config[section]: - temp_config[section][item] = data[section][item] - data[section][item] = True - log.debug(f"{section}/{item} modified") - else: - data[section][item] = False - log.debug(f"{section}/{item} does not exist in config") + temp_config[section][item] = data[section][item] + data[section][item] = True + log.debug(f"{section}/{item} modified") with open(config_path, "w") as config_file: temp_config.write(config_file) config = load_config(config_path, data_dir)