Skip to content

Commit

Permalink
0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperZombi committed Mar 31, 2024
1 parent 2082878 commit 52c92be
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Melody Monitor for OBS

<p align="right">
<img align="left" src="https://shields.io/badge/version-v0.1.0-blue">
<img align="left" src="https://shields.io/badge/version-v0.2.0-blue">
<a href="#donate"><img src="https://shields.io/badge/💲-Support_the_Project-2ea043"></a>
</p>

Expand Down
45 changes: 34 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import eel


__version__ = "0.1.0"
__version__ = "0.2.0"
SETTINGS = {}


Expand Down Expand Up @@ -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):
Expand All @@ -138,27 +145,38 @@ 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")):
with open(exe_path("settings.user.json"), 'w', encoding='utf-8') as f:
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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion web/dark.css
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
21 changes: 14 additions & 7 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(){
Expand All @@ -68,3 +70,8 @@ async function load_mods(){
}
})
}

eel.expose(update_url);
function update_url(url) {
window.location.href = url;
}

0 comments on commit 52c92be

Please sign in to comment.