add blocker presets

This commit is contained in:
timka123 committed 2026-10-19 11:54:15 +03:00
1 parent 2be074f191
commit 772fdbfded
12 files changed
+426 -83

No files matched your search

+40
View File
@@ -261,6 +261,24 @@ class Controller(QObject):
def settings(self) -> dict[str, Any]:
return self._settings
@pyqtProperty(int, notify=settingsChanged)
def activePresetIndex(self) -> int:
"""Which saved preset the live Focus/Short/Long minutes match, or -1.
One source of truth for SettingsPage (the full switcher, with the
numbers editable below it) and TimerPage (a quick switcher next to
the dial) so the two never compute "which preset is this" differently.
"""
pomodoro = self._settings.get("pomodoro", {})
for index, preset in enumerate(pomodoro.get("presets", [])):
if (
preset.get("work_minutes") == pomodoro.get("work_minutes")
and preset.get("short_break_minutes") == pomodoro.get("short_break_minutes")
and preset.get("long_break_minutes") == pomodoro.get("long_break_minutes")
):
return index
return -1
@pyqtProperty(bool, notify=blockerChanged)
def blockerActive(self) -> bool:
return bool(self._policy.get("active"))
@@ -426,6 +444,28 @@ class Controller(QObject):
def patchSettings(self, patch: dict[str, Any]) -> None:
self._send("patch_settings", {"patch": patch})
@pyqtSlot(int)
def applyPreset(self, index: int) -> None:
"""Copy a saved preset's minutes onto the live timer settings.
The backend resizes whatever interval is already running or paused
to match, so this takes effect at once — not just on the next one.
"""
presets = self._settings.get("pomodoro", {}).get("presets", [])
if not (0 <= index < len(presets)):
return
preset = presets[index]
self.patchSettings(
{
"pomodoro": {
"work_minutes": preset["work_minutes"],
"short_break_minutes": preset["short_break_minutes"],
"long_break_minutes": preset["long_break_minutes"],
"cycles_before_long_break": preset["cycles_before_long_break"],
}
}
)
@pyqtSlot(str, "QVariant")
def setConfig(self, key: str, value: Any) -> None:
"""Change a desktop-local setting and apply it immediately."""