Release v1.0.8: Timer Accuracy Fix
This commit is contained in:
76
main.js
76
main.js
@@ -714,42 +714,10 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
||||
// ============ Timer Management ============
|
||||
// Sync timer based on timestamp when app returns from background
|
||||
syncTimerFromTimestamp() {
|
||||
if (!this.isTimerRunning || this.timerStartTimestamp === 0)
|
||||
if (!this.isTimerRunning)
|
||||
return;
|
||||
const now = Date.now();
|
||||
const elapsedMs = now - this.timerStartTimestamp;
|
||||
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||
if (elapsedSeconds < 1)
|
||||
return;
|
||||
if (this.isBreakMode) {
|
||||
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||
if (this.currentTimerSeconds <= 0) {
|
||||
this.handlePomodoroEnd();
|
||||
}
|
||||
} else {
|
||||
const task = this.data.tasks.find((t) => t.id === this.activeTaskId);
|
||||
if (!task)
|
||||
return;
|
||||
if (this.pausedTimeRemaining > 0) {
|
||||
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||
this.secondsWorkedOnCurrentTask += elapsedSeconds;
|
||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||
this.focusSecondsToday += elapsedSeconds;
|
||||
if (this.currentTimerSeconds <= 0) {
|
||||
this.handlePomodoroEnd();
|
||||
}
|
||||
} else {
|
||||
this.currentTimerSeconds += elapsedSeconds;
|
||||
this.secondsWorkedOnCurrentTask += elapsedSeconds;
|
||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||
this.focusSecondsToday += elapsedSeconds;
|
||||
}
|
||||
}
|
||||
this.timerStartTimestamp = now;
|
||||
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
this.saveAllData();
|
||||
}
|
||||
startTimer(taskId) {
|
||||
const task = this.data.tasks.find((t) => t.id === taskId);
|
||||
@@ -764,16 +732,23 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
||||
this.secondsWorkedOnCurrentTask = task.actualMinutes * 60;
|
||||
this.timerStartTimestamp = Date.now();
|
||||
this.pausedTimeRemaining = 0;
|
||||
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||
let alertShown = false;
|
||||
this.refreshView();
|
||||
this.updateStatusBar();
|
||||
this.timerInterval = window.setInterval(() => {
|
||||
this.currentTimerSeconds++;
|
||||
this.secondsWorkedOnCurrentTask++;
|
||||
const now = Date.now();
|
||||
const elapsedMs = now - this.timerStartTimestamp;
|
||||
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||
this.currentTimerSeconds = elapsedSeconds;
|
||||
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||
this.focusSecondsToday++;
|
||||
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||
this.focusSecondsToday = newFocusSeconds;
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
if (this.currentTimerSeconds === task.estimatedMinutes * 60) {
|
||||
if (!alertShown && this.currentTimerSeconds >= task.estimatedMinutes * 60) {
|
||||
alertShown = true;
|
||||
if (this.settings.enableSounds) {
|
||||
this.playAlertSound();
|
||||
}
|
||||
@@ -795,17 +770,22 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
||||
this.secondsWorkedOnCurrentTask = Math.floor(task.actualMinutes * 60);
|
||||
this.timerStartTimestamp = Date.now();
|
||||
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||
this.refreshView();
|
||||
this.updateStatusBar();
|
||||
this.timerInterval = window.setInterval(() => {
|
||||
this.currentTimerSeconds--;
|
||||
const now = Date.now();
|
||||
const elapsedMs = now - this.timerStartTimestamp;
|
||||
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||
if (!this.isBreakMode) {
|
||||
this.secondsWorkedOnCurrentTask++;
|
||||
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||
const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||
if (task.actualMinutes !== actualMinutes) {
|
||||
task.actualMinutes = actualMinutes;
|
||||
}
|
||||
this.focusSecondsToday++;
|
||||
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||
this.focusSecondsToday = newFocusSeconds;
|
||||
}
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
@@ -855,7 +835,10 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
||||
this.refreshView();
|
||||
if (!this.timerInterval) {
|
||||
this.timerInterval = window.setInterval(() => {
|
||||
this.currentTimerSeconds--;
|
||||
const now = Date.now();
|
||||
const elapsedMs = now - this.timerStartTimestamp;
|
||||
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
if (this.currentTimerSeconds <= 0) {
|
||||
@@ -875,12 +858,17 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
||||
this.isTimerRunning = true;
|
||||
this.timerStartTimestamp = Date.now();
|
||||
const task = this.data.tasks.find((t) => t.id === this.activeTaskId);
|
||||
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||
this.timerInterval = window.setInterval(() => {
|
||||
this.currentTimerSeconds--;
|
||||
const now = Date.now();
|
||||
const elapsedMs = now - this.timerStartTimestamp;
|
||||
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||
if (task && !this.isBreakMode) {
|
||||
this.secondsWorkedOnCurrentTask++;
|
||||
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||
this.focusSecondsToday++;
|
||||
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||
this.focusSecondsToday = newFocusSeconds;
|
||||
}
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
|
||||
Reference in New Issue
Block a user