- Move inline styles from TypeScript to CSS for better theme compatibility - Remove "Freewriting" from command names to follow Obsidian conventions - Fix TypeScript type casting by properly typing model as AnthropicModel - Update to latest Claude models including Opus 4.1 and Sonnet 4 Changes: • commands/staggeredPrompts.ts: Replace inline styles with CSS class • main.ts: Rename commands to "Show Staggered Prompts" and "Add Note Prompts" • settings.ts: Remove 'as any' cast and update default model • styles.css: Add .freewriting-prompt-notice class with proper styling • types.ts: Change model field type from string to AnthropicModel 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
113 lines
3.5 KiB
TypeScript
113 lines
3.5 KiB
TypeScript
// ABOUTME: Staggered 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 StaggeredPromptsCommand {
|
|
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 staggered sequence
|
|
this.stop();
|
|
|
|
try {
|
|
// Generate prompts
|
|
const prompts = await this.promptGenerator.generateStaggeredPrompts(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();
|
|
|
|
// If there are more prompts, start the interval
|
|
if (prompts.length > 1) {
|
|
this.startInterval(settings.delaySeconds);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Error executing staggered 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();
|
|
} else {
|
|
// We've shown all prompts, stop the interval
|
|
this.stop();
|
|
new Notice('All prompts have been shown');
|
|
}
|
|
}, delaySeconds * 1000);
|
|
}
|
|
|
|
private showCurrentPrompt(): void {
|
|
if (this.currentIndex < this.promptQueue.length) {
|
|
const prompt = this.promptQueue[this.currentIndex];
|
|
const promptNumber = this.currentIndex + 1;
|
|
const totalPrompts = this.promptQueue.length;
|
|
|
|
// Create a longer-lasting notice for the prompt
|
|
const notice = new Notice(
|
|
`Writing Prompt ${promptNumber}/${totalPrompts}:\n\n${prompt}`,
|
|
8000 // Show for 8 seconds
|
|
);
|
|
|
|
// 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);
|
|
}
|
|
} |