refactor: rename "Staggered Prompts" to "Timed Prompts" for clarity
Renames command terminology throughout codebase to better reflect regular interval delivery rather than irregular/staggered timing. Changes: - Rename staggeredPrompts.ts → timedPrompts.ts - Update class StaggeredPromptsCommand → TimedPromptsCommand - Update command IDs: staggered-prompts → timed-prompts - Update user-facing labels in settings and README - Update property names: staggeredCount → timedCount - Update method names: generateStaggeredPrompts → generateTimedPrompts - Update API constants and type annotations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
8 files changed
+65
-65
No files matched your search
@@ -0,0 +1,116 @@
|
||||
// ABOUTME: Timed prompts command implementation that shows prompts as timed notifications
|
||||
// ABOUTME: Manages interval-based prompt display with proper cleanup and error handling
|
||||
|
||||
import { Notice } from 'obsidian';
|
||||
import { PromptGeneratorService } from '../services/promptGenerator';
|
||||
import { FreewritingPromptsSettings } from '../types';
|
||||
|
||||
export class TimedPromptsCommand {
|
||||
private activeInterval: number | null = null;
|
||||
private promptQueue: string[] = [];
|
||||
private currentIndex = 0;
|
||||
|
||||
constructor(private promptGenerator: PromptGeneratorService) {}
|
||||
|
||||
// MARK: - Public Methods
|
||||
|
||||
async execute(settings: FreewritingPromptsSettings): Promise<void> {
|
||||
// Stop any existing timed sequence
|
||||
this.stop();
|
||||
|
||||
try {
|
||||
// Generate prompts
|
||||
const prompts = await this.promptGenerator.generateTimedPrompts(settings);
|
||||
|
||||
if (prompts.length === 0) {
|
||||
new Notice('No prompts were generated');
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize the prompt queue
|
||||
this.promptQueue = prompts;
|
||||
this.currentIndex = 0;
|
||||
|
||||
// Show the first prompt immediately
|
||||
this.showCurrentPrompt(settings.delaySeconds);
|
||||
|
||||
// If there are more prompts, start the interval
|
||||
if (prompts.length > 1) {
|
||||
this.startInterval(settings.delaySeconds);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error executing timed prompts command:', error);
|
||||
// Error handling is done in the service layer
|
||||
}
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
if (this.activeInterval !== null) {
|
||||
clearInterval(this.activeInterval);
|
||||
this.activeInterval = null;
|
||||
}
|
||||
this.promptQueue = [];
|
||||
this.currentIndex = 0;
|
||||
}
|
||||
|
||||
isRunning(): boolean {
|
||||
return this.activeInterval !== null;
|
||||
}
|
||||
|
||||
// MARK: - Private Methods
|
||||
|
||||
private startInterval(delaySeconds: number): void {
|
||||
this.activeInterval = window.setInterval(() => {
|
||||
this.currentIndex++;
|
||||
|
||||
if (this.currentIndex < this.promptQueue.length) {
|
||||
this.showCurrentPrompt(delaySeconds);
|
||||
} else {
|
||||
// We've shown all prompts, stop the interval
|
||||
this.stop();
|
||||
new Notice('All prompts have been shown');
|
||||
}
|
||||
}, delaySeconds * 1000);
|
||||
}
|
||||
|
||||
private showCurrentPrompt(delaySeconds: number): void {
|
||||
if (this.currentIndex < this.promptQueue.length) {
|
||||
const prompt = this.promptQueue[this.currentIndex];
|
||||
const promptNumber = this.currentIndex + 1;
|
||||
const totalPrompts = this.promptQueue.length;
|
||||
|
||||
// Calculate notification duration: slightly less than delay to avoid overlap
|
||||
// Subtract 500ms to allow for fade-out before next prompt appears
|
||||
const notificationDuration = Math.max(1000, (delaySeconds * 1000) - 500);
|
||||
|
||||
const notice = new Notice(
|
||||
`Writing Prompt ${promptNumber}/${totalPrompts}:\n\n${prompt}`,
|
||||
notificationDuration
|
||||
);
|
||||
|
||||
// Add CSS class for styling
|
||||
const noticeEl = notice.noticeEl;
|
||||
if (noticeEl) {
|
||||
noticeEl.addClass('freewriting-prompt-notice');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Status Methods
|
||||
|
||||
getStatus(): { isRunning: boolean; currentPrompt: number; totalPrompts: number } {
|
||||
return {
|
||||
isRunning: this.isRunning(),
|
||||
currentPrompt: this.currentIndex + 1,
|
||||
totalPrompts: this.promptQueue.length
|
||||
};
|
||||
}
|
||||
|
||||
getRemainingPrompts(): string[] {
|
||||
if (this.currentIndex >= this.promptQueue.length) {
|
||||
return [];
|
||||
}
|
||||
return this.promptQueue.slice(this.currentIndex + 1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user