feat: add active time window to countdown rules
UI: Active Window Start/End time inputs on countdown form. Leave blank = runs any time. End before start = crosses midnight. Scheduler: checks current time against window before starting timer; supports cross-midnight windows (e.g. 9:00 AM to 4:00 AM next day). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -195,9 +195,12 @@ function dwmRuleSummary(r) {
|
||||
return `⚡ If ${src} → ${when}, then ${action} (${targets})`;
|
||||
}
|
||||
if (r.type === 'Countdown') {
|
||||
const mins = r.countdownTime ? Math.round(r.countdownTime / 60) : null;
|
||||
const mins = r.countdownTime ? Math.round(r.countdownTime / 60) : null;
|
||||
const cond = r.countdownAction === 'off_to_on' ? 'OFF→ON' : 'ON→OFF';
|
||||
return mins ? `⏱ ${mins} min · ${cond}` : '—';
|
||||
const win = (r.windowStart >= 0 && r.windowEnd >= 0)
|
||||
? ` · ${secsToHHMM(r.windowStart)}–${secsToHHMM(r.windowEnd)}`
|
||||
: (r.windowStart >= 0 ? ` · from ${secsToHHMM(r.windowStart)}` : '');
|
||||
return mins ? `⏱ ${mins} min · ${cond}${win}` : '—';
|
||||
}
|
||||
const days = dayLabel(r.days);
|
||||
const devs = (r.targetDevices ?? []).map((td) => esc(td.name ?? td.host)).join(', ') || 'no targets';
|
||||
@@ -443,7 +446,9 @@ function openDwmEdit(id) {
|
||||
document.getElementById('dwm-end-action').value = String(r.endAction ?? -1);
|
||||
document.getElementById('dwm-countdown-mins').value =
|
||||
r.countdownTime ? String(Math.round(r.countdownTime / 60)) : '';
|
||||
document.getElementById('dwm-countdown-action').value = r.countdownAction ?? 'on_to_off';
|
||||
document.getElementById('dwm-countdown-action').value = r.countdownAction ?? 'on_to_off';
|
||||
document.getElementById('dwm-countdown-window-start').value = r.windowStart >= 0 ? secsToHHMM(r.windowStart) : '';
|
||||
document.getElementById('dwm-countdown-window-end').value = r.windowEnd >= 0 ? secsToHHMM(r.windowEnd) : '';
|
||||
|
||||
_selectedDwmDays = new Set((r.days ?? []).map(Number));
|
||||
|
||||
@@ -476,8 +481,10 @@ function openDwmEdit(id) {
|
||||
document.getElementById('dwm-end-time').value = '';
|
||||
document.getElementById('dwm-start-action').value = '1';
|
||||
document.getElementById('dwm-end-action').value = '-1';
|
||||
document.getElementById('dwm-countdown-mins').value = '';
|
||||
document.getElementById('dwm-countdown-action').value = 'on_to_off';
|
||||
document.getElementById('dwm-countdown-mins').value = '';
|
||||
document.getElementById('dwm-countdown-action').value = 'on_to_off';
|
||||
document.getElementById('dwm-countdown-window-start').value = '';
|
||||
document.getElementById('dwm-countdown-window-end').value = '';
|
||||
document.getElementById('dwm-trigger-src').value = '';
|
||||
document.getElementById('dwm-trigger-event').value = 'any';
|
||||
document.getElementById('dwm-trigger-action').value = 'on';
|
||||
@@ -609,6 +616,10 @@ document.getElementById('dwm-form-save-btn').addEventListener('click', async ()
|
||||
if (!mins || mins < 1) { showModalError('Enter countdown duration in minutes'); return; }
|
||||
rule.countdownTime = mins * 60;
|
||||
rule.countdownAction = document.getElementById('dwm-countdown-action').value;
|
||||
const winStart = hhmmToSecs(document.getElementById('dwm-countdown-window-start').value);
|
||||
const winEnd = hhmmToSecs(document.getElementById('dwm-countdown-window-end').value);
|
||||
rule.windowStart = winStart >= 0 ? winStart : -1;
|
||||
rule.windowEnd = winEnd >= 0 ? winEnd : -1;
|
||||
} else {
|
||||
const startType = document.getElementById('dwm-start-type').value;
|
||||
const startOffset = parseInt(document.getElementById('dwm-start-offset').value ?? '0', 10) || 0;
|
||||
|
||||
Reference in New Issue
Block a user