Compare commits
5 Commits
e66d9b4d25
...
v1.0.8
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f2346b4c8 | |||
| c8f5c69102 | |||
| 2800a7507e | |||
| 2f861c2fcb | |||
| 9abdd10ada |
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/
|
||||||
11
README.md
11
README.md
@@ -4,7 +4,7 @@ A powerful task management and focus timer plugin for [Obsidian](https://obsidia
|
|||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
## 🎯 Overview
|
## 🎯 Overview
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ Focus Task brings the power of time-boxed task management directly into your Obs
|
|||||||
- **Daily Note Logging**: Automatically log completed tasks to your daily notes with timestamps and performance metrics
|
- **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
|
||||||
- **Celebration Messages**: Fun, randomized messages when you complete tasks
|
- **Celebration Messages**: Fun, randomized messages when you complete tasks
|
||||||
- **Sound Notifications**: Audio alerts for timer completion and task completion
|
- **Sound Notifications**: Audio alerts for timer completion and task completion
|
||||||
- **Keyboard Shortcuts**: Quick access to common actions
|
- **Keyboard Shortcuts**: Quick access to common actions
|
||||||
@@ -66,8 +66,11 @@ Focus Task brings the power of time-boxed task management directly into your Obs
|
|||||||
### Manual Installation
|
### Manual Installation
|
||||||
1. Download the latest release from the [releases page](https://git.cribdev.com/crib/focus-task/releases)
|
1. Download the latest release from the [releases page](https://git.cribdev.com/crib/focus-task/releases)
|
||||||
2. Extract the files to your vault's `.obsidian/plugins/focus-task/` folder
|
2. Extract the files to your vault's `.obsidian/plugins/focus-task/` folder
|
||||||
3. Reload Obsidian
|
3. **⚠️ IMPORTANT**: When updating, do NOT replace or delete the existing `data.json` file - this contains all your tasks, settings, and progress!
|
||||||
4. Enable the plugin in Settings → Community Plugins
|
4. Reload Obsidian
|
||||||
|
5. Enable the plugin in Settings → Community Plugins
|
||||||
|
|
||||||
|
> **Note**: Only copy the three plugin files (`main.js`, `manifest.json`, `styles.css`) when updating. Your `data.json` file stores all your tasks and settings and should never be replaced.
|
||||||
|
|
||||||
### Building from Source
|
### Building from Source
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
78
main.js
78
main.js
@@ -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,13 @@ 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)
|
||||||
|
return;
|
||||||
|
this.updateStatusBar();
|
||||||
|
this.updateTimerDisplay();
|
||||||
|
}
|
||||||
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,16 +730,25 @@ 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;
|
||||||
|
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||||
|
let alertShown = false;
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds++;
|
const now = Date.now();
|
||||||
this.secondsWorkedOnCurrentTask++;
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||||
|
this.currentTimerSeconds = elapsedSeconds;
|
||||||
|
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
this.focusSecondsToday++;
|
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||||
|
this.focusSecondsToday = newFocusSeconds;
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
if (this.currentTimerSeconds === task.estimatedMinutes * 60) {
|
if (!alertShown && this.currentTimerSeconds >= task.estimatedMinutes * 60) {
|
||||||
|
alertShown = true;
|
||||||
if (this.settings.enableSounds) {
|
if (this.settings.enableSounds) {
|
||||||
this.playAlertSound();
|
this.playAlertSound();
|
||||||
}
|
}
|
||||||
@@ -740,15 +767,25 @@ 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;
|
||||||
|
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||||
|
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||||
if (!this.isBreakMode) {
|
if (!this.isBreakMode) {
|
||||||
this.secondsWorkedOnCurrentTask++;
|
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
this.focusSecondsToday++;
|
if (task.actualMinutes !== actualMinutes) {
|
||||||
|
task.actualMinutes = actualMinutes;
|
||||||
|
}
|
||||||
|
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||||
|
this.focusSecondsToday = newFocusSeconds;
|
||||||
}
|
}
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
@@ -792,11 +829,16 @@ 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) {
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||||
|
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
if (this.currentTimerSeconds <= 0) {
|
if (this.currentTimerSeconds <= 0) {
|
||||||
@@ -811,15 +853,22 @@ 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);
|
||||||
|
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1e3);
|
||||||
|
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||||
if (task && !this.isBreakMode) {
|
if (task && !this.isBreakMode) {
|
||||||
this.secondsWorkedOnCurrentTask++;
|
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
this.focusSecondsToday++;
|
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||||
|
this.focusSecondsToday = newFocusSeconds;
|
||||||
}
|
}
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
@@ -842,11 +891,14 @@ var FocusTaskPlugin = class extends import_obsidian3.Plugin {
|
|||||||
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;
|
||||||
|
task.actualMinutes = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "focus-task",
|
"id": "focus-task",
|
||||||
"name": "Focus Task",
|
"name": "Focus Task",
|
||||||
"version": "1.0.4",
|
"version": "1.0.8",
|
||||||
"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.4",
|
"version": "1.0.8",
|
||||||
"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": [
|
||||||
|
|||||||
149
src/main.ts
149
src/main.ts
@@ -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;
|
||||||
@@ -46,10 +50,17 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
|
|
||||||
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,
|
||||||
@@ -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,18 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
|
|
||||||
// ============ Timer Management ============
|
// ============ Timer Management ============
|
||||||
|
|
||||||
|
// Sync timer based on timestamp when app returns from background
|
||||||
|
syncTimerFromTimestamp() {
|
||||||
|
// Since all intervals now calculate from timestamps directly,
|
||||||
|
// we just need to trigger an update when coming back to foreground
|
||||||
|
if (!this.isTimerRunning) return;
|
||||||
|
|
||||||
|
// The interval will automatically calculate correct values on next tick
|
||||||
|
// Just update the display immediately to show current state
|
||||||
|
this.updateStatusBar();
|
||||||
|
this.updateTimerDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
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,25 +298,43 @@ 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
|
||||||
|
|
||||||
|
// Store initial values
|
||||||
|
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||||
|
let alertShown = false;
|
||||||
|
|
||||||
// Full refresh to show the active task card
|
// Full refresh to show the active task card
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
|
|
||||||
// Start interval (count up mode - stopwatch)
|
// Start interval (count up mode - stopwatch)
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds++;
|
// Calculate elapsed time from timestamp
|
||||||
this.secondsWorkedOnCurrentTask++;
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1000);
|
||||||
|
|
||||||
|
// Update timer (count up)
|
||||||
|
this.currentTimerSeconds = elapsedSeconds;
|
||||||
|
|
||||||
|
// Update actual time worked
|
||||||
|
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
|
|
||||||
// Track focus time
|
// Update focus time
|
||||||
this.focusSecondsToday++;
|
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||||
|
this.focusSecondsToday = newFocusSeconds;
|
||||||
|
|
||||||
// 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 (only alert once)
|
||||||
if (this.currentTimerSeconds === task.estimatedMinutes * 60) {
|
if (!alertShown && this.currentTimerSeconds >= task.estimatedMinutes * 60) {
|
||||||
|
alertShown = true;
|
||||||
if (this.settings.enableSounds) {
|
if (this.settings.enableSounds) {
|
||||||
this.playAlertSound();
|
this.playAlertSound();
|
||||||
}
|
}
|
||||||
@@ -307,20 +357,41 @@ 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;
|
||||||
|
|
||||||
|
// Store the initial seconds worked to calculate delta
|
||||||
|
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||||
|
|
||||||
// Full refresh to show the active task card
|
// Full refresh to show the active task card
|
||||||
this.refreshView();
|
this.refreshView();
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
|
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
// Calculate elapsed time from timestamp (more accurate than counting ticks)
|
||||||
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1000);
|
||||||
|
|
||||||
|
// Update countdown timer
|
||||||
|
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||||
|
|
||||||
if (!this.isBreakMode) {
|
if (!this.isBreakMode) {
|
||||||
this.secondsWorkedOnCurrentTask++;
|
// Update actual time worked based on real elapsed time
|
||||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||||
// Increment focus time by 1 second
|
const actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
this.focusSecondsToday++;
|
|
||||||
|
if (task.actualMinutes !== actualMinutes) {
|
||||||
|
task.actualMinutes = actualMinutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update focus time based on elapsed seconds
|
||||||
|
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||||
|
this.focusSecondsToday = newFocusSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Light update - only timer display, no full refresh
|
// Light update - only timer display, no full refresh
|
||||||
@@ -384,6 +455,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
|
||||||
@@ -391,7 +466,14 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
|
|
||||||
if (!this.timerInterval) {
|
if (!this.timerInterval) {
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
// Calculate elapsed time from timestamp
|
||||||
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1000);
|
||||||
|
|
||||||
|
// Update countdown timer
|
||||||
|
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||||
|
|
||||||
// Light update - only timer display
|
// Light update - only timer display
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
@@ -407,23 +489,39 @@ 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);
|
||||||
|
|
||||||
|
// Store initial values for resume
|
||||||
|
const initialSecondsWorked = this.secondsWorkedOnCurrentTask;
|
||||||
|
|
||||||
this.timerInterval = window.setInterval(() => {
|
this.timerInterval = window.setInterval(() => {
|
||||||
this.currentTimerSeconds--;
|
// Calculate elapsed time from timestamp
|
||||||
|
const now = Date.now();
|
||||||
|
const elapsedMs = now - this.timerStartTimestamp;
|
||||||
|
const elapsedSeconds = Math.floor(elapsedMs / 1000);
|
||||||
|
|
||||||
|
// Update timer (countdown from paused position)
|
||||||
|
this.currentTimerSeconds = Math.max(0, this.pausedTimeRemaining - elapsedSeconds);
|
||||||
|
|
||||||
if (task && !this.isBreakMode) {
|
if (task && !this.isBreakMode) {
|
||||||
this.secondsWorkedOnCurrentTask++;
|
// Update actual time worked
|
||||||
|
this.secondsWorkedOnCurrentTask = initialSecondsWorked + elapsedSeconds;
|
||||||
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
task.actualMinutes = Math.floor(this.secondsWorkedOnCurrentTask / 60);
|
||||||
// Track focus time
|
|
||||||
this.focusSecondsToday++;
|
// Update focus time
|
||||||
|
const newFocusSeconds = Math.floor((this.data.totalFocusMinutesToday || 0) * 60) + elapsedSeconds;
|
||||||
|
this.focusSecondsToday = newFocusSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Light update - only timer display
|
// Light update - only timer display
|
||||||
this.updateStatusBar();
|
this.updateStatusBar();
|
||||||
this.updateTimerDisplay();
|
this.updateTimerDisplay();
|
||||||
@@ -451,12 +549,17 @@ export default class FocusTaskPlugin extends Plugin {
|
|||||||
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;
|
||||||
|
// Reset actual time when manually stopping (not after a break)
|
||||||
|
// This allows starting fresh next time
|
||||||
|
task.actualMinutes = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
{
|
{
|
||||||
"1.0.4": "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",
|
||||||
|
"1.0.8": "0.15.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user