Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ad5b5e81bb | |||
| 951e9c5406 | |||
| 6dc4d2952d | |||
| 8e10724206 | |||
| d661466c81 | |||
| f634993637 | |||
| 1a0c37d642 | |||
| 5a33e641b1 | |||
| 7b4e2e674a |
13
README.md
13
README.md
@@ -4,7 +4,7 @@ A powerful task management and focus timer plugin for [Obsidian](https://obsidia
|
|||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
## 🎯 Overview
|
## 🎯 Overview
|
||||||
|
|
||||||
@@ -224,17 +224,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.
|
||||||
|
|||||||
112
main.js
112
main.js
@@ -2,7 +2,6 @@
|
|||||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||||
if you want to view the source, please visit the github repository of this plugin
|
if you want to view the source, please visit the github repository of this plugin
|
||||||
*/
|
*/
|
||||||
/* Build version 1.0.1 */
|
|
||||||
|
|
||||||
var __defProp = Object.defineProperty;
|
var __defProp = Object.defineProperty;
|
||||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||||
@@ -45,7 +44,11 @@ var DEFAULT_SETTINGS = {
|
|||||||
{ id: "learning", name: "Learning", color: "#f59e0b", icon: "\u{1F4DA}" }
|
{ id: "learning", name: "Learning", color: "#f59e0b", icon: "\u{1F4DA}" }
|
||||||
],
|
],
|
||||||
autoStartBreak: false,
|
autoStartBreak: false,
|
||||||
tickSoundEnabled: false
|
tickSoundEnabled: false,
|
||||||
|
// Daily note logging
|
||||||
|
logToDaily: false,
|
||||||
|
dailyNoteFormat: "YYYY-MM-DD",
|
||||||
|
dailyNoteHeading: "## \u26A1 Completed Tasks"
|
||||||
};
|
};
|
||||||
var DEFAULT_DATA = {
|
var DEFAULT_DATA = {
|
||||||
tasks: [],
|
tasks: [],
|
||||||
@@ -496,6 +499,8 @@ 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;
|
||||||
|
// Focus time tracking (in seconds for accuracy)
|
||||||
|
this.focusSecondsToday = 0;
|
||||||
// Status bar element
|
// Status bar element
|
||||||
this.statusBarEl = null;
|
this.statusBarEl = null;
|
||||||
}
|
}
|
||||||
@@ -544,8 +549,10 @@ 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) || {});
|
||||||
|
this.focusSecondsToday = (this.data.totalFocusMinutesToday || 0) * 60;
|
||||||
}
|
}
|
||||||
async saveAllData() {
|
async saveAllData() {
|
||||||
|
this.data.totalFocusMinutesToday = Math.floor(this.focusSecondsToday / 60);
|
||||||
await this.saveData({
|
await this.saveData({
|
||||||
settings: this.settings,
|
settings: this.settings,
|
||||||
data: this.data
|
data: this.data
|
||||||
@@ -563,6 +570,7 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
}
|
}
|
||||||
this.data.completedToday = 0;
|
this.data.completedToday = 0;
|
||||||
this.data.totalFocusMinutesToday = 0;
|
this.data.totalFocusMinutesToday = 0;
|
||||||
|
this.focusSecondsToday = 0;
|
||||||
this.data.lastActiveDate = today;
|
this.data.lastActiveDate = today;
|
||||||
this.saveAllData();
|
this.saveAllData();
|
||||||
}
|
}
|
||||||
@@ -636,6 +644,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;
|
||||||
@@ -667,6 +678,7 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds++;
|
this.currentTimerSeconds++;
|
||||||
task.actualMinutes = Math.floor(this.currentTimerSeconds / 60);
|
task.actualMinutes = Math.floor(this.currentTimerSeconds / 60);
|
||||||
|
this.focusSecondsToday++;
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
if (this.currentTimerSeconds === task.estimatedMinutes * 60) {
|
if (this.currentTimerSeconds === task.estimatedMinutes * 60) {
|
||||||
@@ -690,11 +702,13 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
this.isTimerRunning = true;
|
this.isTimerRunning = true;
|
||||||
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) {
|
||||||
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
secondsWorked++;
|
||||||
this.data.totalFocusMinutesToday = Math.floor(this.data.totalFocusMinutesToday + 1 / 60);
|
task.actualMinutes = Math.floor(secondsWorked / 60);
|
||||||
|
this.focusSecondsToday++;
|
||||||
}
|
}
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
@@ -756,6 +770,7 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
this.currentTimerSeconds--;
|
this.currentTimerSeconds--;
|
||||||
if (task && !this.isBreakMode) {
|
if (task && !this.isBreakMode) {
|
||||||
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
||||||
|
this.focusSecondsToday++;
|
||||||
}
|
}
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
@@ -870,6 +885,80 @@ 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 dailyNotePath = this.getDailyNotePath();
|
||||||
|
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(dailyNotePath, taskEntry);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to log task to daily note:", e);
|
||||||
|
new import_obsidian3.Notice("Failed to log task to daily note");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getDailyNotePath() {
|
||||||
|
const now = new Date();
|
||||||
|
const format = this.settings.dailyNoteFormat;
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = (now.getMonth() + 1).toString().padStart(2, "0");
|
||||||
|
const day = now.getDate().toString().padStart(2, "0");
|
||||||
|
let filename = format.replace("YYYY", year.toString()).replace("MM", month).replace("DD", day);
|
||||||
|
return `${filename}.md`;
|
||||||
|
}
|
||||||
|
async appendToDailyNote(path, content) {
|
||||||
|
const { vault } = this.app;
|
||||||
|
const heading = this.settings.dailyNoteHeading;
|
||||||
|
let file = vault.getAbstractFileByPath(path);
|
||||||
|
if (!file) {
|
||||||
|
await vault.create(path, `# ${new Date().toLocaleDateString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric" })}
|
||||||
|
|
||||||
|
${heading}
|
||||||
|
|
||||||
|
${content}
|
||||||
|
`);
|
||||||
|
new import_obsidian3.Notice("\u{1F4DD} Task logged to new daily note");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(file instanceof import_obsidian3.TFile)) {
|
||||||
|
new import_obsidian3.Notice("Daily note path is not a file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let existingContent = await vault.read(file);
|
||||||
|
if (existingContent.includes(heading)) {
|
||||||
|
const headingIndex = existingContent.indexOf(heading);
|
||||||
|
const afterHeading = headingIndex + heading.length;
|
||||||
|
const nextHeadingMatch = existingContent.slice(afterHeading).match(/\n##? /);
|
||||||
|
let insertPosition;
|
||||||
|
if (nextHeadingMatch && nextHeadingMatch.index !== void 0) {
|
||||||
|
insertPosition = afterHeading + nextHeadingMatch.index;
|
||||||
|
} else {
|
||||||
|
insertPosition = existingContent.length;
|
||||||
|
}
|
||||||
|
const before = existingContent.slice(0, insertPosition);
|
||||||
|
const after = existingContent.slice(insertPosition);
|
||||||
|
const newContent = before.trimEnd() + "\n" + content + "\n" + after.trimStart();
|
||||||
|
await vault.modify(file, newContent);
|
||||||
|
} else {
|
||||||
|
const newContent = existingContent.trimEnd() + "\n\n" + heading + "\n\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);
|
||||||
@@ -927,7 +1016,7 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
pendingCount: pending.length,
|
pendingCount: pending.length,
|
||||||
completedToday: this.data.completedToday,
|
completedToday: this.data.completedToday,
|
||||||
totalEstimatedMinutes: totalEstimate,
|
totalEstimatedMinutes: totalEstimate,
|
||||||
totalFocusMinutesToday: Math.floor(this.data.totalFocusMinutesToday),
|
totalFocusMinutesToday: Math.floor(this.focusSecondsToday / 60),
|
||||||
streak: this.data.streak,
|
streak: this.data.streak,
|
||||||
pomodorosCompleted: this.data.pomodorosCompleted,
|
pomodorosCompleted: this.data.pomodorosCompleted,
|
||||||
avgAccuracy: Math.round(avgAccuracy * 100)
|
avgAccuracy: Math.round(avgAccuracy * 100)
|
||||||
@@ -977,6 +1066,19 @@ 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").addToggle((toggle) => toggle.setValue(this.plugin.settings.logToDaily).onChange(async (value) => {
|
||||||
|
this.plugin.settings.logToDaily = value;
|
||||||
|
await this.plugin.saveAllData();
|
||||||
|
}));
|
||||||
|
new import_obsidian3.Setting(containerEl).setName("Daily note filename format").setDesc("Format for daily note filename (YYYY = year, MM = month, DD = day)").addText((text) => text.setPlaceholder("YYYY-MM-DD").setValue(this.plugin.settings.dailyNoteFormat).onChange(async (value) => {
|
||||||
|
this.plugin.settings.dailyNoteFormat = value || "YYYY-MM-DD";
|
||||||
|
await this.plugin.saveAllData();
|
||||||
|
}));
|
||||||
|
new import_obsidian3.Setting(containerEl).setName("Section heading").setDesc("Heading under which completed tasks will be logged").addText((text) => text.setPlaceholder("## \u26A1 Completed Tasks").setValue(this.plugin.settings.dailyNoteHeading).onChange(async (value) => {
|
||||||
|
this.plugin.settings.dailyNoteHeading = value || "## \u26A1 Completed Tasks";
|
||||||
|
await this.plugin.saveAllData();
|
||||||
|
}));
|
||||||
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.1",
|
"version": "1.0.3",
|
||||||
"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",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "focus-task",
|
"name": "focus-task",
|
||||||
"version": "1.0.1",
|
"version": "1.0.3",
|
||||||
"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": {
|
||||||
|
|||||||
171
src/main.ts
171
src/main.ts
@@ -4,6 +4,7 @@ import {
|
|||||||
Plugin,
|
Plugin,
|
||||||
PluginSettingTab,
|
PluginSettingTab,
|
||||||
Setting,
|
Setting,
|
||||||
|
TFile,
|
||||||
WorkspaceLeaf,
|
WorkspaceLeaf,
|
||||||
} from 'obsidian';
|
} from 'obsidian';
|
||||||
|
|
||||||
@@ -36,6 +37,9 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
activeTaskId: string | null = null;
|
activeTaskId: string | null = null;
|
||||||
pomodoroCount: number = 0;
|
pomodoroCount: number = 0;
|
||||||
|
|
||||||
|
// Focus time tracking (in seconds for accuracy)
|
||||||
|
private focusSecondsToday: number = 0;
|
||||||
|
|
||||||
// Status bar element
|
// Status bar element
|
||||||
statusBarEl: HTMLElement | null = null;
|
statusBarEl: HTMLElement | null = null;
|
||||||
|
|
||||||
@@ -102,9 +106,13 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
const loaded = await this.loadData();
|
const loaded = await this.loadData();
|
||||||
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 || {});
|
||||||
|
// Initialize seconds from stored minutes
|
||||||
|
this.focusSecondsToday = (this.data.totalFocusMinutesToday || 0) * 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveAllData() {
|
async saveAllData() {
|
||||||
|
// Sync minutes from seconds before saving
|
||||||
|
this.data.totalFocusMinutesToday = Math.floor(this.focusSecondsToday / 60);
|
||||||
await this.saveData({
|
await this.saveData({
|
||||||
settings: this.settings,
|
settings: this.settings,
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@@ -126,6 +134,7 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
// Reset daily stats
|
// Reset daily stats
|
||||||
this.data.completedToday = 0;
|
this.data.completedToday = 0;
|
||||||
this.data.totalFocusMinutesToday = 0;
|
this.data.totalFocusMinutesToday = 0;
|
||||||
|
this.focusSecondsToday = 0;
|
||||||
this.data.lastActiveDate = today;
|
this.data.lastActiveDate = today;
|
||||||
this.saveAllData();
|
this.saveAllData();
|
||||||
}
|
}
|
||||||
@@ -216,6 +225,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;
|
||||||
@@ -259,6 +273,9 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
this.currentTimerSeconds++;
|
this.currentTimerSeconds++;
|
||||||
task.actualMinutes = Math.floor(this.currentTimerSeconds / 60);
|
task.actualMinutes = Math.floor(this.currentTimerSeconds / 60);
|
||||||
|
|
||||||
|
// Track focus time
|
||||||
|
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();
|
||||||
@@ -290,12 +307,17 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
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) {
|
||||||
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
secondsWorked++;
|
||||||
this.data.totalFocusMinutesToday = Math.floor(this.data.totalFocusMinutesToday + 1/60);
|
task.actualMinutes = Math.floor(secondsWorked / 60);
|
||||||
|
// Increment focus time by 1 second
|
||||||
|
this.focusSecondsToday++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Light update - only timer display, no full refresh
|
// Light update - only timer display, no full refresh
|
||||||
@@ -379,6 +401,8 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
this.currentTimerSeconds--;
|
this.currentTimerSeconds--;
|
||||||
if (task && !this.isBreakMode) {
|
if (task && !this.isBreakMode) {
|
||||||
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
task.actualMinutes = Math.floor((this.settings.pomodoroWorkMinutes * 60 - this.currentTimerSeconds) / 60);
|
||||||
|
// Track focus time
|
||||||
|
this.focusSecondsToday++;
|
||||||
}
|
}
|
||||||
// Light update - only timer display
|
// Light update - only timer display
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
@@ -523,6 +547,112 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ Daily Note Logging ============
|
||||||
|
|
||||||
|
async logTaskToDailyNote(task: FocusTask) {
|
||||||
|
try {
|
||||||
|
const dailyNotePath = this.getDailyNotePath();
|
||||||
|
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(dailyNotePath, taskEntry);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to log task to daily note:', e);
|
||||||
|
new Notice('Failed to log task to daily note');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getDailyNotePath(): string {
|
||||||
|
const now = new Date();
|
||||||
|
const format = this.settings.dailyNoteFormat;
|
||||||
|
|
||||||
|
// Simple date formatting
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = (now.getMonth() + 1).toString().padStart(2, '0');
|
||||||
|
const day = now.getDate().toString().padStart(2, '0');
|
||||||
|
|
||||||
|
let filename = format
|
||||||
|
.replace('YYYY', year.toString())
|
||||||
|
.replace('MM', month)
|
||||||
|
.replace('DD', day);
|
||||||
|
|
||||||
|
return `${filename}.md`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async appendToDailyNote(path: string, content: string) {
|
||||||
|
const { vault } = this.app;
|
||||||
|
const heading = this.settings.dailyNoteHeading;
|
||||||
|
|
||||||
|
let file = vault.getAbstractFileByPath(path);
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
// Create the daily note if it doesn't exist
|
||||||
|
await vault.create(path, `# ${new Date().toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}\n\n${heading}\n\n${content}\n`);
|
||||||
|
new Notice('📝 Task logged to new daily note');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(file instanceof TFile)) {
|
||||||
|
new Notice('Daily note path is not a file');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read existing content
|
||||||
|
let existingContent = await vault.read(file);
|
||||||
|
|
||||||
|
// Check if heading exists
|
||||||
|
if (existingContent.includes(heading)) {
|
||||||
|
// Find the heading and append after it
|
||||||
|
const headingIndex = existingContent.indexOf(heading);
|
||||||
|
const afterHeading = headingIndex + heading.length;
|
||||||
|
|
||||||
|
// Find the next heading or end of file
|
||||||
|
const nextHeadingMatch = existingContent.slice(afterHeading).match(/\n##? /);
|
||||||
|
let insertPosition: number;
|
||||||
|
|
||||||
|
if (nextHeadingMatch && nextHeadingMatch.index !== undefined) {
|
||||||
|
// Insert before the next heading
|
||||||
|
insertPosition = afterHeading + nextHeadingMatch.index;
|
||||||
|
} else {
|
||||||
|
// Append to end of file
|
||||||
|
insertPosition = existingContent.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert the new task entry
|
||||||
|
const before = existingContent.slice(0, insertPosition);
|
||||||
|
const after = existingContent.slice(insertPosition);
|
||||||
|
|
||||||
|
// Make sure there's a newline before our content
|
||||||
|
const newContent = before.trimEnd() + '\n' + content + '\n' + after.trimStart();
|
||||||
|
|
||||||
|
await vault.modify(file, newContent);
|
||||||
|
} else {
|
||||||
|
// Add the heading and content at the end
|
||||||
|
const newContent = existingContent.trimEnd() + '\n\n' + heading + '\n\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 {
|
||||||
@@ -588,7 +718,7 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
pendingCount: pending.length,
|
pendingCount: pending.length,
|
||||||
completedToday: this.data.completedToday,
|
completedToday: this.data.completedToday,
|
||||||
totalEstimatedMinutes: totalEstimate,
|
totalEstimatedMinutes: totalEstimate,
|
||||||
totalFocusMinutesToday: Math.floor(this.data.totalFocusMinutesToday),
|
totalFocusMinutesToday: Math.floor(this.focusSecondsToday / 60),
|
||||||
streak: this.data.streak,
|
streak: this.data.streak,
|
||||||
pomodorosCompleted: this.data.pomodorosCompleted,
|
pomodorosCompleted: this.data.pomodorosCompleted,
|
||||||
avgAccuracy: Math.round(avgAccuracy * 100),
|
avgAccuracy: Math.round(avgAccuracy * 100),
|
||||||
@@ -708,6 +838,41 @@ 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')
|
||||||
|
.addToggle(toggle => toggle
|
||||||
|
.setValue(this.plugin.settings.logToDaily)
|
||||||
|
.onChange(async value => {
|
||||||
|
this.plugin.settings.logToDaily = value;
|
||||||
|
await this.plugin.saveAllData();
|
||||||
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Daily note filename format')
|
||||||
|
.setDesc('Format for daily note filename (YYYY = year, MM = month, DD = day)')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('YYYY-MM-DD')
|
||||||
|
.setValue(this.plugin.settings.dailyNoteFormat)
|
||||||
|
.onChange(async value => {
|
||||||
|
this.plugin.settings.dailyNoteFormat = value || 'YYYY-MM-DD';
|
||||||
|
await this.plugin.saveAllData();
|
||||||
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Section heading')
|
||||||
|
.setDesc('Heading under which completed tasks will be logged')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('## ⚡ Completed Tasks')
|
||||||
|
.setValue(this.plugin.settings.dailyNoteHeading)
|
||||||
|
.onChange(async value => {
|
||||||
|
this.plugin.settings.dailyNoteHeading = value || '## ⚡ Completed Tasks';
|
||||||
|
await this.plugin.saveAllData();
|
||||||
|
}));
|
||||||
|
|
||||||
// Lists Management
|
// Lists Management
|
||||||
containerEl.createEl('h2', { text: '📋 Lists' });
|
containerEl.createEl('h2', { text: '📋 Lists' });
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ export interface FocusTaskSettings {
|
|||||||
lists: TaskList[];
|
lists: TaskList[];
|
||||||
autoStartBreak: boolean;
|
autoStartBreak: boolean;
|
||||||
tickSoundEnabled: boolean;
|
tickSoundEnabled: boolean;
|
||||||
|
// Daily note logging
|
||||||
|
logToDaily: boolean;
|
||||||
|
dailyNoteFormat: string;
|
||||||
|
dailyNoteHeading: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FocusTaskData {
|
export interface FocusTaskData {
|
||||||
@@ -58,6 +62,10 @@ export const DEFAULT_SETTINGS: FocusTaskSettings = {
|
|||||||
],
|
],
|
||||||
autoStartBreak: false,
|
autoStartBreak: false,
|
||||||
tickSoundEnabled: false,
|
tickSoundEnabled: false,
|
||||||
|
// Daily note logging
|
||||||
|
logToDaily: false,
|
||||||
|
dailyNoteFormat: 'YYYY-MM-DD',
|
||||||
|
dailyNoteHeading: '## ⚡ Completed Tasks',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_DATA: FocusTaskData = {
|
export const DEFAULT_DATA: FocusTaskData = {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"1.0.1": "0.15.0"
|
"1.0.3": "0.15.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user