General Bug fixes on Timers/Breaks

This commit is contained in:
2025-11-23 11:46:13 +01:00
parent 285ac7a7c9
commit e66d9b4d25
4 changed files with 203 additions and 80 deletions

110
main.js
View File

@@ -43,7 +43,7 @@ var DEFAULT_SETTINGS = {
{ id: "personal", name: "Personal", color: "#22c55e", icon: "\u{1F3E0}" },
{ id: "learning", name: "Learning", color: "#f59e0b", icon: "\u{1F4DA}" }
],
autoStartBreak: false,
autoStartBreak: true,
tickSoundEnabled: false,
// Daily note logging
logToDaily: false
@@ -319,9 +319,11 @@ var FocusTaskView = class extends import_obsidian2.ItemView {
const activeCard = activeSection.createEl("div", { cls: "focus-task-active-card" });
if (this.plugin.isBreakMode) {
activeCard.addClass("focus-task-break-card");
activeCard.createEl("div", { cls: "focus-task-active-label", text: "\u2615 BREAK TIME" });
const breakLabel = this.plugin.currentTimerSeconds > 0 ? "\u2615 BREAK TIME" : "\u2728 BREAK COMPLETE";
activeCard.createEl("div", { cls: "focus-task-active-label", text: breakLabel });
} else {
activeCard.createEl("div", { cls: "focus-task-active-label", text: "\u{1F3AF} FOCUSING ON" });
const workLabel = this.plugin.currentTimerSeconds > 0 ? "\u{1F3AF} FOCUSING ON" : "\u{1F345} POMODORO COMPLETE";
activeCard.createEl("div", { cls: "focus-task-active-label", text: workLabel });
}
activeCard.createEl("div", { cls: "focus-task-active-task-name", text: task.text });
const timerDisplay = activeCard.createEl("div", { cls: "focus-task-timer-display" });
@@ -348,25 +350,62 @@ var FocusTaskView = class extends import_obsidian2.ItemView {
this.actualTimeEl = timeInfo.createEl("span", { text: `Actual: ${this.plugin.formatTimeHuman(task.actualMinutes)}` });
}
const controls = activeCard.createEl("div", { cls: "focus-task-active-controls" });
this.pauseBtnEl = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-secondary" });
this.pauseBtnEl.innerHTML = this.plugin.isTimerRunning ? "\u23F8 Pause" : "\u25B6 Resume";
this.pauseBtnEl.addEventListener("click", () => this.plugin.toggleTimer());
if (!this.plugin.isBreakMode) {
const completeBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-success" });
completeBtn.innerHTML = "\u2713 Complete";
completeBtn.addEventListener("click", () => this.plugin.completeTask(task.id));
}
const stopBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-danger" });
stopBtn.innerHTML = "\u2715 Stop";
stopBtn.addEventListener("click", () => this.plugin.stopTimer());
if (this.plugin.isBreakMode) {
const skipBreakBtn = controls.createEl("button", { cls: "focus-task-btn" });
skipBreakBtn.innerHTML = "\u23ED Skip Break";
skipBreakBtn.addEventListener("click", () => {
this.plugin.isBreakMode = false;
this.plugin.stopTimer();
this.refresh();
});
if (this.plugin.currentTimerSeconds > 0) {
this.pauseBtnEl = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-secondary" });
this.pauseBtnEl.innerHTML = this.plugin.isTimerRunning ? "\u23F8 Pause" : "\u25B6 Resume";
this.pauseBtnEl.addEventListener("click", () => this.plugin.toggleTimer());
const skipBreakBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-primary" });
skipBreakBtn.innerHTML = "\u23ED Skip Break";
skipBreakBtn.addEventListener("click", () => {
this.plugin.isBreakMode = false;
this.plugin.startPomodoro(task.id);
});
const stopBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-danger" });
stopBtn.innerHTML = "\u2715 Stop";
stopBtn.addEventListener("click", () => {
this.plugin.isBreakMode = false;
this.plugin.stopTimer();
});
} else {
const resumeWorkBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-success" });
resumeWorkBtn.innerHTML = "\u25B6 Resume Work";
resumeWorkBtn.addEventListener("click", () => {
this.plugin.isBreakMode = false;
this.plugin.startPomodoro(task.id);
});
const stopBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-danger" });
stopBtn.innerHTML = "\u2715 Stop";
stopBtn.addEventListener("click", () => {
this.plugin.isBreakMode = false;
this.plugin.stopTimer();
});
}
} else {
if (this.plugin.currentTimerSeconds > 0) {
this.pauseBtnEl = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-secondary" });
this.pauseBtnEl.innerHTML = this.plugin.isTimerRunning ? "\u23F8 Pause" : "\u25B6 Resume";
this.pauseBtnEl.addEventListener("click", () => this.plugin.toggleTimer());
const completeBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-success" });
completeBtn.innerHTML = "\u2713 Complete";
completeBtn.addEventListener("click", () => this.plugin.completeTask(task.id));
const stopBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-danger" });
stopBtn.innerHTML = "\u2715 Stop";
stopBtn.addEventListener("click", () => this.plugin.stopTimer());
} else {
const startBreakBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-secondary" });
startBreakBtn.innerHTML = "\u2615 Start Break";
startBreakBtn.addEventListener("click", () => this.plugin.startBreak());
const continueBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-primary" });
continueBtn.innerHTML = "\u25B6 Continue Working";
continueBtn.addEventListener("click", () => this.plugin.startPomodoro(task.id));
const completeBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-success" });
completeBtn.innerHTML = "\u2713 Complete";
completeBtn.addEventListener("click", () => this.plugin.completeTask(task.id));
const stopBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-danger" });
stopBtn.innerHTML = "\u2715 Stop";
stopBtn.addEventListener("click", () => this.plugin.stopTimer());
}
}
}
} else {
@@ -499,6 +538,7 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.pomodoroCount = 0;
// Focus time tracking (in seconds for accuracy)
this.focusSecondsToday = 0;
this.secondsWorkedOnCurrentTask = 0;
// Status bar element
this.statusBarEl = null;
}
@@ -671,11 +711,13 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.isBreakMode = false;
this.currentTimerSeconds = 0;
this.isTimerRunning = true;
this.secondsWorkedOnCurrentTask = task.actualMinutes * 60;
this.refreshView();
this.updateStatusBar();
this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds++;
task.actualMinutes = Math.floor(this.currentTimerSeconds / 60);
this.secondsWorkedOnCurrentTask++;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
this.focusSecondsToday++;
this.updateStatusBar();
this.updateTimerDisplay();
@@ -698,14 +740,14 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.isBreakMode = false;
this.currentTimerSeconds = this.settings.pomodoroWorkMinutes * 60;
this.isTimerRunning = true;
this.secondsWorkedOnCurrentTask = task.actualMinutes * 60;
this.refreshView();
this.updateStatusBar();
let secondsWorked = 0;
this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds--;
if (!this.isBreakMode) {
secondsWorked++;
task.actualMinutes = Math.floor(secondsWorked / 60);
this.secondsWorkedOnCurrentTask++;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
this.focusSecondsToday++;
}
this.updateStatusBar();
@@ -716,6 +758,14 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
}, 1e3);
}
handlePomodoroEnd() {
if (this.timerInterval) {
window.clearInterval(this.timerInterval);
this.timerInterval = null;
}
this.currentTimerSeconds = 0;
this.isTimerRunning = false;
this.updateStatusBar();
this.updateTimerDisplay();
if (!this.isBreakMode) {
this.pomodoroCount++;
this.data.pomodorosCompleted++;
@@ -726,20 +776,20 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
if (this.settings.autoStartBreak) {
this.startBreak();
} else {
this.stopTimer();
this.refreshView();
}
} else {
if (this.settings.enableSounds) {
this.playAlertSound();
}
new import_obsidian3.Notice("\u26A1 Break over! Ready to focus?");
this.isBreakMode = false;
this.stopTimer();
this.refreshView();
}
this.saveAllData();
}
startBreak() {
this.isBreakMode = true;
this.isTimerRunning = true;
const isLongBreak = this.pomodoroCount % this.settings.longBreakInterval === 0;
this.currentTimerSeconds = (isLongBreak ? this.settings.longBreakMinutes : this.settings.pomodoroBreakMinutes) * 60;
new import_obsidian3.Notice(isLongBreak ? "\u2615 Long break time!" : "\u2615 Short break time!");
@@ -767,7 +817,8 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds--;
if (task && !this.isBreakMode) {
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
this.secondsWorkedOnCurrentTask++;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
this.focusSecondsToday++;
}
this.updateStatusBar();
@@ -795,6 +846,7 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
}
this.isTimerRunning = false;
this.activeTaskId = null;
this.secondsWorkedOnCurrentTask = 0;
this.updateStatusBar();
this.saveAllData();
this.refreshView();