Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2800a7507e | |||
| 2f861c2fcb | |||
| 9abdd10ada | |||
| e66d9b4d25 | |||
| 285ac7a7c9 | |||
| 9e35a2603c | |||
| f5e4a16aff | |||
| 9014f086d6 | |||
| d4f2af179f | |||
| aeb1d62895 | |||
| 9de2b00a2f | |||
| 66652afc90 | |||
| ad5b5e81bb | |||
| 951e9c5406 | |||
| 6dc4d2952d | |||
| 8e10724206 | |||
| d661466c81 | |||
| f634993637 |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,5 +1,7 @@
|
|||||||
# Build output
|
# Build output
|
||||||
*.js.map
|
*.js.map
|
||||||
|
release/
|
||||||
|
*.zip
|
||||||
|
|
||||||
# npm
|
# npm
|
||||||
node_modules/
|
node_modules/
|
||||||
@@ -15,4 +17,8 @@ package-lock.json
|
|||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# Obsidian
|
# Obsidian
|
||||||
data.json
|
data.json
|
||||||
|
|
||||||
|
# Development/Documentation (not for distribution)
|
||||||
|
RELEASE-GUIDE.md
|
||||||
|
.claude/
|
||||||
37
README.md
37
README.md
@@ -4,7 +4,7 @@ A powerful task management and focus timer plugin for [Obsidian](https://obsidia
|
|||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
## 🎯 Overview
|
## 🎯 Overview
|
||||||
|
|
||||||
@@ -46,6 +46,7 @@ Focus Task brings the power of time-boxed task management directly into your Obs
|
|||||||
- **Streak Counter**: Build momentum with consecutive productive days
|
- **Streak Counter**: Build momentum with consecutive productive days
|
||||||
- **Time Comparison**: Compare estimated vs. actual time to improve planning
|
- **Time Comparison**: Compare estimated vs. actual time to improve planning
|
||||||
- **Pomodoro Count**: Track total pomodoros completed
|
- **Pomodoro Count**: Track total pomodoros completed
|
||||||
|
- **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
|
||||||
@@ -136,7 +137,7 @@ Best for: Tracking time on open-ended tasks
|
|||||||
| Short Break | Length of short breaks | 5 min |
|
| Short Break | Length of short breaks | 5 min |
|
||||||
| Long Break | Length of long breaks | 15 min |
|
| Long Break | Length of long breaks | 15 min |
|
||||||
| Long Break Interval | Pomodoros before a long break | 4 |
|
| Long Break Interval | Pomodoros before a long break | 4 |
|
||||||
| Auto-start Breaks | Automatically start break timer | Off |
|
| Auto-start Breaks | Automatically start break timer | On |
|
||||||
|
|
||||||
### General
|
### General
|
||||||
| Setting | Description | Default |
|
| Setting | Description | Default |
|
||||||
@@ -146,6 +147,27 @@ Best for: Tracking time on open-ended tasks
|
|||||||
| Enable Celebrations | Show celebration messages | On |
|
| Enable Celebrations | Show celebration messages | On |
|
||||||
| Show Floating Timer | Display draggable timer widget | On |
|
| Show Floating Timer | Display draggable timer widget | On |
|
||||||
|
|
||||||
|
### Daily Note Integration
|
||||||
|
|
||||||
|
| Setting | Description | Default |
|
||||||
|
|---------|-------------|---------|
|
||||||
|
| Log to Daily Note | Automatically log completed tasks to your daily note | Off |
|
||||||
|
|
||||||
|
When enabled, completed tasks are automatically appended to your daily note with:
|
||||||
|
|
||||||
|
- Task name and list category
|
||||||
|
- Time spent vs. estimated time
|
||||||
|
- Completion timestamp
|
||||||
|
- Performance indicator (under/over/on target)
|
||||||
|
|
||||||
|
**Example entry:**
|
||||||
|
|
||||||
|
```
|
||||||
|
- [x] Write project proposal | 💼 Work | ⏱️ 45min / 30min (15min over estimate) | ✅ 14:30
|
||||||
|
```
|
||||||
|
|
||||||
|
**Requirements:** The core "Daily Notes" plugin must be enabled in Obsidian settings. Focus Task respects your Daily Notes configuration (folder, date format, and template).
|
||||||
|
|
||||||
### Lists
|
### Lists
|
||||||
Customize your task lists with:
|
Customize your task lists with:
|
||||||
- Custom names
|
- Custom names
|
||||||
@@ -224,17 +246,6 @@ npm run dev
|
|||||||
ln -s $(pwd) /path/to/vault/.obsidian/plugins/focus-task
|
ln -s $(pwd) /path/to/vault/.obsidian/plugins/focus-task
|
||||||
```
|
```
|
||||||
|
|
||||||
## 📝 Roadmap
|
|
||||||
|
|
||||||
- [ ] Integration with Obsidian Tasks plugin
|
|
||||||
- [ ] Calendar view for scheduled tasks
|
|
||||||
- [ ] Weekly/Monthly reports
|
|
||||||
- [ ] Task templates
|
|
||||||
- [ ] Sync with external task managers
|
|
||||||
- [ ] Mobile optimizations
|
|
||||||
- [ ] Task dependencies
|
|
||||||
- [ ] Time blocking in daily notes
|
|
||||||
|
|
||||||
## 📜 License
|
## 📜 License
|
||||||
|
|
||||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||||
|
|||||||
297
main.js
297
main.js
@@ -43,8 +43,10 @@ var DEFAULT_SETTINGS = {
|
|||||||
{ id: "personal", name: "Personal", color: "#22c55e", icon: "\u{1F3E0}" },
|
{ id: "personal", name: "Personal", color: "#22c55e", icon: "\u{1F3E0}" },
|
||||||
{ id: "learning", name: "Learning", color: "#f59e0b", icon: "\u{1F4DA}" }
|
{ id: "learning", name: "Learning", color: "#f59e0b", icon: "\u{1F4DA}" }
|
||||||
],
|
],
|
||||||
autoStartBreak: false,
|
autoStartBreak: true,
|
||||||
tickSoundEnabled: false
|
tickSoundEnabled: false,
|
||||||
|
// Daily note logging
|
||||||
|
logToDaily: false
|
||||||
};
|
};
|
||||||
var DEFAULT_DATA = {
|
var DEFAULT_DATA = {
|
||||||
tasks: [],
|
tasks: [],
|
||||||
@@ -317,9 +319,11 @@ var FocusTaskView = class extends import_obsidian2.ItemView {
|
|||||||
const activeCard = activeSection.createEl("div", { cls: "focus-task-active-card" });
|
const activeCard = activeSection.createEl("div", { cls: "focus-task-active-card" });
|
||||||
if (this.plugin.isBreakMode) {
|
if (this.plugin.isBreakMode) {
|
||||||
activeCard.addClass("focus-task-break-card");
|
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 {
|
} 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 });
|
activeCard.createEl("div", { cls: "focus-task-active-task-name", text: task.text });
|
||||||
const timerDisplay = activeCard.createEl("div", { cls: "focus-task-timer-display" });
|
const timerDisplay = activeCard.createEl("div", { cls: "focus-task-timer-display" });
|
||||||
@@ -346,25 +350,62 @@ var FocusTaskView = class extends import_obsidian2.ItemView {
|
|||||||
this.actualTimeEl = timeInfo.createEl("span", { text: `Actual: ${this.plugin.formatTimeHuman(task.actualMinutes)}` });
|
this.actualTimeEl = timeInfo.createEl("span", { text: `Actual: ${this.plugin.formatTimeHuman(task.actualMinutes)}` });
|
||||||
}
|
}
|
||||||
const controls = activeCard.createEl("div", { cls: "focus-task-active-controls" });
|
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) {
|
if (this.plugin.isBreakMode) {
|
||||||
const skipBreakBtn = controls.createEl("button", { cls: "focus-task-btn" });
|
if (this.plugin.currentTimerSeconds > 0) {
|
||||||
skipBreakBtn.innerHTML = "\u23ED Skip Break";
|
this.pauseBtnEl = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-secondary" });
|
||||||
skipBreakBtn.addEventListener("click", () => {
|
this.pauseBtnEl.innerHTML = this.plugin.isTimerRunning ? "\u23F8 Pause" : "\u25B6 Resume";
|
||||||
this.plugin.isBreakMode = false;
|
this.pauseBtnEl.addEventListener("click", () => this.plugin.toggleTimer());
|
||||||
this.plugin.stopTimer();
|
const skipBreakBtn = controls.createEl("button", { cls: "focus-task-btn focus-task-btn-primary" });
|
||||||
this.refresh();
|
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 {
|
} else {
|
||||||
@@ -495,14 +536,23 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
this.isBreakMode = false;
|
this.isBreakMode = false;
|
||||||
this.activeTaskId = null;
|
this.activeTaskId = null;
|
||||||
this.pomodoroCount = 0;
|
this.pomodoroCount = 0;
|
||||||
|
// Timestamp-based tracking for reliable background timing
|
||||||
|
this.timerStartTimestamp = 0;
|
||||||
|
this.pausedTimeRemaining = 0;
|
||||||
// Focus time tracking (in seconds for accuracy)
|
// Focus time tracking (in seconds for accuracy)
|
||||||
this.focusSecondsToday = 0;
|
this.focusSecondsToday = 0;
|
||||||
|
this.secondsWorkedOnCurrentTask = 0;
|
||||||
// Status bar element
|
// Status bar element
|
||||||
this.statusBarEl = null;
|
this.statusBarEl = null;
|
||||||
}
|
}
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadAllData();
|
await this.loadAllData();
|
||||||
this.checkDailyReset();
|
this.checkDailyReset();
|
||||||
|
document.addEventListener("visibilitychange", () => {
|
||||||
|
if (!document.hidden && this.isTimerRunning) {
|
||||||
|
this.syncTimerFromTimestamp();
|
||||||
|
}
|
||||||
|
});
|
||||||
this.registerView(
|
this.registerView(
|
||||||
VIEW_TYPE_FOCUS_TASK,
|
VIEW_TYPE_FOCUS_TASK,
|
||||||
(leaf) => new FocusTaskView(leaf, this)
|
(leaf) => new FocusTaskView(leaf, this)
|
||||||
@@ -545,6 +595,9 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
const loaded = await this.loadData();
|
const loaded = await this.loadData();
|
||||||
this.data = Object.assign({}, DEFAULT_DATA, (loaded == null ? void 0 : loaded.data) || {});
|
this.data = Object.assign({}, DEFAULT_DATA, (loaded == null ? void 0 : loaded.data) || {});
|
||||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, (loaded == null ? void 0 : loaded.settings) || {});
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, (loaded == null ? void 0 : loaded.settings) || {});
|
||||||
|
if (!this.settings.lists || this.settings.lists.length === 0) {
|
||||||
|
this.settings.lists = DEFAULT_SETTINGS.lists;
|
||||||
|
}
|
||||||
this.focusSecondsToday = (this.data.totalFocusMinutesToday || 0) * 60;
|
this.focusSecondsToday = (this.data.totalFocusMinutesToday || 0) * 60;
|
||||||
}
|
}
|
||||||
async saveAllData() {
|
async saveAllData() {
|
||||||
@@ -640,6 +693,9 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
if (this.settings.enableSounds) {
|
if (this.settings.enableSounds) {
|
||||||
this.playCompletionSound();
|
this.playCompletionSound();
|
||||||
}
|
}
|
||||||
|
if (this.settings.logToDaily) {
|
||||||
|
this.logTaskToDailyNote(task);
|
||||||
|
}
|
||||||
if (this.activeTaskId === taskId) {
|
if (this.activeTaskId === taskId) {
|
||||||
this.stopTimer();
|
this.stopTimer();
|
||||||
this.activeTaskId = null;
|
this.activeTaskId = null;
|
||||||
@@ -656,6 +712,41 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ============ Timer Management ============
|
// ============ Timer Management ============
|
||||||
|
// Sync timer based on timestamp when app returns from background
|
||||||
|
syncTimerFromTimestamp() {
|
||||||
|
if (!this.isTimerRunning || this.timerStartTimestamp === 0)
|
||||||
|
return;
|
||||||
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||||
|
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.updateStatusBar();
|
||||||
|
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);
|
||||||
if (!task)
|
if (!task)
|
||||||
@@ -666,11 +757,15 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
this.isBreakMode = false;
|
this.isBreakMode = false;
|
||||||
this.currentTimerSeconds = 0;
|
this.currentTimerSeconds = 0;
|
||||||
this.isTimerRunning = true;
|
this.isTimerRunning = true;
|
||||||
|
this.secondsWorkedOnCurrentTask = task.actualMinutes * 60;
|
||||||
|
this.timerStartTimestamp = Date.now();
|
||||||
|
this.pausedTimeRemaining = 0;
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds++;
|
this.currentTimerSeconds++;
|
||||||
task.actualMinutes = Math.floor(this.currentTimerSeconds / 60);
|
this.secondsWorkedOnCurrentTask++;
|
||||||
|
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
this.focusSecondsToday++;
|
this.focusSecondsToday++;
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
@@ -693,14 +788,19 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
this.isBreakMode = false;
|
this.isBreakMode = false;
|
||||||
this.currentTimerSeconds = this.settings.pomodoroWorkMinutes * 60;
|
this.currentTimerSeconds = this.settings.pomodoroWorkMinutes * 60;
|
||||||
this.isTimerRunning = true;
|
this.isTimerRunning = true;
|
||||||
|
this.secondsWorkedOnCurrentTask = Math.floor(task.actualMinutes * 60);
|
||||||
|
this.timerStartTimestamp = Date.now();
|
||||||
|
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
let secondsWorked = 0;
|
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
this.currentTimerSeconds--;
|
||||||
if (!this.isBreakMode) {
|
if (!this.isBreakMode) {
|
||||||
secondsWorked++;
|
this.secondsWorkedOnCurrentTask++;
|
||||||
task.actualMinutes = Math.floor(secondsWorked / 60);
|
const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
|
if (task.actualMinutes !== actualMinutes) {
|
||||||
|
task.actualMinutes = actualMinutes;
|
||||||
|
}
|
||||||
this.focusSecondsToday++;
|
this.focusSecondsToday++;
|
||||||
}
|
}
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
@@ -711,6 +811,14 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
}, 1e3);
|
}, 1e3);
|
||||||
}
|
}
|
||||||
handlePomodoroEnd() {
|
handlePomodoroEnd() {
|
||||||
|
if (this.timerInterval) {
|
||||||
|
window.clearInterval(this.timerInterval);
|
||||||
|
this.timerInterval = null;
|
||||||
|
}
|
||||||
|
this.currentTimerSeconds = 0;
|
||||||
|
this.isTimerRunning = false;
|
||||||
|
this.updateStatusBar();
|
||||||
|
this.updateTimerDisplay();
|
||||||
if (!this.isBreakMode) {
|
if (!this.isBreakMode) {
|
||||||
this.pomodoroCount++;
|
this.pomodoroCount++;
|
||||||
this.data.pomodorosCompleted++;
|
this.data.pomodorosCompleted++;
|
||||||
@@ -721,22 +829,24 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
if (this.settings.autoStartBreak) {
|
if (this.settings.autoStartBreak) {
|
||||||
this.startBreak();
|
this.startBreak();
|
||||||
} else {
|
} else {
|
||||||
this.stopTimer();
|
this.refreshView();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.settings.enableSounds) {
|
if (this.settings.enableSounds) {
|
||||||
this.playAlertSound();
|
this.playAlertSound();
|
||||||
}
|
}
|
||||||
new import_obsidian3.Notice("\u26A1 Break over! Ready to focus?");
|
new import_obsidian3.Notice("\u26A1 Break over! Ready to focus?");
|
||||||
this.isBreakMode = false;
|
this.refreshView();
|
||||||
this.stopTimer();
|
|
||||||
}
|
}
|
||||||
this.saveAllData();
|
this.saveAllData();
|
||||||
}
|
}
|
||||||
startBreak() {
|
startBreak() {
|
||||||
this.isBreakMode = true;
|
this.isBreakMode = true;
|
||||||
|
this.isTimerRunning = true;
|
||||||
const isLongBreak = this.pomodoroCount % this.settings.longBreakInterval === 0;
|
const isLongBreak = this.pomodoroCount % this.settings.longBreakInterval === 0;
|
||||||
this.currentTimerSeconds = (isLongBreak ? this.settings.longBreakMinutes : this.settings.pomodoroBreakMinutes) * 60;
|
this.currentTimerSeconds = (isLongBreak ? this.settings.longBreakMinutes : this.settings.pomodoroBreakMinutes) * 60;
|
||||||
|
this.timerStartTimestamp = Date.now();
|
||||||
|
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||||
new import_obsidian3.Notice(isLongBreak ? "\u2615 Long break time!" : "\u2615 Short break time!");
|
new import_obsidian3.Notice(isLongBreak ? "\u2615 Long break time!" : "\u2615 Short break time!");
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
if (!this.timerInterval) {
|
if (!this.timerInterval) {
|
||||||
@@ -756,13 +866,16 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
window.clearInterval(this.timerInterval);
|
window.clearInterval(this.timerInterval);
|
||||||
this.timerInterval = null;
|
this.timerInterval = null;
|
||||||
this.isTimerRunning = false;
|
this.isTimerRunning = false;
|
||||||
|
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||||
} else if (this.activeTaskId) {
|
} else if (this.activeTaskId) {
|
||||||
this.isTimerRunning = true;
|
this.isTimerRunning = true;
|
||||||
|
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);
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
this.currentTimerSeconds--;
|
||||||
if (task && !this.isBreakMode) {
|
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.focusSecondsToday++;
|
||||||
}
|
}
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
@@ -790,6 +903,9 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
}
|
}
|
||||||
this.isTimerRunning = false;
|
this.isTimerRunning = false;
|
||||||
this.activeTaskId = null;
|
this.activeTaskId = null;
|
||||||
|
this.secondsWorkedOnCurrentTask = 0;
|
||||||
|
this.timerStartTimestamp = 0;
|
||||||
|
this.pausedTimeRemaining = 0;
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.saveAllData();
|
this.saveAllData();
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
@@ -878,6 +994,112 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
console.log("Audio not available");
|
console.log("Audio not available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ============ Daily Note Logging ============
|
||||||
|
async logTaskToDailyNote(task) {
|
||||||
|
try {
|
||||||
|
const list = this.settings.lists.find((l) => l.id === task.list);
|
||||||
|
const timeDiff = task.actualMinutes - task.estimatedMinutes;
|
||||||
|
let timeComparison = "";
|
||||||
|
if (timeDiff < 0) {
|
||||||
|
timeComparison = `${Math.abs(timeDiff)}min under estimate \u2728`;
|
||||||
|
} else if (timeDiff > 0) {
|
||||||
|
timeComparison = `${timeDiff}min over estimate`;
|
||||||
|
} else {
|
||||||
|
timeComparison = `exactly on target \u{1F3AF}`;
|
||||||
|
}
|
||||||
|
const completedTime = new Date(task.completedAt || Date.now()).toLocaleTimeString("en-US", {
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: false
|
||||||
|
});
|
||||||
|
const taskEntry = `- [x] ${task.text} | ${(list == null ? void 0 : list.icon) || "\u{1F4CB}"} ${(list == null ? void 0 : list.name) || "Task"} | \u23F1\uFE0F ${this.formatTimeHuman(task.actualMinutes)} / ${this.formatTimeHuman(task.estimatedMinutes)} (${timeComparison}) | \u2705 ${completedTime}`;
|
||||||
|
await this.appendToDailyNote(taskEntry);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to log task to daily note:", e);
|
||||||
|
new import_obsidian3.Notice("Failed to log task to daily note. Make sure Daily Notes core plugin is enabled.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getDailyNoteSettings() {
|
||||||
|
var _a, _b, _c;
|
||||||
|
const dailyNotesPlugin = (_b = (_a = this.app.internalPlugins) == null ? void 0 : _a.plugins) == null ? void 0 : _b["daily-notes"];
|
||||||
|
if (!(dailyNotesPlugin == null ? void 0 : dailyNotesPlugin.enabled)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const settings = (_c = dailyNotesPlugin.instance) == null ? void 0 : _c.options;
|
||||||
|
return {
|
||||||
|
folder: (settings == null ? void 0 : settings.folder) || "",
|
||||||
|
format: (settings == null ? void 0 : settings.format) || "YYYY-MM-DD",
|
||||||
|
template: (settings == null ? void 0 : settings.template) || ""
|
||||||
|
};
|
||||||
|
}
|
||||||
|
formatDailyNoteDate(format) {
|
||||||
|
const now = new Date();
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = now.getMonth() + 1;
|
||||||
|
const day = now.getDate();
|
||||||
|
let result = format;
|
||||||
|
result = result.replace(/YYYY/g, year.toString());
|
||||||
|
result = result.replace(/YY/g, year.toString().slice(-2));
|
||||||
|
result = result.replace(/MMMM/g, now.toLocaleDateString("en-US", { month: "long" }));
|
||||||
|
result = result.replace(/MMM/g, now.toLocaleDateString("en-US", { month: "short" }));
|
||||||
|
result = result.replace(/MM/g, month.toString().padStart(2, "0"));
|
||||||
|
result = result.replace(/(?<![A-Za-z])M(?![A-Za-z])/g, month.toString());
|
||||||
|
result = result.replace(/dddd/g, now.toLocaleDateString("en-US", { weekday: "long" }));
|
||||||
|
result = result.replace(/ddd/g, now.toLocaleDateString("en-US", { weekday: "short" }));
|
||||||
|
result = result.replace(/DD/g, day.toString().padStart(2, "0"));
|
||||||
|
result = result.replace(/(?<![A-Za-z])D(?![A-Za-z])/g, day.toString());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
async getOrCreateDailyNote() {
|
||||||
|
const { vault } = this.app;
|
||||||
|
const dailySettings = this.getDailyNoteSettings();
|
||||||
|
if (!dailySettings) {
|
||||||
|
new import_obsidian3.Notice("Daily Notes core plugin is not enabled. Please enable it in Settings \u2192 Core plugins.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const filename = this.formatDailyNoteDate(dailySettings.format);
|
||||||
|
const folder = dailySettings.folder ? `${dailySettings.folder}/` : "";
|
||||||
|
const path = `${folder}${filename}.md`;
|
||||||
|
let file = vault.getAbstractFileByPath(path);
|
||||||
|
if (file && file instanceof import_obsidian3.TFile) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (dailySettings.folder) {
|
||||||
|
const folderExists = vault.getAbstractFileByPath(dailySettings.folder);
|
||||||
|
if (!folderExists) {
|
||||||
|
await vault.createFolder(dailySettings.folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let content = "";
|
||||||
|
if (dailySettings.template) {
|
||||||
|
const templatePath = dailySettings.template.endsWith(".md") ? dailySettings.template : `${dailySettings.template}.md`;
|
||||||
|
const templateFile = vault.getAbstractFileByPath(templatePath);
|
||||||
|
if (templateFile && templateFile instanceof import_obsidian3.TFile) {
|
||||||
|
content = await vault.read(templateFile);
|
||||||
|
content = content.replace(/{{date}}/g, filename).replace(/{{time}}/g, new Date().toLocaleTimeString()).replace(/{{title}}/g, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const newFile = await vault.create(path, content);
|
||||||
|
new import_obsidian3.Notice(`\u{1F4DD} Created daily note: ${filename}`);
|
||||||
|
return newFile;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to create daily note:", e);
|
||||||
|
new import_obsidian3.Notice("Failed to create daily note");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async appendToDailyNote(content) {
|
||||||
|
const file = await this.getOrCreateDailyNote();
|
||||||
|
if (!file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { vault } = this.app;
|
||||||
|
const existingContent = await vault.read(file);
|
||||||
|
const newContent = existingContent.trimEnd() + "\n" + content + "\n";
|
||||||
|
await vault.modify(file, newContent);
|
||||||
|
new import_obsidian3.Notice("\u{1F4DD} Task logged to daily note");
|
||||||
|
}
|
||||||
// ============ Utilities ============
|
// ============ Utilities ============
|
||||||
formatTime(seconds) {
|
formatTime(seconds) {
|
||||||
const absSeconds = Math.abs(seconds);
|
const absSeconds = Math.abs(seconds);
|
||||||
@@ -985,6 +1207,21 @@ var FocusTaskSettingTab = class extends import_obsidian3.PluginSettingTab {
|
|||||||
this.plugin.settings.enableCelebrations = value;
|
this.plugin.settings.enableCelebrations = value;
|
||||||
await this.plugin.saveAllData();
|
await this.plugin.saveAllData();
|
||||||
}));
|
}));
|
||||||
|
containerEl.createEl("h2", { text: "\u{1F4DD} Daily Note Integration" });
|
||||||
|
new import_obsidian3.Setting(containerEl).setName("Log completed tasks to daily note").setDesc("When you complete a task, add an entry to your daily note. Uses the core Daily Notes plugin settings.").addToggle((toggle) => toggle.setValue(this.plugin.settings.logToDaily).onChange(async (value) => {
|
||||||
|
this.plugin.settings.logToDaily = value;
|
||||||
|
await this.plugin.saveAllData();
|
||||||
|
}));
|
||||||
|
const infoEl = containerEl.createEl("div", { cls: "setting-item-description" });
|
||||||
|
infoEl.style.marginTop = "-10px";
|
||||||
|
infoEl.style.marginBottom = "20px";
|
||||||
|
infoEl.innerHTML = `
|
||||||
|
<small>
|
||||||
|
This feature uses the <strong>Daily Notes</strong> core plugin.
|
||||||
|
Configure your daily note folder, date format, and template in
|
||||||
|
<em>Settings \u2192 Core plugins \u2192 Daily notes</em>.
|
||||||
|
</small>
|
||||||
|
`;
|
||||||
containerEl.createEl("h2", { text: "\u{1F4CB} Lists" });
|
containerEl.createEl("h2", { text: "\u{1F4CB} Lists" });
|
||||||
this.plugin.settings.lists.forEach((list, index) => {
|
this.plugin.settings.lists.forEach((list, index) => {
|
||||||
new import_obsidian3.Setting(containerEl).setName(`${list.icon} ${list.name}`).addText((text) => text.setValue(list.name).setPlaceholder("List name").onChange(async (value) => {
|
new import_obsidian3.Setting(containerEl).setName(`${list.icon} ${list.name}`).addText((text) => text.setValue(list.name).setPlaceholder("List name").onChange(async (value) => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "focus-task",
|
"id": "focus-task",
|
||||||
"name": "Focus Task",
|
"name": "Focus Task",
|
||||||
"version": "1.0.2",
|
"version": "1.0.7",
|
||||||
"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",
|
||||||
|
|||||||
62
package-release.mjs
Normal file
62
package-release.mjs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
import { dirname } from 'path';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
|
const RELEASE_DIR = 'release';
|
||||||
|
const FILES_TO_INCLUDE = [
|
||||||
|
'main.js',
|
||||||
|
'manifest.json',
|
||||||
|
'styles.css'
|
||||||
|
];
|
||||||
|
|
||||||
|
async function packageRelease() {
|
||||||
|
try {
|
||||||
|
console.log('📦 Packaging release files...\n');
|
||||||
|
|
||||||
|
// Create release directory if it doesn't exist
|
||||||
|
try {
|
||||||
|
await fs.access(RELEASE_DIR);
|
||||||
|
console.log(`✓ Release directory exists: ${RELEASE_DIR}`);
|
||||||
|
} catch {
|
||||||
|
await fs.mkdir(RELEASE_DIR);
|
||||||
|
console.log(`✓ Created release directory: ${RELEASE_DIR}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy each file
|
||||||
|
for (const file of FILES_TO_INCLUDE) {
|
||||||
|
const sourcePath = path.join(__dirname, file);
|
||||||
|
const destPath = path.join(__dirname, RELEASE_DIR, file);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.copyFile(sourcePath, destPath);
|
||||||
|
console.log(`✓ Copied ${file}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`✗ Failed to copy ${file}:`, error.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read manifest to get version
|
||||||
|
const manifestPath = path.join(__dirname, 'manifest.json');
|
||||||
|
const manifestContent = await fs.readFile(manifestPath, 'utf8');
|
||||||
|
const manifest = JSON.parse(manifestContent);
|
||||||
|
|
||||||
|
console.log(`\n✅ Release package created successfully!`);
|
||||||
|
console.log(`📁 Location: ./${RELEASE_DIR}/`);
|
||||||
|
console.log(`📌 Version: ${manifest.version}`);
|
||||||
|
console.log(`\nFiles included:`);
|
||||||
|
FILES_TO_INCLUDE.forEach(file => console.log(` - ${file}`));
|
||||||
|
console.log(`\n💡 Tip: You can now upload these files from the '${RELEASE_DIR}' directory to your Gitea release.`);
|
||||||
|
console.log(`💡 Tip: To create a zip, run: cd ${RELEASE_DIR} && zip -r ../focus-task-${manifest.version}.zip *`);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Error packaging release:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
packageRelease();
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "focus-task",
|
"name": "focus-task",
|
||||||
"version": "1.0.2",
|
"version": "1.0.7",
|
||||||
"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": {
|
||||||
"dev": "node esbuild.config.mjs",
|
"dev": "node esbuild.config.mjs",
|
||||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||||
|
"package": "npm run build && node package-release.mjs",
|
||||||
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
362
src/main.ts
362
src/main.ts
@@ -4,6 +4,7 @@ import {
|
|||||||
Plugin,
|
Plugin,
|
||||||
PluginSettingTab,
|
PluginSettingTab,
|
||||||
Setting,
|
Setting,
|
||||||
|
TFile,
|
||||||
WorkspaceLeaf,
|
WorkspaceLeaf,
|
||||||
} from 'obsidian';
|
} from 'obsidian';
|
||||||
|
|
||||||
@@ -35,19 +36,31 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
isBreakMode: boolean = false;
|
isBreakMode: boolean = false;
|
||||||
activeTaskId: string | null = null;
|
activeTaskId: string | null = null;
|
||||||
pomodoroCount: number = 0;
|
pomodoroCount: number = 0;
|
||||||
|
|
||||||
|
// Timestamp-based tracking for reliable background timing
|
||||||
|
private timerStartTimestamp: number = 0;
|
||||||
|
private pausedTimeRemaining: number = 0;
|
||||||
|
|
||||||
// Focus time tracking (in seconds for accuracy)
|
// Focus time tracking (in seconds for accuracy)
|
||||||
private focusSecondsToday: number = 0;
|
private focusSecondsToday: number = 0;
|
||||||
|
private secondsWorkedOnCurrentTask: number = 0;
|
||||||
|
|
||||||
// Status bar element
|
// Status bar element
|
||||||
statusBarEl: HTMLElement | null = null;
|
statusBarEl: HTMLElement | null = null;
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadAllData();
|
await this.loadAllData();
|
||||||
|
|
||||||
// Check and reset daily stats
|
// Check and reset daily stats
|
||||||
this.checkDailyReset();
|
this.checkDailyReset();
|
||||||
|
|
||||||
|
// Handle visibility changes to sync timer when app comes back to foreground
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (!document.hidden && this.isTimerRunning) {
|
||||||
|
this.syncTimerFromTimestamp();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Register the main view
|
// Register the main view
|
||||||
this.registerView(
|
this.registerView(
|
||||||
VIEW_TYPE_FOCUS_TASK,
|
VIEW_TYPE_FOCUS_TASK,
|
||||||
@@ -103,8 +116,17 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
|
|
||||||
async loadAllData() {
|
async loadAllData() {
|
||||||
const loaded = await this.loadData();
|
const loaded = await this.loadData();
|
||||||
|
|
||||||
|
// Merge loaded data with defaults (defaults first, then override with loaded)
|
||||||
|
// This ensures new fields get default values even for existing installs
|
||||||
this.data = Object.assign({}, DEFAULT_DATA, loaded?.data || {});
|
this.data = Object.assign({}, DEFAULT_DATA, loaded?.data || {});
|
||||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, loaded?.settings || {});
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, loaded?.settings || {});
|
||||||
|
|
||||||
|
// Ensure lists array exists and has at least the default lists
|
||||||
|
if (!this.settings.lists || this.settings.lists.length === 0) {
|
||||||
|
this.settings.lists = DEFAULT_SETTINGS.lists;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize seconds from stored minutes
|
// Initialize seconds from stored minutes
|
||||||
this.focusSecondsToday = (this.data.totalFocusMinutesToday || 0) * 60;
|
this.focusSecondsToday = (this.data.totalFocusMinutesToday || 0) * 60;
|
||||||
}
|
}
|
||||||
@@ -224,6 +246,11 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
this.playCompletionSound();
|
this.playCompletionSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log to daily note
|
||||||
|
if (this.settings.logToDaily) {
|
||||||
|
this.logTaskToDailyNote(task);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.activeTaskId === taskId) {
|
if (this.activeTaskId === taskId) {
|
||||||
this.stopTimer();
|
this.stopTimer();
|
||||||
this.activeTaskId = null;
|
this.activeTaskId = null;
|
||||||
@@ -244,6 +271,53 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
|
|
||||||
// ============ Timer Management ============
|
// ============ Timer Management ============
|
||||||
|
|
||||||
|
// Sync timer based on timestamp when app returns from background
|
||||||
|
syncTimerFromTimestamp() {
|
||||||
|
if (!this.isTimerRunning || this.timerStartTimestamp === 0) return;
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1000);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update displays
|
||||||
|
this.updateStatusBar();
|
||||||
|
this.updateTimerDisplay();
|
||||||
|
this.saveAllData();
|
||||||
|
}
|
||||||
|
|
||||||
startTimer(taskId: string) {
|
startTimer(taskId: string) {
|
||||||
const task = this.data.tasks.find(t => t.id === taskId);
|
const task = this.data.tasks.find(t => t.id === taskId);
|
||||||
if (!task) return;
|
if (!task) return;
|
||||||
@@ -257,6 +331,11 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
this.isBreakMode = false;
|
this.isBreakMode = false;
|
||||||
this.currentTimerSeconds = 0;
|
this.currentTimerSeconds = 0;
|
||||||
this.isTimerRunning = true;
|
this.isTimerRunning = true;
|
||||||
|
this.secondsWorkedOnCurrentTask = task.actualMinutes * 60;
|
||||||
|
|
||||||
|
// Set timestamp for background tracking (stopwatch mode)
|
||||||
|
this.timerStartTimestamp = Date.now();
|
||||||
|
this.pausedTimeRemaining = 0; // 0 indicates stopwatch mode
|
||||||
|
|
||||||
// Full refresh to show the active task card
|
// Full refresh to show the active task card
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
@@ -265,15 +344,16 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
// Start interval (count up mode - stopwatch)
|
// Start interval (count up mode - stopwatch)
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds++;
|
this.currentTimerSeconds++;
|
||||||
task.actualMinutes = Math.floor(this.currentTimerSeconds / 60);
|
this.secondsWorkedOnCurrentTask++;
|
||||||
|
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
|
|
||||||
// Track focus time
|
// Track focus time
|
||||||
this.focusSecondsToday++;
|
this.focusSecondsToday++;
|
||||||
|
|
||||||
// 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
|
||||||
if (this.currentTimerSeconds === task.estimatedMinutes * 60) {
|
if (this.currentTimerSeconds === task.estimatedMinutes * 60) {
|
||||||
if (this.settings.enableSounds) {
|
if (this.settings.enableSounds) {
|
||||||
@@ -297,23 +377,33 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
this.currentTimerSeconds = this.settings.pomodoroWorkMinutes * 60;
|
this.currentTimerSeconds = this.settings.pomodoroWorkMinutes * 60;
|
||||||
this.isTimerRunning = true;
|
this.isTimerRunning = true;
|
||||||
|
|
||||||
|
// Initialize from existing actual time to preserve progress across breaks
|
||||||
|
// Store as seconds for precision
|
||||||
|
this.secondsWorkedOnCurrentTask = Math.floor(task.actualMinutes * 60);
|
||||||
|
|
||||||
|
// Set timestamp for background tracking (pomodoro countdown mode)
|
||||||
|
this.timerStartTimestamp = Date.now();
|
||||||
|
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||||
|
|
||||||
// Full refresh to show the active task card
|
// Full refresh to show the active task card
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
|
|
||||||
// Track seconds worked for accurate focus time
|
|
||||||
let secondsWorked = 0;
|
|
||||||
|
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
this.currentTimerSeconds--;
|
||||||
|
|
||||||
if (!this.isBreakMode) {
|
if (!this.isBreakMode) {
|
||||||
secondsWorked++;
|
this.secondsWorkedOnCurrentTask++;
|
||||||
task.actualMinutes = Math.floor(secondsWorked / 60);
|
// Calculate actual minutes from total seconds worked
|
||||||
|
const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
|
// Only update if changed to avoid unnecessary updates
|
||||||
|
if (task.actualMinutes !== actualMinutes) {
|
||||||
|
task.actualMinutes = actualMinutes;
|
||||||
|
}
|
||||||
// Increment focus time by 1 second
|
// Increment focus time by 1 second
|
||||||
this.focusSecondsToday++;
|
this.focusSecondsToday++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Light update - only timer display, no full refresh
|
// Light update - only timer display, no full refresh
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
@@ -325,45 +415,65 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handlePomodoroEnd() {
|
handlePomodoroEnd() {
|
||||||
|
// Stop the timer interval to prevent going into negative
|
||||||
|
if (this.timerInterval) {
|
||||||
|
window.clearInterval(this.timerInterval);
|
||||||
|
this.timerInterval = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set timer to 0 to ensure it doesn't show negative
|
||||||
|
this.currentTimerSeconds = 0;
|
||||||
|
this.isTimerRunning = false;
|
||||||
|
|
||||||
|
// Update displays immediately
|
||||||
|
this.updateStatusBar();
|
||||||
|
this.updateTimerDisplay();
|
||||||
|
|
||||||
if (!this.isBreakMode) {
|
if (!this.isBreakMode) {
|
||||||
// Work session ended
|
// Work session ended
|
||||||
this.pomodoroCount++;
|
this.pomodoroCount++;
|
||||||
this.data.pomodorosCompleted++;
|
this.data.pomodorosCompleted++;
|
||||||
|
|
||||||
if (this.settings.enableSounds) {
|
if (this.settings.enableSounds) {
|
||||||
this.playAlertSound();
|
this.playAlertSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
new Notice('🍅 Pomodoro complete! Time for a break.');
|
new Notice('🍅 Pomodoro complete! Time for a break.');
|
||||||
|
|
||||||
if (this.settings.autoStartBreak) {
|
if (this.settings.autoStartBreak) {
|
||||||
this.startBreak();
|
this.startBreak();
|
||||||
} else {
|
} else {
|
||||||
this.stopTimer();
|
this.refreshView();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Break ended
|
// Break ended - keep timer at 0 until user resumes
|
||||||
if (this.settings.enableSounds) {
|
if (this.settings.enableSounds) {
|
||||||
this.playAlertSound();
|
this.playAlertSound();
|
||||||
}
|
}
|
||||||
new Notice('⚡ Break over! Ready to focus?');
|
new Notice('⚡ Break over! Ready to focus?');
|
||||||
this.isBreakMode = false;
|
|
||||||
this.stopTimer();
|
// Keep the break card visible with timer at 0:00
|
||||||
|
this.refreshView();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveAllData();
|
this.saveAllData();
|
||||||
}
|
}
|
||||||
|
|
||||||
startBreak() {
|
startBreak() {
|
||||||
this.isBreakMode = true;
|
this.isBreakMode = true;
|
||||||
|
this.isTimerRunning = true;
|
||||||
const isLongBreak = this.pomodoroCount % this.settings.longBreakInterval === 0;
|
const isLongBreak = this.pomodoroCount % this.settings.longBreakInterval === 0;
|
||||||
this.currentTimerSeconds = (isLongBreak ? this.settings.longBreakMinutes : this.settings.pomodoroBreakMinutes) * 60;
|
this.currentTimerSeconds = (isLongBreak ? this.settings.longBreakMinutes : this.settings.pomodoroBreakMinutes) * 60;
|
||||||
|
|
||||||
|
// Set timestamp for background tracking (break countdown mode)
|
||||||
|
this.timerStartTimestamp = Date.now();
|
||||||
|
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||||
|
|
||||||
new Notice(isLongBreak ? '☕ Long break time!' : '☕ Short break time!');
|
new Notice(isLongBreak ? '☕ Long break time!' : '☕ Short break time!');
|
||||||
|
|
||||||
// Full refresh to show break state
|
// Full refresh to show break state
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
|
|
||||||
if (!this.timerInterval) {
|
if (!this.timerInterval) {
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
this.currentTimerSeconds--;
|
||||||
@@ -376,25 +486,28 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleTimer() {
|
toggleTimer() {
|
||||||
if (this.isTimerRunning && this.timerInterval) {
|
if (this.isTimerRunning && this.timerInterval) {
|
||||||
// Pause
|
// Pause - save current state
|
||||||
window.clearInterval(this.timerInterval);
|
window.clearInterval(this.timerInterval);
|
||||||
this.timerInterval = null;
|
this.timerInterval = null;
|
||||||
this.isTimerRunning = false;
|
this.isTimerRunning = false;
|
||||||
|
this.pausedTimeRemaining = this.currentTimerSeconds;
|
||||||
} else if (this.activeTaskId) {
|
} else if (this.activeTaskId) {
|
||||||
// Resume
|
// Resume - restart with new timestamp
|
||||||
this.isTimerRunning = true;
|
this.isTimerRunning = true;
|
||||||
|
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);
|
||||||
|
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
this.currentTimerSeconds--;
|
||||||
if (task && !this.isBreakMode) {
|
if (task && !this.isBreakMode) {
|
||||||
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
this.secondsWorkedOnCurrentTask++;
|
||||||
|
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
// Track focus time
|
// Track focus time
|
||||||
this.focusSecondsToday++;
|
this.focusSecondsToday++;
|
||||||
}
|
}
|
||||||
@@ -409,7 +522,7 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
} else {
|
} else {
|
||||||
new Notice('No active task. Select a task first.');
|
new Notice('No active task. Select a task first.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Full refresh to update pause/resume button state
|
// Full refresh to update pause/resume button state
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
@@ -420,16 +533,19 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
window.clearInterval(this.timerInterval);
|
window.clearInterval(this.timerInterval);
|
||||||
this.timerInterval = null;
|
this.timerInterval = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.activeTaskId) {
|
if (this.activeTaskId) {
|
||||||
const task = this.data.tasks.find(t => t.id === this.activeTaskId);
|
const task = this.data.tasks.find(t => t.id === this.activeTaskId);
|
||||||
if (task) {
|
if (task) {
|
||||||
task.isActive = false;
|
task.isActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isTimerRunning = false;
|
this.isTimerRunning = false;
|
||||||
this.activeTaskId = null;
|
this.activeTaskId = null;
|
||||||
|
this.secondsWorkedOnCurrentTask = 0;
|
||||||
|
this.timerStartTimestamp = 0;
|
||||||
|
this.pausedTimeRemaining = 0;
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.saveAllData();
|
this.saveAllData();
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
@@ -541,6 +657,161 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ Daily Note Logging ============
|
||||||
|
|
||||||
|
async logTaskToDailyNote(task: FocusTask) {
|
||||||
|
try {
|
||||||
|
const list = this.settings.lists.find(l => l.id === task.list);
|
||||||
|
|
||||||
|
// Format the task entry
|
||||||
|
const timeDiff = task.actualMinutes - task.estimatedMinutes;
|
||||||
|
let timeComparison = '';
|
||||||
|
if (timeDiff < 0) {
|
||||||
|
timeComparison = `${Math.abs(timeDiff)}min under estimate ✨`;
|
||||||
|
} else if (timeDiff > 0) {
|
||||||
|
timeComparison = `${timeDiff}min over estimate`;
|
||||||
|
} else {
|
||||||
|
timeComparison = `exactly on target 🎯`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const completedTime = new Date(task.completedAt || Date.now()).toLocaleTimeString('en-US', {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const taskEntry = `- [x] ${task.text} | ${list?.icon || '📋'} ${list?.name || 'Task'} | ⏱️ ${this.formatTimeHuman(task.actualMinutes)} / ${this.formatTimeHuman(task.estimatedMinutes)} (${timeComparison}) | ✅ ${completedTime}`;
|
||||||
|
|
||||||
|
await this.appendToDailyNote(taskEntry);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to log task to daily note:', e);
|
||||||
|
new Notice('Failed to log task to daily note. Make sure Daily Notes core plugin is enabled.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getDailyNoteSettings(): { folder: string; format: string; template: string } | null {
|
||||||
|
// Access the core Daily Notes plugin settings
|
||||||
|
const dailyNotesPlugin = (this.app as any).internalPlugins?.plugins?.['daily-notes'];
|
||||||
|
|
||||||
|
if (!dailyNotesPlugin?.enabled) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = dailyNotesPlugin.instance?.options;
|
||||||
|
return {
|
||||||
|
folder: settings?.folder || '',
|
||||||
|
format: settings?.format || 'YYYY-MM-DD',
|
||||||
|
template: settings?.template || '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
formatDailyNoteDate(format: string): string {
|
||||||
|
const now = new Date();
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = now.getMonth() + 1;
|
||||||
|
const day = now.getDate();
|
||||||
|
|
||||||
|
// Use placeholders to avoid replacement conflicts
|
||||||
|
// Replace longer tokens first, use unique placeholders
|
||||||
|
let result = format;
|
||||||
|
|
||||||
|
// Year tokens
|
||||||
|
result = result.replace(/YYYY/g, year.toString());
|
||||||
|
result = result.replace(/YY/g, year.toString().slice(-2));
|
||||||
|
|
||||||
|
// Month tokens (longer first)
|
||||||
|
result = result.replace(/MMMM/g, now.toLocaleDateString('en-US', { month: 'long' }));
|
||||||
|
result = result.replace(/MMM/g, now.toLocaleDateString('en-US', { month: 'short' }));
|
||||||
|
result = result.replace(/MM/g, month.toString().padStart(2, '0'));
|
||||||
|
// Only replace standalone M, not part of other tokens
|
||||||
|
result = result.replace(/(?<![A-Za-z])M(?![A-Za-z])/g, month.toString());
|
||||||
|
|
||||||
|
// Day tokens (longer first)
|
||||||
|
result = result.replace(/dddd/g, now.toLocaleDateString('en-US', { weekday: 'long' }));
|
||||||
|
result = result.replace(/ddd/g, now.toLocaleDateString('en-US', { weekday: 'short' }));
|
||||||
|
result = result.replace(/DD/g, day.toString().padStart(2, '0'));
|
||||||
|
// Only replace standalone D, not part of other tokens
|
||||||
|
result = result.replace(/(?<![A-Za-z])D(?![A-Za-z])/g, day.toString());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getOrCreateDailyNote(): Promise<TFile | null> {
|
||||||
|
const { vault } = this.app;
|
||||||
|
const dailySettings = this.getDailyNoteSettings();
|
||||||
|
|
||||||
|
if (!dailySettings) {
|
||||||
|
new Notice('Daily Notes core plugin is not enabled. Please enable it in Settings → Core plugins.');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filename = this.formatDailyNoteDate(dailySettings.format);
|
||||||
|
const folder = dailySettings.folder ? `${dailySettings.folder}/` : '';
|
||||||
|
const path = `${folder}${filename}.md`;
|
||||||
|
|
||||||
|
// Check if daily note exists
|
||||||
|
let file = vault.getAbstractFileByPath(path);
|
||||||
|
|
||||||
|
if (file && file instanceof TFile) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the daily note
|
||||||
|
try {
|
||||||
|
// Ensure folder exists
|
||||||
|
if (dailySettings.folder) {
|
||||||
|
const folderExists = vault.getAbstractFileByPath(dailySettings.folder);
|
||||||
|
if (!folderExists) {
|
||||||
|
await vault.createFolder(dailySettings.folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if template exists and use it
|
||||||
|
let content = '';
|
||||||
|
if (dailySettings.template) {
|
||||||
|
const templatePath = dailySettings.template.endsWith('.md')
|
||||||
|
? dailySettings.template
|
||||||
|
: `${dailySettings.template}.md`;
|
||||||
|
const templateFile = vault.getAbstractFileByPath(templatePath);
|
||||||
|
|
||||||
|
if (templateFile && templateFile instanceof TFile) {
|
||||||
|
content = await vault.read(templateFile);
|
||||||
|
// Replace template variables
|
||||||
|
content = content
|
||||||
|
.replace(/{{date}}/g, filename)
|
||||||
|
.replace(/{{time}}/g, new Date().toLocaleTimeString())
|
||||||
|
.replace(/{{title}}/g, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the file
|
||||||
|
const newFile = await vault.create(path, content);
|
||||||
|
new Notice(`📝 Created daily note: ${filename}`);
|
||||||
|
return newFile;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to create daily note:', e);
|
||||||
|
new Notice('Failed to create daily note');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async appendToDailyNote(content: string) {
|
||||||
|
const file = await this.getOrCreateDailyNote();
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { vault } = this.app;
|
||||||
|
|
||||||
|
// Read existing content and append to the end
|
||||||
|
const existingContent = await vault.read(file);
|
||||||
|
const newContent = existingContent.trimEnd() + '\n' + content + '\n';
|
||||||
|
|
||||||
|
await vault.modify(file, newContent);
|
||||||
|
new Notice('📝 Task logged to daily note');
|
||||||
|
}
|
||||||
|
|
||||||
// ============ Utilities ============
|
// ============ Utilities ============
|
||||||
|
|
||||||
formatTime(seconds: number): string {
|
formatTime(seconds: number): string {
|
||||||
@@ -726,6 +997,31 @@ class FocusTaskSettingTab extends PluginSettingTab {
|
|||||||
await this.plugin.saveAllData();
|
await this.plugin.saveAllData();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Daily Note Integration
|
||||||
|
containerEl.createEl('h2', { text: '📝 Daily Note Integration' });
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Log completed tasks to daily note')
|
||||||
|
.setDesc('When you complete a task, add an entry to your daily note. Uses the core Daily Notes plugin settings.')
|
||||||
|
.addToggle(toggle => toggle
|
||||||
|
.setValue(this.plugin.settings.logToDaily)
|
||||||
|
.onChange(async value => {
|
||||||
|
this.plugin.settings.logToDaily = value;
|
||||||
|
await this.plugin.saveAllData();
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Show info about Daily Notes plugin
|
||||||
|
const infoEl = containerEl.createEl('div', { cls: 'setting-item-description' });
|
||||||
|
infoEl.style.marginTop = '-10px';
|
||||||
|
infoEl.style.marginBottom = '20px';
|
||||||
|
infoEl.innerHTML = `
|
||||||
|
<small>
|
||||||
|
This feature uses the <strong>Daily Notes</strong> core plugin.
|
||||||
|
Configure your daily note folder, date format, and template in
|
||||||
|
<em>Settings → Core plugins → Daily notes</em>.
|
||||||
|
</small>
|
||||||
|
`;
|
||||||
|
|
||||||
// Lists Management
|
// Lists Management
|
||||||
containerEl.createEl('h2', { text: '📋 Lists' });
|
containerEl.createEl('h2', { text: '📋 Lists' });
|
||||||
|
|
||||||
@@ -790,4 +1086,4 @@ class FocusTaskSettingTab extends PluginSettingTab {
|
|||||||
</p>
|
</p>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ export interface FocusTaskSettings {
|
|||||||
lists: TaskList[];
|
lists: TaskList[];
|
||||||
autoStartBreak: boolean;
|
autoStartBreak: boolean;
|
||||||
tickSoundEnabled: boolean;
|
tickSoundEnabled: boolean;
|
||||||
|
// Daily note logging
|
||||||
|
logToDaily: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FocusTaskData {
|
export interface FocusTaskData {
|
||||||
@@ -56,8 +58,10 @@ export const DEFAULT_SETTINGS: FocusTaskSettings = {
|
|||||||
{ id: 'personal', name: 'Personal', color: '#22c55e', icon: '🏠' },
|
{ id: 'personal', name: 'Personal', color: '#22c55e', icon: '🏠' },
|
||||||
{ id: 'learning', name: 'Learning', color: '#f59e0b', icon: '📚' },
|
{ id: 'learning', name: 'Learning', color: '#f59e0b', icon: '📚' },
|
||||||
],
|
],
|
||||||
autoStartBreak: false,
|
autoStartBreak: true,
|
||||||
tickSoundEnabled: false,
|
tickSoundEnabled: false,
|
||||||
|
// Daily note logging
|
||||||
|
logToDaily: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_DATA: FocusTaskData = {
|
export const DEFAULT_DATA: FocusTaskData = {
|
||||||
@@ -96,4 +100,4 @@ export const OVERTIME_MESSAGES = [
|
|||||||
{ emoji: '💪', message: 'Persistence pays off!' },
|
{ emoji: '💪', message: 'Persistence pays off!' },
|
||||||
{ emoji: '🏃', message: 'Marathon runner!' },
|
{ emoji: '🏃', message: 'Marathon runner!' },
|
||||||
{ emoji: '🔥', message: 'The grind is real!' },
|
{ emoji: '🔥', message: 'The grind is real!' },
|
||||||
];
|
];
|
||||||
|
|||||||
98
src/view.ts
98
src/view.ts
@@ -145,9 +145,11 @@ export class FocusTaskView extends ItemView {
|
|||||||
|
|
||||||
if (this.plugin.isBreakMode) {
|
if (this.plugin.isBreakMode) {
|
||||||
activeCard.addClass('focus-task-break-card');
|
activeCard.addClass('focus-task-break-card');
|
||||||
activeCard.createEl('div', { cls: 'focus-task-active-label', text: '☕ BREAK TIME' });
|
const breakLabel = this.plugin.currentTimerSeconds > 0 ? '☕ BREAK TIME' : '✨ BREAK COMPLETE';
|
||||||
|
activeCard.createEl('div', { cls: 'focus-task-active-label', text: breakLabel });
|
||||||
} else {
|
} else {
|
||||||
activeCard.createEl('div', { cls: 'focus-task-active-label', text: '🎯 FOCUSING ON' });
|
const workLabel = this.plugin.currentTimerSeconds > 0 ? '🎯 FOCUSING ON' : '🍅 POMODORO COMPLETE';
|
||||||
|
activeCard.createEl('div', { cls: 'focus-task-active-label', text: workLabel });
|
||||||
}
|
}
|
||||||
|
|
||||||
activeCard.createEl('div', { cls: 'focus-task-active-task-name', text: task.text });
|
activeCard.createEl('div', { cls: 'focus-task-active-task-name', text: task.text });
|
||||||
@@ -186,29 +188,77 @@ export class FocusTaskView extends ItemView {
|
|||||||
|
|
||||||
// Controls
|
// Controls
|
||||||
const controls = activeCard.createEl('div', { cls: 'focus-task-active-controls' });
|
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 ? '⏸ Pause' : '▶ 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 = '✓ Complete';
|
|
||||||
completeBtn.addEventListener('click', () => this.plugin.completeTask(task.id));
|
|
||||||
}
|
|
||||||
|
|
||||||
const stopBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-danger' });
|
|
||||||
stopBtn.innerHTML = '✕ Stop';
|
|
||||||
stopBtn.addEventListener('click', () => this.plugin.stopTimer());
|
|
||||||
|
|
||||||
if (this.plugin.isBreakMode) {
|
if (this.plugin.isBreakMode) {
|
||||||
const skipBreakBtn = controls.createEl('button', { cls: 'focus-task-btn' });
|
// Break mode controls
|
||||||
skipBreakBtn.innerHTML = '⏭ Skip Break';
|
if (this.plugin.currentTimerSeconds > 0) {
|
||||||
skipBreakBtn.addEventListener('click', () => {
|
// Break is still counting down
|
||||||
this.plugin.isBreakMode = false;
|
this.pauseBtnEl = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-secondary' });
|
||||||
this.plugin.stopTimer();
|
this.pauseBtnEl.innerHTML = this.plugin.isTimerRunning ? '⏸ Pause' : '▶ Resume';
|
||||||
this.refresh();
|
this.pauseBtnEl.addEventListener('click', () => this.plugin.toggleTimer());
|
||||||
});
|
|
||||||
|
const skipBreakBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-primary' });
|
||||||
|
skipBreakBtn.innerHTML = '⏭ 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 = '✕ Stop';
|
||||||
|
stopBtn.addEventListener('click', () => {
|
||||||
|
this.plugin.isBreakMode = false;
|
||||||
|
this.plugin.stopTimer();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Break timer finished - show resume button
|
||||||
|
const resumeWorkBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-success' });
|
||||||
|
resumeWorkBtn.innerHTML = '▶ 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 = '✕ Stop';
|
||||||
|
stopBtn.addEventListener('click', () => {
|
||||||
|
this.plugin.isBreakMode = false;
|
||||||
|
this.plugin.stopTimer();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Work mode controls
|
||||||
|
if (this.plugin.currentTimerSeconds > 0) {
|
||||||
|
// Work session still running
|
||||||
|
this.pauseBtnEl = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-secondary' });
|
||||||
|
this.pauseBtnEl.innerHTML = this.plugin.isTimerRunning ? '⏸ Pause' : '▶ Resume';
|
||||||
|
this.pauseBtnEl.addEventListener('click', () => this.plugin.toggleTimer());
|
||||||
|
|
||||||
|
const completeBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-success' });
|
||||||
|
completeBtn.innerHTML = '✓ Complete';
|
||||||
|
completeBtn.addEventListener('click', () => this.plugin.completeTask(task.id));
|
||||||
|
|
||||||
|
const stopBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-danger' });
|
||||||
|
stopBtn.innerHTML = '✕ Stop';
|
||||||
|
stopBtn.addEventListener('click', () => this.plugin.stopTimer());
|
||||||
|
} else {
|
||||||
|
// Work session finished - show break and completion options
|
||||||
|
const startBreakBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-secondary' });
|
||||||
|
startBreakBtn.innerHTML = '☕ Start Break';
|
||||||
|
startBreakBtn.addEventListener('click', () => this.plugin.startBreak());
|
||||||
|
|
||||||
|
const continueBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-primary' });
|
||||||
|
continueBtn.innerHTML = '▶ 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 = '✓ Complete';
|
||||||
|
completeBtn.addEventListener('click', () => this.plugin.completeTask(task.id));
|
||||||
|
|
||||||
|
const stopBtn = controls.createEl('button', { cls: 'focus-task-btn focus-task-btn-danger' });
|
||||||
|
stopBtn.innerHTML = '✕ Stop';
|
||||||
|
stopBtn.addEventListener('click', () => this.plugin.stopTimer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
{
|
{
|
||||||
"1.0.2": "0.15.0"
|
"1.0.4": "0.15.0",
|
||||||
|
"1.0.5": "0.15.0",
|
||||||
|
"1.0.6": "0.15.0",
|
||||||
|
"1.0.7": "0.15.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user