diff --git a/AdminInterface/www/mupi.php b/AdminInterface/www/mupi.php index 7b1441fb..2cd90f2c 100644 --- a/AdminInterface/www/mupi.php +++ b/AdminInterface/www/mupi.php @@ -441,6 +441,75 @@ $CHANGE_TXT=$CHANGE_TXT."
  • Press Button delay set to ".$_POST['pressDelay']. " seconds
  • "; $change=2; } + $playtime_changed = false; + if( $_POST['playtime_save'] ) + { + if( !isset($data["playtimeLimit"]) || !is_array($data["playtimeLimit"]) ) + { + $data["playtimeLimit"] = array( + "enabled" => false, + "resetHour" => 0, + "maxOverrunMinutes" => 10, + "limitsMinutes" => array("mon"=>60,"tue"=>60,"wed"=>60,"thu"=>60,"fri"=>60,"sat"=>60,"sun"=>60), + ); + } + if( !isset($data["playtimeLimit"]["limitsMinutes"]) || !is_array($data["playtimeLimit"]["limitsMinutes"]) ) + { + $data["playtimeLimit"]["limitsMinutes"] = array("mon"=>60,"tue"=>60,"wed"=>60,"thu"=>60,"fri"=>60,"sat"=>60,"sun"=>60); + } + $data["playtimeLimit"]["enabled"] = (isset($_POST['playtime_enabled']) && $_POST['playtime_enabled'] === '1'); + $data["playtimeLimit"]["resetHour"] = max(0, min(23, intval($_POST['playtime_resetHour']))); + $data["playtimeLimit"]["maxOverrunMinutes"] = max(0, min(60, intval($_POST['playtime_maxOverrunMinutes']))); + $playtime_days = array('mon','tue','wed','thu','fri','sat','sun'); + foreach( $playtime_days as $d ) + { + $field = 'playtime_limit_' . $d; + $val = isset($_POST[$field]) ? intval($_POST[$field]) : 60; + $data["playtimeLimit"]["limitsMinutes"][$d] = max(0, min(1440, $val)); + } + $playtime_changed = true; + $CHANGE_TXT = $CHANGE_TXT."
  • Playtime limit settings saved (live, no restart needed)
  • "; + $change = 2; + } + if( $_POST['quiethours_save'] ) + { + if( !isset($data["quietHours"]) || !is_array($data["quietHours"]) ) + { + $data["quietHours"] = array( + "enabled" => false, + "maxOverrunMinutes" => 10, + "schedule" => array("mon"=>array(),"tue"=>array(),"wed"=>array(),"thu"=>array(),"fri"=>array(),"sat"=>array(),"sun"=>array()), + ); + } + $data["quietHours"]["enabled"] = (isset($_POST['quiethours_enabled']) && $_POST['quiethours_enabled'] === '1'); + $data["quietHours"]["maxOverrunMinutes"] = max(0, min(60, intval($_POST['quiethours_maxOverrunMinutes']))); + $quiethours_days = array('mon','tue','wed','thu','fri','sat','sun'); + $quiethours_window_count = 0; + foreach( $quiethours_days as $d ) + { + $rawWindows = isset($_POST['quiet_windows'][$d]) && is_array($_POST['quiet_windows'][$d]) ? $_POST['quiet_windows'][$d] : array(); + $cleaned = array(); + foreach( $rawWindows as $w ) + { + if( !is_array($w) ) continue; + $from = isset($w['from']) ? trim($w['from']) : ''; + $to = isset($w['to']) ? trim($w['to']) : ''; + // Skip incomplete rows (so add-row-then-don't-fill doesn't pollute config). + if( $from === '' || $to === '' ) continue; + if( !preg_match('/^([01][0-9]|2[0-3]):[0-5][0-9]$/', $from) ) continue; + if( !preg_match('/^([01][0-9]|2[0-3]):[0-5][0-9]$/', $to) ) continue; + $entry = array('from' => $from, 'to' => $to); + $label = isset($w['label']) ? trim($w['label']) : ''; + if( $label !== '' ) $entry['label'] = $label; + $cleaned[] = $entry; + $quiethours_window_count++; + } + $data["quietHours"]["schedule"][$d] = array_values($cleaned); + } + $playtime_changed = true; + $CHANGE_TXT = $CHANGE_TXT."
  • Quiet hours saved (".$quiethours_window_count." window(s), live, no restart needed)
  • "; + $change = 2; + } if( $data["shim"]["ledPin"]!=$_POST['ledPin'] && $_POST['ledPin']) { $data["shim"]["ledPin"]=$_POST['ledPin']; @@ -569,7 +638,12 @@ exec("sudo mv /tmp/.mupiboxconfig.json /etc/mupibox/mupiboxconfig.json"); exec("sudo /usr/local/bin/mupibox/./setting_update.sh"); } - + // Note: playtime/quiet-hours saves used to trigger `pm2 restart spotify-control` here + // because the player cached mupiboxconfig.json at startup via require(). The player + // now does live-reload via fs.watch, so the restart is no longer needed for those + // sub-blocks — the changes take effect within ~50ms without an audio gap. + // $playtime_changed stays as a flag in case future code wants to react to it. + $CHANGE_TXT=$CHANGE_TXT.""; ?> @@ -695,6 +769,177 @@ +
    + Daily playtime limit + +
    + +
    + Quiet hours + +
    + + +
    System settings