|
@@ -217,6 +217,36 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /// Handle timer completion
|
|
|
+ Future<void> _timerCompleted() async {
|
|
|
+ setState(() {
|
|
|
+ timerState = TimerState.finish;
|
|
|
+ });
|
|
|
+
|
|
|
+ // Play sound and vibrate
|
|
|
+ if (_settings.vibrate) {
|
|
|
+ _audioManager.triggerVibration();
|
|
|
+ }
|
|
|
+ _audioManager.playSound(_settings.sound, _settings.volume, _settings.loop);
|
|
|
+
|
|
|
+ // If loop is enabled, restart the timer
|
|
|
+ if (_settings.loop) {
|
|
|
+ Future.delayed(Duration(seconds: 5), () {
|
|
|
+ _audioManager.stopSound();
|
|
|
+ _audioManager.stopVibration();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 不再检查是否需要整点对齐,直接启动倒计时
|
|
|
+ setState(() {
|
|
|
+ timerState = TimerState.running;
|
|
|
+ _remainingSeconds = _hours * 3600 + _minutes * 60 + _seconds;
|
|
|
+ _totalDurationSeconds = _remainingSeconds;
|
|
|
+ });
|
|
|
+
|
|
|
+ _backgroundTimerService.startTimer(_remainingSeconds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// Start a new timer or resume an existing paused timer
|
|
|
void _startTimer(String status) {
|
|
|
if (status == "resume") {
|
|
@@ -239,7 +269,7 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
_minutes = _minutestmp;
|
|
|
_seconds = _secondstmp;
|
|
|
|
|
|
- // 检查是否需要整点对齐
|
|
|
+ // 检查是否需要整点对齐 - 只有在初始启动时才检查
|
|
|
if (_settings.alignToHour && _settings.loop && totalSeconds >= 600) { // 只有在循环模式、时间至少10分钟时才启用整点对齐
|
|
|
_startTimerWithAlignment(totalSeconds);
|
|
|
} else {
|
|
@@ -256,18 +286,14 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
final totalSeconds = _hours * 3600 + _minutes * 60 + _seconds;
|
|
|
if (totalSeconds <= 0) return;
|
|
|
|
|
|
- // 检查是否需要整点对齐
|
|
|
- if (_settings.alignToHour && _settings.loop && totalSeconds >= 600) { // 只有在循环模式、时间至少10分钟时才启用整点对齐
|
|
|
- _startTimerWithAlignment(totalSeconds);
|
|
|
- } else {
|
|
|
- setState(() {
|
|
|
- timerState = TimerState.running;
|
|
|
- _remainingSeconds = totalSeconds;
|
|
|
- _totalDurationSeconds = totalSeconds;
|
|
|
- });
|
|
|
-
|
|
|
- _backgroundTimerService.startTimer(totalSeconds);
|
|
|
- }
|
|
|
+ // 直接启动倒计时,不再检查是否需要整点对齐
|
|
|
+ setState(() {
|
|
|
+ timerState = TimerState.running;
|
|
|
+ _remainingSeconds = totalSeconds;
|
|
|
+ _totalDurationSeconds = totalSeconds;
|
|
|
+ });
|
|
|
+
|
|
|
+ _backgroundTimerService.startTimer(totalSeconds);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -303,28 +329,6 @@ class _TimerPageState extends State<TimerPage> with WidgetsBindingObserver {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /// Handle timer completion
|
|
|
- Future<void> _timerCompleted() async {
|
|
|
- setState(() {
|
|
|
- timerState = TimerState.finish;
|
|
|
- });
|
|
|
-
|
|
|
- // Play sound and vibrate
|
|
|
- if (_settings.vibrate) {
|
|
|
- _audioManager.triggerVibration();
|
|
|
- }
|
|
|
- _audioManager.playSound(_settings.sound, _settings.volume, _settings.loop);
|
|
|
-
|
|
|
- // If loop is enabled, restart the timer
|
|
|
- if (_settings.loop) {
|
|
|
- Future.delayed(Duration(seconds: 5), () {
|
|
|
- _audioManager.stopSound();
|
|
|
- _audioManager.stopVibration();
|
|
|
- });
|
|
|
- _startTimer("loop");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
String _formatTime(int seconds) {
|
|
|
final hours = seconds ~/ 3600;
|
|
|
final minutes = (seconds % 3600) ~/ 60;
|