Skip to content

Commit

Permalink
fix: api key when opening web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
elibroftw committed Apr 12, 2024
1 parent 98a42b7 commit 49bbb10
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/music_caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3156,7 +3156,8 @@ def read_main_window():
elif main_event == 'open_github':
open_in_browser('https://github.com/elibroftw/music-caster')
elif main_event == 'web_gui':
open_in_browser(f'http://{get_lan_ip()}:{State.PORT}')
api_key = settings['api_key']
open_in_browser(f'http://{get_lan_ip()}:{State.PORT}?api_key={api_key}')
# toggle settings
elif main_event in TOGGLEABLE_SETTINGS:
update_settings(main_event, main_value)
Expand Down Expand Up @@ -3762,8 +3763,7 @@ def handle_action(action):
s1.settimeout(socket_timeout), s2.settimeout(socket_timeout)
# check if ports are not occupied
if s1.connect_ex(('127.0.0.1', State.PORT)) != 0 and s2.connect_ex(('::1', State.PORT)) != 0:
# if ports are not occupied
with suppress(OSError):
with suppress(OSError, PermissionError):
# try to start server and bind it to PORT
# Linux auto-maps ipv4 to ipv6 however Windows keep them seperate
if platform.system() == 'Windows':
Expand Down Expand Up @@ -3840,6 +3840,13 @@ def handle_action(action):
app_log.info(f'Time to start (excluding imports) is {TIME_TO_START:.2f} seconds')
app_log.info(f'Time to start (including imports) is {TIME_TO_START + TIME_TO_IMPORT:.2f} seconds')
last_position_save = time.monotonic()

# health check
if not IS_FROZEN:
api_key = settings['api_key']
r = requests.get(f'http://127.0.0.1:{State.PORT}/?api_key={api_key}')
assert r.ok

while True:
while not daemon_commands.empty(): handle_action(daemon_commands.get())
if playing_status.playing() and track_length is not None and time.monotonic() > track_end:
Expand Down

0 comments on commit 49bbb10

Please sign in to comment.