2 Commits

Author SHA1 Message Date
2800a7507e Release v1.0.7: General bugfixes 2025-11-23 15:06:12 +01:00
2f861c2fcb Release v1.0.6: Background Timer Fix 2025-11-23 13:15:45 +01:00
8 changed files with 234 additions and 15 deletions

6
.gitignore vendored
View File

@@ -1,5 +1,7 @@
# Build output # Build output
*.js.map *.js.map
release/
*.zip
# npm # npm
node_modules/ node_modules/
@@ -16,3 +18,7 @@ Thumbs.db
# Obsidian # Obsidian
data.json data.json
# Development/Documentation (not for distribution)
RELEASE-GUIDE.md
.claude/

View File

@@ -4,7 +4,7 @@ A powerful task management and focus timer plugin for [Obsidian](https://obsidia
![Focus Task Banner](https://img.shields.io/badge/Obsidian-Plugin-7c3aed?style=for-the-badge&logo=obsidian&logoColor=white) ![Focus Task Banner](https://img.shields.io/badge/Obsidian-Plugin-7c3aed?style=for-the-badge&logo=obsidian&logoColor=white)
![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge) ![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge)
![Version](https://img.shields.io/badge/Version-1.0.5-blue?style=for-the-badge) ![Version](https://img.shields.io/badge/Version-1.0.7-blue?style=for-the-badge)
## 🎯 Overview ## 🎯 Overview

63
main.js
View File

@@ -536,6 +536,9 @@ 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; this.secondsWorkedOnCurrentTask = 0;
@@ -545,6 +548,11 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
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)
@@ -587,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() {
@@ -701,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)
@@ -712,6 +758,8 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.currentTimerSeconds = 0; this.currentTimerSeconds = 0;
this.isTimerRunning = true; this.isTimerRunning = true;
this.secondsWorkedOnCurrentTask = task.actualMinutes * 60; 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(() => {
@@ -740,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 = task.actualMinutes * 60; this.secondsWorkedOnCurrentTask = Math.floor(task.actualMinutes * 60);
this.timerStartTimestamp = Date.now();
this.pausedTimeRemaining = this.currentTimerSeconds;
this.refreshView(); this.refreshView();
this.updateStatusBar(); this.updateStatusBar();
this.timerInterval = window.setInterval(() => { this.timerInterval = window.setInterval(() => {
this.currentTimerSeconds--; this.currentTimerSeconds--;
if (!this.isBreakMode) { if (!this.isBreakMode) {
this.secondsWorkedOnCurrentTask++; this.secondsWorkedOnCurrentTask++;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60); const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
if (task.actualMinutes !== actualMinutes) {
task.actualMinutes = actualMinutes;
}
this.focusSecondsToday++; this.focusSecondsToday++;
} }
this.updateStatusBar(); this.updateStatusBar();
@@ -792,6 +845,8 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.isTimerRunning = 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) {
@@ -811,8 +866,10 @@ 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--;
@@ -847,6 +904,8 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
this.isTimerRunning = false; this.isTimerRunning = false;
this.activeTaskId = null; this.activeTaskId = null;
this.secondsWorkedOnCurrentTask = 0; this.secondsWorkedOnCurrentTask = 0;
this.timerStartTimestamp = 0;
this.pausedTimeRemaining = 0;
this.updateStatusBar(); this.updateStatusBar();
this.saveAllData(); this.saveAllData();
this.refreshView(); this.refreshView();

View File

@@ -1,7 +1,7 @@
{ {
"id": "focus-task", "id": "focus-task",
"name": "Focus Task", "name": "Focus Task",
"version": "1.0.5", "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
View 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();

View File

@@ -1,11 +1,12 @@
{ {
"name": "focus-task", "name": "focus-task",
"version": "1.0.5", "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": [

View File

@@ -37,6 +37,10 @@ export default class FocusTaskPlugin extends Plugin {
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; private secondsWorkedOnCurrentTask: number = 0;
@@ -50,6 +54,13 @@ export default class FocusTaskPlugin extends Plugin {
// 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,
@@ -105,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;
} }
@@ -251,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;
@@ -266,6 +333,10 @@ export default class FocusTaskPlugin extends Plugin {
this.isTimerRunning = true; this.isTimerRunning = true;
this.secondsWorkedOnCurrentTask = task.actualMinutes * 60; 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();
this.updateStatusBar(); this.updateStatusBar();
@@ -307,7 +378,12 @@ export default class FocusTaskPlugin extends Plugin {
this.isTimerRunning = true; this.isTimerRunning = true;
// Initialize from existing actual time to preserve progress across breaks // Initialize from existing actual time to preserve progress across breaks
this.secondsWorkedOnCurrentTask = task.actualMinutes * 60; // 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();
@@ -318,7 +394,12 @@ export default class FocusTaskPlugin extends Plugin {
if (!this.isBreakMode) { if (!this.isBreakMode) {
this.secondsWorkedOnCurrentTask++; this.secondsWorkedOnCurrentTask++;
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 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++;
} }
@@ -384,6 +465,10 @@ export default class FocusTaskPlugin extends Plugin {
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
@@ -407,13 +492,15 @@ export default class FocusTaskPlugin extends Plugin {
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(() => {
@@ -457,6 +544,8 @@ export default class FocusTaskPlugin extends Plugin {
this.isTimerRunning = false; this.isTimerRunning = false;
this.activeTaskId = null; this.activeTaskId = null;
this.secondsWorkedOnCurrentTask = 0; this.secondsWorkedOnCurrentTask = 0;
this.timerStartTimestamp = 0;
this.pausedTimeRemaining = 0;
this.updateStatusBar(); this.updateStatusBar();
this.saveAllData(); this.saveAllData();
this.refreshView(); this.refreshView();

View File

@@ -1,4 +1,6 @@
{ {
"1.0.4": "0.15.0", "1.0.4": "0.15.0",
"1.0.5": "0.15.0" "1.0.5": "0.15.0",
"1.0.6": "0.15.0",
"1.0.7": "0.15.0"
} }