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

|
||||

|
||||

|
||||

|
||||
|
||||
## 🎯 Overview
|
||||
|
||||
@@ -224,17 +224,6 @@ npm run dev
|
||||
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
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
96
main.js
96
main.js
@@ -44,7 +44,11 @@ var DEFAULT_SETTINGS = {
|
||||
{ id: "learning", name: "Learning", color: "#f59e0b", icon: "\u{1F4DA}" }
|
||||
],
|
||||
autoStartBreak: false,
|
||||
tickSoundEnabled: false
|
||||
tickSoundEnabled: false,
|
||||
// Daily note logging
|
||||
logToDaily: false,
|
||||
dailyNoteFormat: "YYYY-MM-DD",
|
||||
dailyNoteHeading: "## \u26A1 Completed Tasks"
|
||||
};
|
||||
var DEFAULT_DATA = {
|
||||
tasks: [],
|
||||
@@ -640,6 +644,9 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
||||
if (this.settings.enableSounds) {
|
||||
this.playCompletionSound();
|
||||
}
|
||||
if (this.settings.logToDaily) {
|
||||
this.logTaskToDailyNote(task);
|
||||
}
|
||||
if (this.activeTaskId === taskId) {
|
||||
this.stopTimer();
|
||||
this.activeTaskId = null;
|
||||
@@ -878,6 +885,80 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
||||
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 ============
|
||||
formatTime(seconds) {
|
||||
const absSeconds = Math.abs(seconds);
|
||||
@@ -985,6 +1066,19 @@ var FocusTaskSettingTab = class extends import_obsidian3.PluginSettingTab {
|
||||
this.plugin.settings.enableCelebrations = value;
|
||||
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" });
|
||||
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) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "focus-task",
|
||||
"name": "Focus Task",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"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.",
|
||||
"author": "Crib",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "focus-task",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"description": "A Blitzit-inspired task management and focus timer plugin for Obsidian",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
147
src/main.ts
147
src/main.ts
@@ -4,6 +4,7 @@ import {
|
||||
Plugin,
|
||||
PluginSettingTab,
|
||||
Setting,
|
||||
TFile,
|
||||
WorkspaceLeaf,
|
||||
} from 'obsidian';
|
||||
|
||||
@@ -224,6 +225,11 @@ export default class FocusTaskPlugin extends Plugin {
|
||||
this.playCompletionSound();
|
||||
}
|
||||
|
||||
// Log to daily note
|
||||
if (this.settings.logToDaily) {
|
||||
this.logTaskToDailyNote(task);
|
||||
}
|
||||
|
||||
if (this.activeTaskId === taskId) {
|
||||
this.stopTimer();
|
||||
this.activeTaskId = null;
|
||||
@@ -541,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 ============
|
||||
|
||||
formatTime(seconds: number): string {
|
||||
@@ -726,6 +838,41 @@ class FocusTaskSettingTab extends PluginSettingTab {
|
||||
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
|
||||
containerEl.createEl('h2', { text: '📋 Lists' });
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ export interface FocusTaskSettings {
|
||||
lists: TaskList[];
|
||||
autoStartBreak: boolean;
|
||||
tickSoundEnabled: boolean;
|
||||
// Daily note logging
|
||||
logToDaily: boolean;
|
||||
dailyNoteFormat: string;
|
||||
dailyNoteHeading: string;
|
||||
}
|
||||
|
||||
export interface FocusTaskData {
|
||||
@@ -58,6 +62,10 @@ export const DEFAULT_SETTINGS: FocusTaskSettings = {
|
||||
],
|
||||
autoStartBreak: false,
|
||||
tickSoundEnabled: false,
|
||||
// Daily note logging
|
||||
logToDaily: false,
|
||||
dailyNoteFormat: 'YYYY-MM-DD',
|
||||
dailyNoteHeading: '## ⚡ Completed Tasks',
|
||||
};
|
||||
|
||||
export const DEFAULT_DATA: FocusTaskData = {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"1.0.2": "0.15.0"
|
||||
"1.0.3": "0.15.0"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user