Fixed Focus time not adding time properly
This commit is contained in:
24
src/main.ts
24
src/main.ts
@@ -36,6 +36,9 @@ export default class FocusTaskPlugin extends Plugin {
|
||||
activeTaskId: string | null = null;
|
||||
pomodoroCount: number = 0;
|
||||
|
||||
// Focus time tracking (in seconds for accuracy)
|
||||
private focusSecondsToday: number = 0;
|
||||
|
||||
// Status bar element
|
||||
statusBarEl: HTMLElement | null = null;
|
||||
|
||||
@@ -102,9 +105,13 @@ export default class FocusTaskPlugin extends Plugin {
|
||||
const loaded = await this.loadData();
|
||||
this.data = Object.assign({}, DEFAULT_DATA, loaded?.data || {});
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, loaded?.settings || {});
|
||||
// Initialize seconds from stored minutes
|
||||
this.focusSecondsToday = (this.data.totalFocusMinutesToday || 0) * 60;
|
||||
}
|
||||
|
||||
async saveAllData() {
|
||||
// Sync minutes from seconds before saving
|
||||
this.data.totalFocusMinutesToday = Math.floor(this.focusSecondsToday / 60);
|
||||
await this.saveData({
|
||||
settings: this.settings,
|
||||
data: this.data,
|
||||
@@ -126,6 +133,7 @@ export default class FocusTaskPlugin extends Plugin {
|
||||
// Reset daily stats
|
||||
this.data.completedToday = 0;
|
||||
this.data.totalFocusMinutesToday = 0;
|
||||
this.focusSecondsToday = 0;
|
||||
this.data.lastActiveDate = today;
|
||||
this.saveAllData();
|
||||
}
|
||||
@@ -259,6 +267,9 @@ export default class FocusTaskPlugin extends Plugin {
|
||||
this.currentTimerSeconds++;
|
||||
task.actualMinutes = Math.floor(this.currentTimerSeconds / 60);
|
||||
|
||||
// Track focus time
|
||||
this.focusSecondsToday++;
|
||||
|
||||
// Light update - only timer display, no full refresh
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
@@ -290,12 +301,17 @@ export default class FocusTaskPlugin extends Plugin {
|
||||
this.refreshView();
|
||||
this.updateStatusBar();
|
||||
|
||||
// Track seconds worked for accurate focus time
|
||||
let secondsWorked = 0;
|
||||
|
||||
this.timerInterval = window.setInterval(() => {
|
||||
this.currentTimerSeconds--;
|
||||
|
||||
if (!this.isBreakMode) {
|
||||
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
||||
this.data.totalFocusMinutesToday = Math.floor(this.data.totalFocusMinutesToday + 1/60);
|
||||
secondsWorked++;
|
||||
task.actualMinutes = Math.floor(secondsWorked / 60);
|
||||
// Increment focus time by 1 second
|
||||
this.focusSecondsToday++;
|
||||
}
|
||||
|
||||
// Light update - only timer display, no full refresh
|
||||
@@ -379,6 +395,8 @@ export default class FocusTaskPlugin extends Plugin {
|
||||
this.currentTimerSeconds--;
|
||||
if (task && !this.isBreakMode) {
|
||||
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
||||
// Track focus time
|
||||
this.focusSecondsToday++;
|
||||
}
|
||||
// Light update - only timer display
|
||||
this.updateStatusBar();
|
||||
@@ -588,7 +606,7 @@ export default class FocusTaskPlugin extends Plugin {
|
||||
pendingCount: pending.length,
|
||||
completedToday: this.data.completedToday,
|
||||
totalEstimatedMinutes: totalEstimate,
|
||||
totalFocusMinutesToday: Math.floor(this.data.totalFocusMinutesToday),
|
||||
totalFocusMinutesToday: Math.floor(this.focusSecondsToday / 60),
|
||||
streak: this.data.streak,
|
||||
pomodorosCompleted: this.data.pomodorosCompleted,
|
||||
avgAccuracy: Math.round(avgAccuracy * 100),
|
||||
|
||||
Reference in New Issue
Block a user