( plugin: TaskNotesPlugin, resolveExplicitTask: () => Promise<TaskInfo | null> )
| 31 | } |
| 32 | |
| 33 | export async function resolveTaskForStopTimeTracking( |
| 34 | plugin: TaskNotesPlugin, |
| 35 | resolveExplicitTask: () => Promise<TaskInfo | null> |
| 36 | ): Promise<TaskInfo> { |
| 37 | const explicitTask = await resolveExplicitTask(); |
| 38 | if (explicitTask) { |
| 39 | return explicitTask; |
| 40 | } |
| 41 | |
| 42 | const allTasks = await plugin.cacheManager.getAllTasks(); |
| 43 | const activeTasks = allTasks.filter((task) => !!getLatestActiveEntry(task)); |
| 44 | |
| 45 | if (activeTasks.length === 1) { |
| 46 | return activeTasks[0]; |
| 47 | } |
| 48 | |
| 49 | if (activeTasks.length > 1) { |
| 50 | throw new Error( |
| 51 | "Multiple tasks have active time tracking; pass path, title, or query" |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | throw new Error("No active time tracking session found"); |
| 56 | } |
| 57 | |
| 58 | export function formatTimeTrackingResult(task: TaskInfo): Record<string, unknown> { |
| 59 | const activeEntry = pluginGetActiveSession(task); |
no test coverage detected