fixxes soundboard auto-start
This commit is contained in:
+17
-1
@@ -131,6 +131,7 @@ def _auto_random_tick():
|
||||
delay = rand_between(imin, imax) * 60
|
||||
with auto_random_lock:
|
||||
if state.auto_random_active:
|
||||
auto_random_params['next_ts'] = time.time() + delay
|
||||
auto_random_timer = threading.Timer(delay, _auto_random_tick)
|
||||
auto_random_timer.daemon = True
|
||||
auto_random_timer.start()
|
||||
@@ -436,6 +437,7 @@ def api_soundboard_auto_start():
|
||||
auto_random_params['imax'] = imax
|
||||
auto_random_params['dmin'] = dmin
|
||||
auto_random_params['dmax'] = dmax
|
||||
auto_random_params['next_ts'] = time.time() + delay
|
||||
global auto_random_timer
|
||||
auto_random_timer = threading.Timer(delay, _auto_random_tick)
|
||||
auto_random_timer.daemon = True
|
||||
@@ -455,7 +457,20 @@ def api_soundboard_auto_stop():
|
||||
def api_soundboard_status():
|
||||
with auto_random_lock:
|
||||
active = state.auto_random_active
|
||||
return jsonify({"active": active})
|
||||
next_ts = auto_random_params.get('next_ts')
|
||||
imin = auto_random_params.get('imin')
|
||||
imax = auto_random_params.get('imax')
|
||||
dmin = auto_random_params.get('dmin')
|
||||
dmax = auto_random_params.get('dmax')
|
||||
next_seconds = max(0, next_ts - time.time()) if next_ts else None
|
||||
return jsonify({
|
||||
"active": active,
|
||||
"next_seconds": next_seconds,
|
||||
"interval_min": imin,
|
||||
"interval_max": imax,
|
||||
"delay_min": dmin,
|
||||
"delay_max": dmax
|
||||
})
|
||||
|
||||
|
||||
def _stop_auto_random_internal():
|
||||
@@ -467,6 +482,7 @@ def _stop_auto_random_internal():
|
||||
auto_random_timer = None
|
||||
stopped = True
|
||||
state.auto_random_active = False
|
||||
auto_random_params.clear()
|
||||
return stopped
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user