From 52c92beaff8dcb615404e919b4d0c53752339ab0 Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sun, 31 Mar 2024 23:35:35 +0300 Subject: [PATCH] 0.2.0 --- README.md | 2 +- main.py | 45 ++++++++++++++++++++++++++++++++++----------- web/dark.css | 2 +- web/main.js | 21 ++++++++++++++------- 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 5aad6aa..fbf6f01 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Melody Monitor for OBS

- +

diff --git a/main.py b/main.py index 538d7fa..30fc24b 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ import eel -__version__ = "0.1.0" +__version__ = "0.2.0" SETTINGS = {} @@ -112,6 +112,13 @@ def get_mods_list(): return [f for f in os.listdir(resource_path(os.path.join("web", "mods")))] return [] +@eel.expose +def get_user_settings(): + if os.path.exists(exe_path("settings.user.json")): + with open(exe_path("settings.user.json"), 'r', encoding='utf-8') as f: + return json.loads(f.read()) + return {} + ##### def resource_path(relative_path): @@ -138,20 +145,18 @@ def load_mods(): if os.path.exists(exe_path("mods")): shutil.copytree(exe_path("mods"), resource_path(os.path.join("web", "mods"))) -def open_browser(_): + +###### +def generate_url(): host = SETTINGS.get('host') if host == "0.0.0.0": host = socket.gethostbyname(socket.gethostname()) + return f"http://{host}:{SETTINGS.get('port')}" - search = [] - if SETTINGS.get('theme') == "dark": - search.append("theme=dark") - - search_str = "" - if len(search) > 0: - search_str = f"?{'&'.join(search)}" - wbr.open(f"http://{host}:{SETTINGS.get('port')}{search_str}") +####### +def open_browser(_): + wbr.open(generate_url()) def open_settings(_): if not os.path.exists(exe_path("settings.user.json")): @@ -159,6 +164,19 @@ def open_settings(_): f.write("{\n\t\n}") os.startfile(exe_path("settings.user.json")) +def open_mods_folder(_): + if not os.path.exists(exe_path("mods")): + os.mkdir(exe_path("mods")) + os.startfile(exe_path("mods")) + +def open_mods_url(_): + wbr.open("https://github.com/SuperZombi/melody-monitor/tree/main/mods") + +def refresh_settings_mods(_): + load_settings() + load_mods() + eel.update_url(generate_url()) + if __name__ == '__main__': load_settings() @@ -169,7 +187,12 @@ def open_settings(_): menu_options = ( ("Open in Browser", None, open_browser), - ("Settings", None, open_settings) + ("Settings", None, ( + ('Open Settings', None, open_settings), + ('Mods Folder', None, open_mods_folder), + ('Download Mods', None, open_mods_url), + ('Refresh', None, refresh_settings_mods) + )) ) systray = SysTrayIcon(resource_path(os.path.join("data", "music.ico")), "Melody Monitor", menu_options, on_quit=lambda _: os._exit(0)) systray.start() diff --git a/web/dark.css b/web/dark.css index bd37d18..049b01b 100644 --- a/web/dark.css +++ b/web/dark.css @@ -1,4 +1,4 @@ -body.dark { +body[theme="dark"] { --background: rgba(20, 20, 20, 0.85); --shadow: 0 0 4px rgba(255, 255, 255, 0.5); --title-text-color: white; diff --git a/web/main.js b/web/main.js index 3e56fae..3ddf88c 100644 --- a/web/main.js +++ b/web/main.js @@ -8,9 +8,11 @@ function checkMarquee(){ } } window.onload=_=>{ - load_params() + load_settings() load_mods() - eel.get_media_info() + setTimeout(_=>{ + eel.get_media_info() + }, 1000) } eel.expose(update_media_info); @@ -50,11 +52,11 @@ function update_media_info(info) { } } -function load_params(){ - const params = new URL(location.href).searchParams; - if (params.get("theme") == "dark"){ - document.body.classList.add("dark") - } +async function load_settings(){ + let settings = await eel.get_user_settings()(); + Object.entries(settings).forEach(([key, value]) => { + document.body.setAttribute(key, value) + }) } async function load_mods(){ @@ -68,3 +70,8 @@ async function load_mods(){ } }) } + +eel.expose(update_url); +function update_url(url) { + window.location.href = url; +}