fix: Stopwatch mode and daily stats improvements
Bug Fixes: - Removed progress bar from stopwatch mode (only shows in pomodoro/break) - Fixed daily stats not resetting at midnight when app stays open - Fixed focus time tracking to only count completed tasks, not stopped sessions Improvements: - Added daily reset check interval (checks every 60 seconds) - Added daily reset check on app visibility change - Focus time now accurately reflects completed work only - Session time tracking separated from daily focus time Technical: - Added dailyResetCheckInterval for periodic day change detection - Added sessionStartSeconds to track focus time per session - Removed real-time focus time updates from timer intervals - Focus time only added in completeTask() method - Progress bar conditionally rendered based on isStopwatchMode flag
This commit is contained in:
59
main.js
59
main.js
@@ -763,19 +763,21 @@ var ImmerseView = class extends import_obsidian2.ItemView {
|
||||
cls: "immerse-timer-time",
|
||||
text: this.plugin.formatTime(this.plugin.currentTimerSeconds)
|
||||
});
|
||||
const progressWrap = activeCard.createEl("div", { cls: "immerse-progress-wrap" });
|
||||
this.progressBarEl = progressWrap.createEl("div", { cls: "immerse-progress-bar" });
|
||||
let progressPercent = 0;
|
||||
if (this.plugin.isBreakMode) {
|
||||
const breakDuration = this.plugin.pomodoroCount % this.plugin.settings.longBreakInterval === 0 ? this.plugin.settings.longBreakMinutes * 60 : this.plugin.settings.pomodoroBreakMinutes * 60;
|
||||
progressPercent = (breakDuration - this.plugin.currentTimerSeconds) / breakDuration * 100;
|
||||
} else {
|
||||
const workDuration = this.plugin.settings.pomodoroWorkMinutes * 60;
|
||||
progressPercent = (workDuration - this.plugin.currentTimerSeconds) / workDuration * 100;
|
||||
if (!this.plugin.isStopwatchMode) {
|
||||
const progressWrap = activeCard.createEl("div", { cls: "immerse-progress-wrap" });
|
||||
this.progressBarEl = progressWrap.createEl("div", { cls: "immerse-progress-bar" });
|
||||
let progressPercent = 0;
|
||||
if (this.plugin.isBreakMode) {
|
||||
const breakDuration = this.plugin.pomodoroCount % this.plugin.settings.longBreakInterval === 0 ? this.plugin.settings.longBreakMinutes * 60 : this.plugin.settings.pomodoroBreakMinutes * 60;
|
||||
progressPercent = (breakDuration - this.plugin.currentTimerSeconds) / breakDuration * 100;
|
||||
} else {
|
||||
const workDuration = this.plugin.settings.pomodoroWorkMinutes * 60;
|
||||
progressPercent = (workDuration - this.plugin.currentTimerSeconds) / workDuration * 100;
|
||||
}
|
||||
this.progressBarEl.style.width = `${Math.min(Math.max(progressPercent, 0), 100)}%`;
|
||||
if (progressPercent >= 100)
|
||||
this.progressBarEl.addClass("immerse-overtime");
|
||||
}
|
||||
this.progressBarEl.style.width = `${Math.min(Math.max(progressPercent, 0), 100)}%`;
|
||||
if (progressPercent >= 100)
|
||||
this.progressBarEl.addClass("immerse-overtime");
|
||||
if (!this.plugin.isBreakMode) {
|
||||
const timeInfo = activeCard.createEl("div", { cls: "immerse-time-info" });
|
||||
timeInfo.createEl("span", { text: `Est: ${this.plugin.formatTimeHuman(task.estimatedMinutes)}` });
|
||||
@@ -1264,19 +1266,29 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
// Focus time tracking (in seconds for accuracy)
|
||||
this.focusSecondsToday = 0;
|
||||
this.secondsWorkedOnCurrentTask = 0;
|
||||
this.sessionStartSeconds = 0;
|
||||
// Track seconds at start of current session
|
||||
// Status bar element
|
||||
this.statusBarEl = null;
|
||||
// Reminder system
|
||||
this.reminderCheckInterval = null;
|
||||
this.notifiedReminders = /* @__PURE__ */ new Set();
|
||||
// Track which reminders have been shown
|
||||
// Daily reset check interval
|
||||
this.dailyResetCheckInterval = null;
|
||||
}
|
||||
// Track which reminders have been shown
|
||||
async onload() {
|
||||
await this.loadAllData();
|
||||
this.checkDailyReset();
|
||||
this.dailyResetCheckInterval = window.setInterval(() => {
|
||||
this.checkDailyReset();
|
||||
}, 6e4);
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (!document.hidden && this.isTimerRunning) {
|
||||
this.syncTimerFromTimestamp();
|
||||
if (!document.hidden) {
|
||||
this.checkDailyReset();
|
||||
if (this.isTimerRunning) {
|
||||
this.syncTimerFromTimestamp();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.registerView(
|
||||
@@ -1329,6 +1341,10 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
onunload() {
|
||||
this.stopTimer();
|
||||
this.stopReminderSystem();
|
||||
if (this.dailyResetCheckInterval) {
|
||||
window.clearInterval(this.dailyResetCheckInterval);
|
||||
this.dailyResetCheckInterval = null;
|
||||
}
|
||||
}
|
||||
async loadAllData() {
|
||||
const loaded = await this.loadData();
|
||||
@@ -1440,6 +1456,10 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
task.isActive = false;
|
||||
this.data.completedToday++;
|
||||
this.data.lastActiveDate = new Date().toDateString();
|
||||
if (this.activeTaskId === taskId && this.sessionStartSeconds !== void 0) {
|
||||
const sessionTime = this.secondsWorkedOnCurrentTask - this.sessionStartSeconds;
|
||||
this.focusSecondsToday += sessionTime;
|
||||
}
|
||||
this.archiveCompletedTask(task);
|
||||
this.updateDailyStats(task);
|
||||
if (this.settings.enableCelebrations) {
|
||||
@@ -1665,6 +1685,7 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
this.timerStartTimestamp = Date.now();
|
||||
this.pausedTimeRemaining = 0;
|
||||
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||
this.sessionStartSeconds = this.secondsWorkedOnCurrentTask;
|
||||
let alertShown = false;
|
||||
this.refreshView();
|
||||
this.updateStatusBar();
|
||||
@@ -1675,8 +1696,6 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
this.currentTimerSeconds = elapsedSeconds;
|
||||
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||
this.focusSecondsToday = newFocusSeconds;
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
if (!alertShown && this.currentTimerSeconds >= task.estimatedMinutes * 60) {
|
||||
@@ -1704,6 +1723,7 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
this.timerStartTimestamp = Date.now();
|
||||
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||
this.sessionStartSeconds = this.secondsWorkedOnCurrentTask;
|
||||
this.refreshView();
|
||||
this.updateStatusBar();
|
||||
this.timerInterval = window.setInterval(() => {
|
||||
@@ -1717,8 +1737,6 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
if (task.actualMinutes !== actualMinutes) {
|
||||
task.actualMinutes = actualMinutes;
|
||||
}
|
||||
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||
this.focusSecondsToday = newFocusSeconds;
|
||||
}
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
@@ -1804,8 +1822,6 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
if (task && !this.isBreakMode) {
|
||||
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||
this.focusSecondsToday = newFocusSeconds;
|
||||
}
|
||||
this.updateStatusBar();
|
||||
this.updateTimerDisplay();
|
||||
@@ -1837,6 +1853,7 @@ var ImmersePlugin = class extends import_obsidian4.Plugin {
|
||||
this.isStopwatchMode = false;
|
||||
this.activeTaskId = null;
|
||||
this.secondsWorkedOnCurrentTask = 0;
|
||||
this.sessionStartSeconds = 0;
|
||||
this.timerStartTimestamp = 0;
|
||||
this.pausedTimeRemaining = 0;
|
||||
this.updateStatusBar();
|
||||
|
||||
Reference in New Issue
Block a user