Release v1.0.8: Timer Accuracy Fix

This commit is contained in:
2025-11-23 15:49:08 +01:00
parent c8f5c69102
commit 2f2346b4c8
6 changed files with 106 additions and 113 deletions

View File

@@ -4,7 +4,7 @@ A powerful task management and focus timer plugin for [Obsidian](https://obsidia
![Focus Task Banner](https://img.shields.io/badge/Obsidian-Plugin-7c3aed?style=for-the-badge&logo=obsidian&logoColor=white) ![Focus Task Banner](https://img.shields.io/badge/Obsidian-Plugin-7c3aed?style=for-the-badge&logo=obsidian&logoColor=white)
![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge) ![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge)
![Version](https://img.shields.io/badge/Version-1.0.7-blue?style=for-the-badge) ![Version](https://img.shields.io/badge/Version-1.0.8-blue?style=for-the-badge)
## 🎯 Overview ## 🎯 Overview
@@ -49,7 +49,7 @@ Focus Task brings the power of time-boxed task management directly into your Obs
- **Daily Note Logging**: Automatically log completed tasks to your daily notes with timestamps and performance metrics - **Daily Note Logging**: Automatically log completed tasks to your daily notes with timestamps and performance metrics
### 🎨 User Experience ### 🎨 User Experience
- **Status Bar Timer**: timer that stays visible while you work - **Status Bar Timer**: Timer that stays visible while you work
- **Celebration Messages**: Fun, randomized messages when you complete tasks - **Celebration Messages**: Fun, randomized messages when you complete tasks
- **Sound Notifications**: Audio alerts for timer completion and task completion - **Sound Notifications**: Audio alerts for timer completion and task completion
- **Keyboard Shortcuts**: Quick access to common actions - **Keyboard Shortcuts**: Quick access to common actions

76
main.js
View File

@@ -714,42 +714,10 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
// ============ Timer Management ============ // ============ Timer Management ============
// Sync timer based on timestamp when app returns from background // Sync timer based on timestamp when app returns from background
syncTimerFromTimestamp() { syncTimerFromTimestamp() {
if (!this.isTimerRunning || this.timerStartTimestamp === 0) if (!this.isTimerRunning)
return; 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.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();
this.saveAllData();
} }
startTimer(taskId) { startTimer(taskId) {
const task = this.data.tasks.find((t) => t.id === 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.secondsWorkedOnCurrentTask = task.actualMinutes * 60;
this.timerStartTimestamp = Date.now(); this.timerStartTimestamp = Date.now();
this.pausedTimeRemaining = 0; this.pausedTimeRemaining = 0;
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
let alertShown = false;
this.refreshView(); this.refreshView();
this.updateStatusBar(); this.updateStatusBar();
this.timerInterval = window.setInterval(() => { this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds++; const now = Date.now();
this.secondsWorkedOnCurrentTask++; 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); 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.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();
if (this.currentTimerSeconds === task.estimatedMinutes * 60) { if (!alertShown && this.currentTimerSeconds >= task.estimatedMinutes * 60) {
alertShown = true;
if (this.settings.enableSounds) { if (this.settings.enableSounds) {
this.playAlertSound(); this.playAlertSound();
} }
@@ -795,17 +770,22 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.secondsWorkedOnCurrentTask = Math.floor(task.actualMinutes * 60); this.secondsWorkedOnCurrentTask = Math.floor(task.actualMinutes * 60);
this.timerStartTimestamp = Date.now(); this.timerStartTimestamp = Date.now();
this.pausedTimeRemaining = this.currentTimerSeconds; this.pausedTimeRemaining = this.currentTimerSeconds;
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
this.refreshView(); this.refreshView();
this.updateStatusBar(); this.updateStatusBar();
this.timerInterval = window.setInterval(() => { 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) { if (!this.isBreakMode) {
this.secondsWorkedOnCurrentTask++; this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60); const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
if (task.actualMinutes !== actualMinutes) { if (task.actualMinutes !== actualMinutes) {
task.actualMinutes = actualMinutes; task.actualMinutes = actualMinutes;
} }
this.focusSecondsToday++; const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
this.focusSecondsToday = newFocusSeconds;
} }
this.updateStatusBar(); this.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();
@@ -855,7 +835,10 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.refreshView(); this.refreshView();
if (!this.timerInterval) { if (!this.timerInterval) {
this.timerInterval = window.setInterval(() => { 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.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();
if (this.currentTimerSeconds <= 0) { if (this.currentTimerSeconds <= 0) {
@@ -875,12 +858,17 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.isTimerRunning = true; this.isTimerRunning = true;
this.timerStartTimestamp = Date.now(); this.timerStartTimestamp = Date.now();
const task = this.data.tasks.find((t) => t.id === this.activeTaskId); const task = this.data.tasks.find((t) => t.id === this.activeTaskId);
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
this.timerInterval = window.setInterval(() => { 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) { if (task && !this.isBreakMode) {
this.secondsWorkedOnCurrentTask++; this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60); 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.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();

View File

@@ -1,7 +1,7 @@
{ {
"id": "focus-task", "id": "focus-task",
"name": "Focus Task", "name": "Focus Task",
"version": "1.0.7", "version": "1.0.8",
"minAppVersion": "0.15.0", "minAppVersion": "0.15.0",
"description": "A Blitzit-inspired task management and focus timer plugin. Plan your day, track time with Pomodoro technique, and crush your tasks with satisfying checkoffs.", "description": "A Blitzit-inspired task management and focus timer plugin. Plan your day, track time with Pomodoro technique, and crush your tasks with satisfying checkoffs.",
"author": "Crib", "author": "Crib",

View File

@@ -1,6 +1,6 @@
{ {
"name": "focus-task", "name": "focus-task",
"version": "1.0.7", "version": "1.0.8",
"description": "A Blitzit-inspired task management and focus timer plugin for Obsidian", "description": "A Blitzit-inspired task management and focus timer plugin for Obsidian",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View File

@@ -273,56 +273,14 @@ export default class FocusTaskPlugin extends Plugin {
// Sync timer based on timestamp when app returns from background // Sync timer based on timestamp when app returns from background
syncTimerFromTimestamp() { syncTimerFromTimestamp() {
if (!this.isTimerRunning || this.timerStartTimestamp === 0) return; // Since all intervals now calculate from timestamps directly,
// we just need to trigger an update when coming back to foreground
if (!this.isTimerRunning) return;
const now = Date.now(); // The interval will automatically calculate correct values on next tick
const elapsedMs = now - this.timerStartTimestamp; // Just update the display immediately to show current state
const elapsedSeconds = Math.floor(elapsedMs / 1000);
// If less than 1 second elapsed, no need to sync
if (elapsedSeconds < 1) return;
if (this.isBreakMode) {
// Break mode: countdown timer
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
if (this.currentTimerSeconds <= 0) {
this.handlePomodoroEnd();
}
} else {
// Work mode: check if it's pomodoro (countdown) or stopwatch (count up)
const task = this.data.tasks.find(t => t.id === this.activeTaskId);
if (!task) return;
if (this.pausedTimeRemaining > 0) {
// Pomodoro countdown mode
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
// Update actual minutes worked
this.secondsWorkedOnCurrentTask += elapsedSeconds;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
this.focusSecondsToday += elapsedSeconds;
if (this.currentTimerSeconds <= 0) {
this.handlePomodoroEnd();
}
} else {
// Stopwatch count up mode
this.currentTimerSeconds += elapsedSeconds;
this.secondsWorkedOnCurrentTask += elapsedSeconds;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
this.focusSecondsToday += elapsedSeconds;
}
}
// Reset timestamp to now to prevent double-counting on next sync
this.timerStartTimestamp = now;
this.pausedTimeRemaining = this.currentTimerSeconds;
// Update displays
this.updateStatusBar(); this.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();
this.saveAllData();
} }
startTimer(taskId: string) { startTimer(taskId: string) {
@@ -344,25 +302,39 @@ export default class FocusTaskPlugin extends Plugin {
this.timerStartTimestamp = Date.now(); this.timerStartTimestamp = Date.now();
this.pausedTimeRemaining = 0; // 0 indicates stopwatch mode this.pausedTimeRemaining = 0; // 0 indicates stopwatch mode
// Store initial values
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
let alertShown = false;
// Full refresh to show the active task card // Full refresh to show the active task card
this.refreshView(); this.refreshView();
this.updateStatusBar(); this.updateStatusBar();
// Start interval (count up mode - stopwatch) // Start interval (count up mode - stopwatch)
this.timerInterval = window.setInterval(() => { this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds++; // Calculate elapsed time from timestamp
this.secondsWorkedOnCurrentTask++; const now = Date.now();
const elapsedMs = now - this.timerStartTimestamp;
const elapsedSeconds = Math.floor(elapsedMs / 1000);
// Update timer (count up)
this.currentTimerSeconds = elapsedSeconds;
// Update actual time worked
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60); task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
// Track focus time // Update focus time
this.focusSecondsToday++; const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
this.focusSecondsToday = newFocusSeconds;
// Light update - only timer display, no full refresh // Light update - only timer display, no full refresh
this.updateStatusBar(); this.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();
// Check if over estimate // Check if over estimate (only alert once)
if (this.currentTimerSeconds === task.estimatedMinutes * 60) { if (!alertShown && this.currentTimerSeconds >= task.estimatedMinutes * 60) {
alertShown = true;
if (this.settings.enableSounds) { if (this.settings.enableSounds) {
this.playAlertSound(); this.playAlertSound();
} }
@@ -392,23 +364,34 @@ export default class FocusTaskPlugin extends Plugin {
this.timerStartTimestamp = Date.now(); this.timerStartTimestamp = Date.now();
this.pausedTimeRemaining = this.currentTimerSeconds; this.pausedTimeRemaining = this.currentTimerSeconds;
// Store the initial seconds worked to calculate delta
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
// Full refresh to show the active task card // Full refresh to show the active task card
this.refreshView(); this.refreshView();
this.updateStatusBar(); this.updateStatusBar();
this.timerInterval = window.setInterval(() => { this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds--; // Calculate elapsed time from timestamp (more accurate than counting ticks)
const now = Date.now();
const elapsedMs = now - this.timerStartTimestamp;
const elapsedSeconds = Math.floor(elapsedMs / 1000);
// Update countdown timer
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
if (!this.isBreakMode) { if (!this.isBreakMode) {
this.secondsWorkedOnCurrentTask++; // Update actual time worked based on real elapsed time
// Calculate actual minutes from total seconds worked this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60); const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
// Only update if changed to avoid unnecessary updates
if (task.actualMinutes !== actualMinutes) { if (task.actualMinutes !== actualMinutes) {
task.actualMinutes = actualMinutes; task.actualMinutes = actualMinutes;
} }
// Increment focus time by 1 second
this.focusSecondsToday++; // Update focus time based on elapsed seconds
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
this.focusSecondsToday = newFocusSeconds;
} }
// Light update - only timer display, no full refresh // Light update - only timer display, no full refresh
@@ -483,7 +466,14 @@ export default class FocusTaskPlugin extends Plugin {
if (!this.timerInterval) { if (!this.timerInterval) {
this.timerInterval = window.setInterval(() => { this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds--; // Calculate elapsed time from timestamp
const now = Date.now();
const elapsedMs = now - this.timerStartTimestamp;
const elapsedSeconds = Math.floor(elapsedMs / 1000);
// Update countdown timer
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
// Light update - only timer display // Light update - only timer display
this.updateStatusBar(); this.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();
@@ -510,14 +500,28 @@ export default class FocusTaskPlugin extends Plugin {
this.timerStartTimestamp = Date.now(); this.timerStartTimestamp = Date.now();
const task = this.data.tasks.find(t => t.id === this.activeTaskId); const task = this.data.tasks.find(t => t.id === this.activeTaskId);
// Store initial values for resume
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
this.timerInterval = window.setInterval(() => { this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds--; // Calculate elapsed time from timestamp
const now = Date.now();
const elapsedMs = now - this.timerStartTimestamp;
const elapsedSeconds = Math.floor(elapsedMs / 1000);
// Update timer (countdown from paused position)
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
if (task && !this.isBreakMode) { if (task && !this.isBreakMode) {
this.secondsWorkedOnCurrentTask++; // Update actual time worked
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60); task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
// Track focus time
this.focusSecondsToday++; // Update focus time
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
this.focusSecondsToday = newFocusSeconds;
} }
// Light update - only timer display // Light update - only timer display
this.updateStatusBar(); this.updateStatusBar();
this.updateTimerDisplay(); this.updateTimerDisplay();

View File

@@ -2,5 +2,6 @@
"1.0.4": "0.15.0", "1.0.4": "0.15.0",
"1.0.5": "0.15.0", "1.0.5": "0.15.0",
"1.0.6": "0.15.0", "1.0.6": "0.15.0",
"1.0.7": "0.15.0" "1.0.7": "0.15.0",
"1.0.8": "0.15.0"
} }